From f80db99359cef51fba34b92aaa30d8695781a13c Mon Sep 17 00:00:00 2001 From: Kerod-Fresenbet-Gebremedhin2660 Date: Wed, 9 Jul 2025 18:40:13 +0300 Subject: [PATCH 2/5] changed restore target makefile --- makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/makefile b/makefile index 6f12878..13a8a04 100644 --- a/makefile +++ b/makefile @@ -49,7 +49,9 @@ backup: @docker exec -t fortunebet-backend-postgres-1 pg_dumpall -c -U root > backup/dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql restore: @echo "Restoring latest backup..." - docker exec -i fortunebet-backend-postgres-1 psql -U root -d gh < $(file) + @latest_file=$$(ls -t backup/dump_*.sql | head -n 1); \ + echo "Restoring from $$latest_file"; \ + docker exec -i fortunebet-backend-postgres-1 psql -U root -d gh < $$latest_file postgres_log: docker logs fortunebet-backend-postgres-1 .PHONY: swagger From 7e52ba5be61de1175c9ba63960802ae777773ef6 Mon Sep 17 00:00:00 2001 From: Samuel Tariku Date: Thu, 10 Jul 2025 00:15:30 +0300 Subject: [PATCH 5/5] fix: persistence fix and compression --- .gitignore | 5 +- db/migrations/000001_fortune.up.sql | 238 +--------------------------- makefile | 16 +- 3 files changed, 18 insertions(+), 241 deletions(-) diff --git a/.gitignore b/.gitignore index f9cc30c..036c1c6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,7 @@ coverage tmp build *.log -backup/ \ No newline at end of file +logs/ +app_logs/ +backup/ + diff --git a/db/migrations/000001_fortune.up.sql b/db/migrations/000001_fortune.up.sql index b435356..5228f1e 100644 --- a/db/migrations/000001_fortune.up.sql +++ b/db/migrations/000001_fortune.up.sql @@ -471,240 +471,4 @@ ADD CONSTRAINT fk_branch_cashiers_users FOREIGN KEY (user_id) REFERENCES users(i ADD CONSTRAINT fk_branch_cashiers_branches FOREIGN KEY (branch_id) REFERENCES branches(id) ON DELETE CASCADE; ALTER TABLE companies ADD CONSTRAINT fk_companies_admin FOREIGN KEY (admin_id) REFERENCES users(id), - ADD CONSTRAINT fk_companies_wallet FOREIGN KEY (wallet_id) REFERENCES wallets(id) ON DELETE CASCADE; -----------------------------------------------seed data------------------------------------------------------------- --------------------------------------- DO NOT USE IN PRODUCTION------------------------------------------------- -CREATE EXTENSION IF NOT EXISTS pgcrypto; -INSERT INTO users ( - first_name, - last_name, - email, - phone_number, - password, - role, - email_verified, - phone_verified, - created_at, - updated_at, - suspended_at, - suspended - ) -VALUES ( - 'John', - 'Doe', - 'john.doe@example.com', - NULL, - crypt('password123', gen_salt('bf'))::bytea, - 'customer', - TRUE, - FALSE, - CURRENT_TIMESTAMP, - CURRENT_TIMESTAMP, - NULL, - FALSE - ); -INSERT INTO wallets ( - balance, - is_withdraw, - is_bettable, - is_transferable, - user_id, - is_active, - created_at, - updated_at - ) -VALUES ( - 10000, - TRUE, - TRUE, - TRUE, - 1, - TRUE, - CURRENT_TIMESTAMP, - CURRENT_TIMESTAMP - ); -INSERT INTO wallets ( - balance, - is_withdraw, - is_bettable, - is_transferable, - user_id, - is_active, - created_at, - updated_at - ) -VALUES ( - 10000, - FALSE, - TRUE, - TRUE, - 1, - TRUE, - CURRENT_TIMESTAMP, - CURRENT_TIMESTAMP - ); -INSERT INTO customer_wallets ( - customer_id, - regular_wallet_id, - static_wallet_id - ) -VALUES (1, 1, 2); -INSERT INTO users ( - first_name, - last_name, - email, - phone_number, - password, - role, - email_verified, - phone_verified, - created_at, - updated_at, - suspended_at, - suspended, - company_id - ) -VALUES ( - 'Test', - 'Admin', - 'test.admin@gmail.com', - '0988554466', - crypt('password123', gen_salt('bf'))::bytea, - 'admin', - TRUE, - TRUE, - CURRENT_TIMESTAMP, - CURRENT_TIMESTAMP, - NULL, - FALSE, - 1 - ); -INSERT INTO users ( - first_name, - last_name, - email, - phone_number, - password, - role, - email_verified, - phone_verified, - created_at, - updated_at, - suspended_at, - suspended - ) -VALUES ( - 'Samuel', - 'Tariku', - 'cybersamt@gmail.com', - '0911111111', - crypt('password@123', gen_salt('bf'))::bytea, - 'super_admin', - TRUE, - TRUE, - CURRENT_TIMESTAMP, - CURRENT_TIMESTAMP, - NULL, - FALSE - ); -INSERT INTO users ( - first_name, - last_name, - email, - phone_number, - password, - role, - email_verified, - phone_verified, - created_at, - updated_at, - suspended_at, - suspended - ) -VALUES ( - 'Kirubel', - 'Kibru', - 'kirubeljkl679 @gmail.com', - '0911554486', - crypt('password@123', gen_salt('bf'))::bytea, - 'super_admin', - TRUE, - TRUE, - CURRENT_TIMESTAMP, - CURRENT_TIMESTAMP, - NULL, - FALSE - ); -INSERT INTO supported_operations (name, description) -VALUES ('SportBook', 'Sportbook operations'), - ('Virtual', 'Virtual operations'); -INSERT INTO wallets ( - balance, - is_withdraw, - is_bettable, - is_transferable, - user_id, - is_active, - created_at, - updated_at - ) -VALUES ( - 10000, - TRUE, - TRUE, - TRUE, - 2, - TRUE, - CURRENT_TIMESTAMP, - CURRENT_TIMESTAMP - ); -INSERT INTO companies ( - name, - admin_id, - wallet_id - ) -values ( - 'Test Company', - 2, - 3 - ); -INSERT INTO wallets ( - balance, - is_withdraw, - is_bettable, - is_transferable, - user_id, - is_active, - created_at, - updated_at - ) -VALUES ( - 10000, - TRUE, - TRUE, - TRUE, - 2, - TRUE, - CURRENT_TIMESTAMP, - CURRENT_TIMESTAMP - ); -INSERT INTO branches ( - name, - location, - wallet_id, - branch_manager_id, - company_id, - is_self_owned, - created_at, - updated_at - ) -values ( - 'Test Branch', - 'Addis Ababa', - 4, - 2, - 1, - TRUE, - CURRENT_TIMESTAMP, - CURRENT_TIMESTAMP - ); \ No newline at end of file + ADD CONSTRAINT fk_companies_wallet FOREIGN KEY (wallet_id) REFERENCES wallets(id) ON DELETE CASCADE; \ No newline at end of file diff --git a/makefile b/makefile index 3fd5edf..3a9b398 100644 --- a/makefile +++ b/makefile @@ -49,9 +49,12 @@ backup: @docker exec -t fortunebet-backend-postgres-1 pg_dumpall -c -U root | gzip > backup/dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql.gz restore: @echo "Restoring latest backup..." - @latest_file=$$(ls -t backup/dump_*.sql | head -n 1); \ + @latest_file=$$(ls -t backup/dump_*.sql.gz | head -n 1); \ echo "Restoring from $$latest_file"; \ - gunzip -c $$latest_file | docker exec -i fortunebet-backend-postgres-1 psql -U root -d gh < $$latest_file + gunzip -c $$latest_file | docker exec -i fortunebet-backend-postgres-1 psql -U root -d gh +restore_file: + @echo "Restoring latest backup..." + gunzip -c $(file) | docker exec -i fortunebet-backend-postgres-1 psql -U root -d gh postgres_log: docker logs fortunebet-backend-postgres-1 .PHONY: swagger @@ -59,7 +62,10 @@ swagger: @swag init -g cmd/main.go .PHONY: db-up -db-up: +logs: + @mkdir -p logs +db-up: | logs + @mkdir -p logs @docker compose up -d postgres migrate mongo redis @docker logs fortunebet-backend-postgres-1 > logs/postgres.log 2>&1 & .PHONY: db-down @@ -69,3 +75,7 @@ db-down: .PHONY: sqlc-gen sqlc-gen: @sqlc generate +app_log: + @mkdir -p app_logs +export_logs: | app_log + @docker exec fortunebet-mongo mongoexport --db=logdb --collection=applogs -u root -p secret --authenticationDatabase=admin --out - > app_logs/log_`date +%Y-%m-%d"_"%H_%M_%S`.json