Enhance Makefile with new database management targets

- Add db-drop-schema target to facilitate schema deletion and recreation for development purposes.
- Introduce db-reset-hard target to streamline the process of resetting the database and seeding data after schema changes.
- Update .PHONY targets for improved clarity and maintainability.
This commit is contained in:
Xin Wang
2026-07-07 21:58:56 +08:00
parent f00d50dc81
commit 6e4c50eee6

View File

@@ -7,7 +7,7 @@
PSQL = docker compose exec -T postgres psql -U postgres -d postgres
.DEFAULT_GOAL := help
.PHONY: help up down restart logs api-logs db db-list db-seed db-seed-model-resources db-seed-assistants db-clear db-reset
.PHONY: help up down restart logs api-logs db db-list db-seed db-seed-model-resources db-seed-assistants db-clear db-reset db-drop-schema db-reset-hard
help: ## 列出所有可用目标
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
@@ -49,3 +49,10 @@ db-clear: ## 清空 助手/知识库/模型资源(按依赖顺序;表不存在
@$(PSQL) -c "DO \$$\$$ BEGIN IF EXISTS (SELECT FROM pg_tables WHERE schemaname = 'public' AND tablename = 'model_resources') THEN TRUNCATE assistant_model_bindings, assistants, knowledge_bases, model_resources CASCADE; END IF; END \$$\$$;"
db-reset: db-clear db-seed ## 清空后重新灌全部种子
db-drop-schema: ## 删除并重建 public schema(开发用:表结构变更后会清空全部数据)
@$(PSQL) -c "DROP SCHEMA IF EXISTS public CASCADE; CREATE SCHEMA public;"
db-reset-hard: db-drop-schema restart ## 重建 schema,重启 api 让 init_db 建表,再灌种子
sleep 3
$(MAKE) db-seed