From 30bcfefc1e4a7965eccff81dd779ff7b8c662adb Mon Sep 17 00:00:00 2001 From: GuwandykA Date: Fri, 7 Aug 2026 17:33:34 +0500 Subject: [PATCH] Merge activity_logs into init migration and ignore myapp binary. Co-authored-by: Cursor --- .gitignore | 1 + db/migrations/20260702125108_init.down.sql | 8 +- db/migrations/20260702125108_init.up.sql | 108 ++++++++++-------- .../20260716170338_activity_logs.down.sql | 1 - .../20260716170338_activity_logs.up.sql | 18 --- 5 files changed, 68 insertions(+), 68 deletions(-) delete mode 100644 db/migrations/20260716170338_activity_logs.down.sql delete mode 100644 db/migrations/20260716170338_activity_logs.up.sql diff --git a/.gitignore b/.gitignore index fc296ee..be3130c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Binaries online-back +myapp *.exe *.exe~ *.dll diff --git a/db/migrations/20260702125108_init.down.sql b/db/migrations/20260702125108_init.down.sql index a5c3472..00f40c7 100644 --- a/db/migrations/20260702125108_init.down.sql +++ b/db/migrations/20260702125108_init.down.sql @@ -1,15 +1,19 @@ +DROP TABLE IF EXISTS activity_logs; DROP TABLE IF EXISTS cards; DROP TABLE IF EXISTS card_pin_orders; DROP TABLE IF EXISTS card_orders; 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; DROP TABLE IF EXISTS loan_types; +DROP TABLE IF EXISTS branch_user; +DROP TABLE IF EXISTS permission_user; +DROP TABLE IF EXISTS role_user; +DROP TABLE IF EXISTS roles; +DROP TABLE IF EXISTS permissions; DROP TABLE IF EXISTS card_states; 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 ffa4eed..6671e2b 100644 --- a/db/migrations/20260702125108_init.up.sql +++ b/db/migrations/20260702125108_init.up.sql @@ -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); diff --git a/db/migrations/20260716170338_activity_logs.down.sql b/db/migrations/20260716170338_activity_logs.down.sql deleted file mode 100644 index b6a2017..0000000 --- a/db/migrations/20260716170338_activity_logs.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS activity_logs; diff --git a/db/migrations/20260716170338_activity_logs.up.sql b/db/migrations/20260716170338_activity_logs.up.sql deleted file mode 100644 index 5cfff61..0000000 --- a/db/migrations/20260716170338_activity_logs.up.sql +++ /dev/null @@ -1,18 +0,0 @@ -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);