From c29c72fd923023c8bb96c60bf14da2fd122a63dd Mon Sep 17 00:00:00 2001 From: GuwandykA Date: Thu, 9 Jul 2026 13:13:18 +0500 Subject: [PATCH] change db --- db/migrations/20260702125108_init.down.sql | 2 +- db/migrations/20260702125108_init.up.sql | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/db/migrations/20260702125108_init.down.sql b/db/migrations/20260702125108_init.down.sql index 2d44ff6..306f773 100644 --- a/db/migrations/20260702125108_init.down.sql +++ b/db/migrations/20260702125108_init.down.sql @@ -1,6 +1,5 @@ DROP TABLE IF EXISTS loan_orders; DROP TABLE IF EXISTS branch_user; -DROP TABLE IF EXISTS roles; DROP TABLE IF EXISTS loan_order_required_docs; DROP TABLE IF EXISTS loan_types; DROP TABLE IF EXISTS card_states; @@ -8,3 +7,4 @@ DROP TABLE IF EXISTS card_types; DROP TABLE IF EXISTS branches; DROP TABLE IF EXISTS provinces; DROP TABLE IF EXISTS users; +DROP TABLE IF EXISTS roles; diff --git a/db/migrations/20260702125108_init.up.sql b/db/migrations/20260702125108_init.up.sql index 760999c..e764d72 100644 --- a/db/migrations/20260702125108_init.up.sql +++ b/db/migrations/20260702125108_init.up.sql @@ -9,9 +9,14 @@ CREATE TABLE IF NOT EXISTS users ( "phone" character varying(250) NOT NULL DEFAULT '', "light_mode" integer DEFAULT 1 NOT NULL, "role" character varying(250) NOT NULL DEFAULT 'user', + "role_id" bigint, "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 + "created_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL, + CONSTRAINT users_role_id_fkey + FOREIGN KEY ("role_id") + REFERENCES roles("id") + ON UPDATE CASCADE ON DELETE CASCADE ); insert into users( @@ -39,7 +44,7 @@ CREATE TABLE IF NOT EXISTS branches ( 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, + province_id bigint, phone_numbers json NOT NULL DEFAULT '[]'::json, billing_username character varying(255) NOT NULL DEFAULT '', billing_password character varying(255) NOT NULL DEFAULT '', @@ -51,7 +56,11 @@ CREATE TABLE IF NOT EXISTS branches ( 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 + "created_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL, + CONSTRAINT branches_province_id_fkey + FOREIGN KEY ("province_id") + REFERENCES provinces("id") + ON UPDATE CASCADE ON DELETE CASCADE ); CREATE TABLE IF NOT EXISTS card_types ( @@ -103,6 +112,7 @@ CREATE TABLE IF NOT EXISTS roles ( updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL ); + CREATE TABLE IF NOT EXISTS permissions ( id bigserial PRIMARY KEY, code character varying(255) NOT NULL DEFAULT '',