Files
online-backend/db/migrations/20260702125108_init.up.sql
2026-07-06 19:13:54 +05:00

97 lines
4.2 KiB
SQL

CREATE TABLE IF NOT EXISTS users (
"id" bigserial primary key,
"email" character varying(250) NOT NULL DEFAULT '',
"password" character varying(250) NOT NULL DEFAULT '',
"fullname" character varying(250) NOT NULL DEFAULT '',
"username" character varying(250) NOT NULL DEFAULT '',
"phone_number" character varying(250) NOT NULL DEFAULT '',
"avatar" character varying(250) NOT NULL DEFAULT '',
"social_media" json NOT NULL DEFAULT '{}'::json,
"light_mode" integer DEFAULT 1 NOT NULL,
"role" character varying(250) NOT NULL DEFAULT 'user',
"active" boolean NOT NULL DEFAULT true,
"updated_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
"created_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
insert into users(
phone_number, password, fullname, email, role
) values (
'61531216',
'$2a$12$8ZbKmoSwna4CASQptM2/SubwvsBUR1YhABULd.2/QJB.13Wi2v55m',
'Admin',
'admin@admin.com',
'admin'
);
CREATE TABLE IF NOT EXISTS provinces (
id bigserial PRIMARY KEY,
name json NOT NULL DEFAULT '{}'::json,
region json NOT NULL DEFAULT '{}'::json,
active boolean NOT NULL DEFAULT true,
"updated_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
"created_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
CREATE TABLE IF NOT EXISTS branches (
id bigserial PRIMARY KEY,
unique_code character varying(255) UNIQUE,
name json NOT NULL DEFAULT '{}'::json,
address json NOT NULL DEFAULT '{}'::json,
region character varying(2) NOT NULL DEFAULT '',
province_id bigint REFERENCES provinces(id) ON DELETE SET NULL,
phone_numbers json NOT NULL DEFAULT '[]'::json,
billing_username character varying(255) NOT NULL DEFAULT '',
billing_password character varying(255) NOT NULL DEFAULT '',
billing_swift_username character varying(255) NOT NULL DEFAULT '',
billing_swift_password character varying(255) NOT NULL DEFAULT '',
billing_visa_master_username character varying(255) NOT NULL DEFAULT '',
billing_visa_master_password character varying(255) NOT NULL DEFAULT '',
billing_sber_username character varying(255) NOT NULL DEFAULT '',
billing_sber_password character varying(255) NOT NULL DEFAULT '',
active boolean NOT NULL DEFAULT true,
"updated_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
"created_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
CREATE TABLE IF NOT EXISTS payment_cards (
id bigserial PRIMARY KEY,
price numeric(12, 2) NOT NULL DEFAULT 0,
title json NOT NULL DEFAULT '{}'::json,
content json NOT NULL DEFAULT '{}'::json,
active boolean NOT NULL DEFAULT true,
"updated_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
"created_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
CREATE TABLE IF NOT EXISTS reasons_cards (
id bigserial PRIMARY KEY,
title json NOT NULL DEFAULT '{}'::json,
price numeric(12, 2) NOT NULL DEFAULT 0,
content json NOT NULL DEFAULT '{}'::json,
created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
CREATE TABLE IF NOT EXISTS loan_types (
id bigserial PRIMARY KEY,
title json NOT NULL DEFAULT '{}'::json,
tax numeric(12, 2) NOT NULL DEFAULT 0,
loan_term character varying(250) NOT NULL DEFAULT '',
content json NOT NULL DEFAULT '{}'::json,
created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
CREATE TABLE IF NOT EXISTS loan_required_documents (
id bigserial PRIMARY KEY,
title json NOT NULL DEFAULT '{}'::json,
content_en text NOT NULL DEFAULT '',
content_ru text NOT NULL DEFAULT '',
content_tm text NOT NULL DEFAULT '',
active boolean NOT NULL DEFAULT true,
created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);