change users table

This commit is contained in:
2026-07-13 12:11:35 +05:00
parent c29c72fd92
commit 6705c4ce91
22 changed files with 3150 additions and 83 deletions

View File

@@ -1,3 +1,5 @@
DROP TABLE IF EXISTS loan_paid_off_letters;
DROP TABLE IF EXISTS loans;
DROP TABLE IF EXISTS loan_orders;
DROP TABLE IF EXISTS branch_user;
DROP TABLE IF EXISTS loan_order_required_docs;

View File

@@ -1,22 +1,28 @@
CREATE TABLE IF NOT EXISTS roles (
id bigserial PRIMARY KEY,
code character varying(255) NOT NULL DEFAULT '',
name character varying(255) NOT NULL,
guard_name character varying(255) NOT NULL,
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 users (
"id" bigserial primary key,
"email" character varying(250) NOT NULL DEFAULT '',
"name" character varying(250) NOT NULL DEFAULT '',
"password" character varying(250) NOT NULL DEFAULT '',
"first_name" character varying(250) NOT NULL DEFAULT '',
"last_name" character varying(250) NOT NULL DEFAULT '',
"name" character varying(255) NOT NULL DEFAULT '',
"first_name" character varying(255) NOT NULL DEFAULT '',
"last_name" character varying(255) NOT NULL DEFAULT '',
"username" character varying(250) NOT NULL DEFAULT '',
"phone" 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',
"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,
CONSTRAINT users_role_id_fkey
FOREIGN KEY ("role_id")
REFERENCES roles("id")
ON UPDATE CASCADE ON DELETE CASCADE
"created_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
insert into users(
@@ -60,7 +66,7 @@ CREATE TABLE IF NOT EXISTS branches (
CONSTRAINT branches_province_id_fkey
FOREIGN KEY ("province_id")
REFERENCES provinces("id")
ON UPDATE CASCADE ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS card_types (
@@ -83,6 +89,23 @@ CREATE TABLE IF NOT EXISTS card_states (
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 '',
name character varying(255) NOT NULL,
guard_name character varying(255) NOT NULL,
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 branch_user (
id bigserial PRIMARY KEY,
branch_id bigint REFERENCES branches(id),
user_id bigint REFERENCES users(id),
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,
name json NOT NULL DEFAULT '{}'::json,
@@ -103,33 +126,6 @@ CREATE TABLE IF NOT EXISTS loan_order_required_docs (
updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
CREATE TABLE IF NOT EXISTS roles (
id bigserial PRIMARY KEY,
code character varying(255) NOT NULL DEFAULT '',
name character varying(255) NOT NULL,
guard_name character varying(255) NOT NULL,
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 permissions (
id bigserial PRIMARY KEY,
code character varying(255) NOT NULL DEFAULT '',
name character varying(255) NOT NULL,
guard_name character varying(255) NOT NULL,
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 branch_user (
id bigserial PRIMARY KEY,
branch_id bigint REFERENCES branches(id) ON DELETE CASCADE,
user_id bigint REFERENCES users(id) ON DELETE CASCADE,
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_orders (
id bigserial PRIMARY KEY,
unique_id character varying(255),
@@ -200,7 +196,47 @@ CREATE TABLE IF NOT EXISTS loan_orders (
satisfiable character varying(255),
notes text,
created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
updated_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 loans (
id bigserial PRIMARY KEY,
user_id bigint,
passport_serie character varying(255) NOT NULL,
passport_id character varying(255) NOT NULL,
account_number character varying(255) NOT NULL,
created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
CONSTRAINT loans_user_id_fkey
FOREIGN KEY ("user_id") REFERENCES users(id)
);
CREATE TABLE IF NOT EXISTS loan_paid_off_letters (
id bigserial PRIMARY KEY,
unique_id character varying(255),
region character varying(2) NOT NULL,
branch_id bigint NOT NULL,
user_id bigint,
customer_name character varying(255) NOT NULL,
customer_surname character varying(255) NOT NULL,
customer_patronic_name character varying(255),
born_at date,
phone character varying(255) NOT NULL,
passport_serie character varying(255) NOT NULL,
passport_id character varying(255) NOT NULL,
status character varying(255),
notes text,
loan_contract_number character varying(255),
loan_contract_date date,
loan_amount character varying(255),
loan_reason character varying(255),
loan_file text,
created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
CONSTRAINT loan_paid_off_letters_branch_id_fkey
FOREIGN KEY ("branch_id") REFERENCES branches(id),
CONSTRAINT loan_paid_off_letters_user_id_fkey
FOREIGN KEY ("user_id") REFERENCES users(id)
);