From 52fea1ddcfd667599b1943f410f121be4d9b8675 Mon Sep 17 00:00:00 2001 From: naskya Date: Mon, 22 Jan 2024 04:14:31 +0900 Subject: [PATCH] dev: add test for neko/revert.sql in Makefile --- Makefile | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e151ae69..00b3a3cc 100644 --- a/Makefile +++ b/Makefile @@ -22,9 +22,33 @@ MIGRATIONS += $(foreach dir, $(RUST_DIR)/migration/src, $(wildcard $(dir)/*)) UPDATE_SCRIPTS := update.sh UPDATE_SCRIPTS += $(foreach dir, neko/update, $(wildcard $(dir)/*)) +POSTGRES_USER := firefish +POSTGRES_DB := firefish_db +POSTGRES_PASSWORD := password +POSTGRES_HOST_PORT := localhost:25432 + .PHONY: pre-commit -pre-commit: format shellcheck update-lockfiles regenerate-entities neko/index.js rust-lint +pre-commit: test format shellcheck update-lockfiles regenerate-entities neko/index.js rust-lint + + +.PHONY: test +test: test-revert + + +.PHONY: test-revert +test-revert: $(T)/test-revert + +$(T)/test-revert: neko/revert.sql $(MIGRATIONS) + cd dev && \ + podman-compose exec db \ + psql \ + --echo-all \ + --user=$(POSTGRES_USER) \ + --dbname=$(POSTGRES_DB) \ + --set='ON_ERROR_STOP=1' \ + --command="$$(printf 'BEGIN;\n%s\nROLLBACK;' "$$(cat ../neko/revert.sql)")" + touch $@ .PHONY: update-lockfiles @@ -74,7 +98,7 @@ $(T)/regenerate-entities: $(MIGRATIONS) cd $(RUST_DIR) && \ sea-orm-cli generate entity \ --output-dir='src/model/entity' \ - --database-url='postgres://firefish:password@localhost:25432/firefish_db' \ + --database-url='postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@$(POSTGRES_HOST_PORT)/$(POSTGRES_DB)' \ --date-time-crate='chrono' \ --model-extra-attributes='NAPI_EXTRA_ATTR_PLACEHOLDER' && \ for file in src/model/entity/*; do \