Files
online-backend/db/migrations/20260702125108_init.up.sql
GuwandykA 82e1aad016 Align schema, API routes, and auth with updated admin domain model.
Rename users table fields and loan documents table, expand branch billing credentials, switch to /api/admin prefix, refactor auth endpoints, replace PATCH with PUT for status updates, remove file upload APIs, and regenerate Swagger with ordered tags.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 14:09:45 +05:00

103 lines
4.5 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',
"status" 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,
title json NOT NULL DEFAULT '{}'::json,
status 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 location (
id bigserial PRIMARY KEY,
province_id bigint NOT NULL REFERENCES provinces(id) ON DELETE CASCADE,
title json NOT NULL DEFAULT '{}'::json,
status 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,
title json NOT NULL DEFAULT '{}'::json,
province_id bigint NOT NULL REFERENCES provinces(id) ON DELETE CASCADE,
location_id bigint NOT NULL REFERENCES location(id) ON DELETE CASCADE,
unikal_nomer character varying(250) NOT NULL UNIQUE,
"address" text NOT NULL DEFAULT '',
billing_username character varying(250) NOT NULL DEFAULT '',
billing_password character varying(250) NOT NULL DEFAULT '',
billing_username_sber character varying(250) NOT NULL DEFAULT '',
billing_password_sber character varying(250) NOT NULL DEFAULT '',
billing_username_visa character varying(250) NOT NULL DEFAULT '',
billing_password_visa character varying(250) NOT NULL DEFAULT '',
billing_username_swift character varying(250) NOT NULL DEFAULT '',
billing_password_swift character varying(250) NOT NULL DEFAULT '',
"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,
status 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 '',
status 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
);