|
|
|
|
@@ -1,38 +1,37 @@
|
|
|
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
|
|
|
"id" bigserial primary key,
|
|
|
|
|
"email" character varying(250) NOT NULL DEFAULT '',
|
|
|
|
|
"password" 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',
|
|
|
|
|
"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 users (
|
|
|
|
|
id bigserial PRIMARY KEY,
|
|
|
|
|
email character varying(250) NOT NULL DEFAULT '',
|
|
|
|
|
password 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 NOT NULL DEFAULT 1,
|
|
|
|
|
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, password, name, email, role
|
|
|
|
|
) values (
|
|
|
|
|
'61531216',
|
|
|
|
|
'$2a$12$8ZbKmoSwna4CASQptM2/SubwvsBUR1YhABULd.2/QJB.13Wi2v55m',
|
|
|
|
|
'Admin',
|
|
|
|
|
'admin@admin.com',
|
|
|
|
|
'admin'
|
|
|
|
|
);
|
|
|
|
|
INSERT INTO users (phone, password, name, 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
|
|
|
|
|
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 (
|
|
|
|
|
@@ -52,12 +51,10 @@ CREATE TABLE IF NOT EXISTS branches (
|
|
|
|
|
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,
|
|
|
|
|
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 branches_province_id_fkey
|
|
|
|
|
FOREIGN KEY ("province_id")
|
|
|
|
|
REFERENCES provinces("id")
|
|
|
|
|
ON UPDATE CASCADE
|
|
|
|
|
FOREIGN KEY (province_id) REFERENCES provinces(id) ON UPDATE CASCADE
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS card_types (
|
|
|
|
|
@@ -66,8 +63,8 @@ CREATE TABLE IF NOT EXISTS card_types (
|
|
|
|
|
price character varying(255) NOT NULL DEFAULT '',
|
|
|
|
|
notes 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
|
|
|
|
|
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 card_states (
|
|
|
|
|
@@ -213,7 +210,6 @@ CREATE TABLE IF NOT EXISTS loan_orders (
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS loans (
|
|
|
|
|
@@ -225,7 +221,7 @@ CREATE TABLE IF NOT EXISTS loans (
|
|
|
|
|
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)
|
|
|
|
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS loan_paid_off_letters (
|
|
|
|
|
@@ -251,9 +247,9 @@ CREATE TABLE IF NOT EXISTS loan_paid_off_letters (
|
|
|
|
|
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),
|
|
|
|
|
FOREIGN KEY (branch_id) REFERENCES branches(id),
|
|
|
|
|
CONSTRAINT loan_paid_off_letters_user_id_fkey
|
|
|
|
|
FOREIGN KEY ("user_id") REFERENCES users(id)
|
|
|
|
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS card_orders (
|
|
|
|
|
@@ -290,13 +286,13 @@ CREATE TABLE IF NOT EXISTS card_orders (
|
|
|
|
|
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 card_orders_card_state_id_fkey
|
|
|
|
|
FOREIGN KEY ("card_state_id") REFERENCES card_states(id),
|
|
|
|
|
FOREIGN KEY (card_state_id) REFERENCES card_states(id),
|
|
|
|
|
CONSTRAINT card_orders_card_type_id_fkey
|
|
|
|
|
FOREIGN KEY ("card_type_id") REFERENCES card_types(id),
|
|
|
|
|
FOREIGN KEY (card_type_id) REFERENCES card_types(id),
|
|
|
|
|
CONSTRAINT card_orders_branch_id_fkey
|
|
|
|
|
FOREIGN KEY ("branch_id") REFERENCES branches(id),
|
|
|
|
|
FOREIGN KEY (branch_id) REFERENCES branches(id),
|
|
|
|
|
CONSTRAINT card_orders_user_id_fkey
|
|
|
|
|
FOREIGN KEY ("user_id") REFERENCES users(id)
|
|
|
|
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS card_pin_orders (
|
|
|
|
|
@@ -323,11 +319,11 @@ CREATE TABLE IF NOT EXISTS card_pin_orders (
|
|
|
|
|
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 card_pin_orders_card_type_id_fkey
|
|
|
|
|
FOREIGN KEY ("card_type_id") REFERENCES card_types(id),
|
|
|
|
|
FOREIGN KEY (card_type_id) REFERENCES card_types(id),
|
|
|
|
|
CONSTRAINT card_pin_orders_branch_id_fkey
|
|
|
|
|
FOREIGN KEY ("branch_id") REFERENCES branches(id),
|
|
|
|
|
FOREIGN KEY (branch_id) REFERENCES branches(id),
|
|
|
|
|
CONSTRAINT card_pin_orders_user_id_fkey
|
|
|
|
|
FOREIGN KEY ("user_id") REFERENCES users(id)
|
|
|
|
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS cards (
|
|
|
|
|
@@ -341,6 +337,24 @@ CREATE TABLE IF NOT EXISTS cards (
|
|
|
|
|
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 cards_user_id_fkey
|
|
|
|
|
FOREIGN KEY ("user_id") REFERENCES users(id)
|
|
|
|
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS activity_logs (
|
|
|
|
|
id bigserial PRIMARY KEY,
|
|
|
|
|
user_id bigint,
|
|
|
|
|
method character varying(10) NOT NULL DEFAULT '',
|
|
|
|
|
path character varying(255) NOT NULL DEFAULT '',
|
|
|
|
|
module character varying(100) NOT NULL DEFAULT '',
|
|
|
|
|
action character varying(50) NOT NULL DEFAULT '',
|
|
|
|
|
status_code integer NOT NULL DEFAULT 0,
|
|
|
|
|
request_body jsonb,
|
|
|
|
|
ip character varying(50) NOT NULL DEFAULT '',
|
|
|
|
|
created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
|
|
|
|
|
CONSTRAINT activity_logs_user_id_fkey
|
|
|
|
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_activity_logs_user_id ON activity_logs(user_id);
|
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_activity_logs_module ON activity_logs(module);
|
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_activity_logs_created_at ON activity_logs(created_at);
|
|
|
|
|
|