- Add new database management targets: db-up, db-schema, db-seed-interface-definitions, and db-init to streamline database setup and seeding processes. - Update db-seed and db-reset dependencies to include new initialization steps for better data integrity. - Introduce new SQL files for schema definition and interface definitions seeding, ensuring a consistent database structure. - Refactor existing seed scripts to align with new dependencies and improve clarity in database operations.
68 lines
2.8 KiB
Makefile
68 lines
2.8 KiB
Makefile
# AI Video Assistant 平台 —— 开发常用命令
|
|
#
|
|
# 用法:make <目标>,例如 make up / make db-seed。
|
|
# 多数目标是对 docker compose 的薄封装,集中沉淀平时手敲的开发脚本。
|
|
|
|
# 容器内执行 psql 的固定前缀(postgres/postgres/postgres,见 docker-compose.yaml)
|
|
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-up db-schema db-seed-interface-definitions db-init 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) \
|
|
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-12s\033[0m %s\n", $$1, $$2}'
|
|
|
|
# ---- 服务编排 ----
|
|
up: ## 起 postgres + api + ui
|
|
docker compose up -d
|
|
|
|
down: ## 停掉所有服务(保留数据卷)
|
|
docker compose down
|
|
|
|
restart: ## 重建 api 容器(改了 env/CORS 后用)
|
|
docker compose up -d --force-recreate api
|
|
|
|
logs: ## 跟随全部服务日志
|
|
docker compose logs -f
|
|
|
|
api-logs: ## 只看后端日志
|
|
docker compose logs -f api
|
|
|
|
# ---- 数据库 ----
|
|
db: ## 进入交互式 psql
|
|
docker compose exec postgres psql -U postgres -d postgres
|
|
|
|
db-list: ## 列出模型资源与助手
|
|
@$(PSQL) -c "SELECT id, name, capability, interface_type, is_default FROM model_resources ORDER BY id;"
|
|
@$(PSQL) -c "SELECT id, name, type FROM assistants ORDER BY id;"
|
|
|
|
db-up: ## 仅启动 postgres
|
|
docker compose up -d postgres
|
|
|
|
db-schema: ## 用纯 SQL 建表/补齐开发库表结构
|
|
$(PSQL) < backend/db/schema.sql
|
|
|
|
db-seed-interface-definitions: ## 灌入接口定义种子(幂等)
|
|
$(PSQL) < backend/db/seed_interface_definitions.sql
|
|
|
|
db-init: db-schema db-seed-interface-definitions ## 用纯 SQL 建表并同步接口定义
|
|
|
|
db-seed-model-resources: ## 灌入 12 条模型资源种子(幂等)
|
|
$(PSQL) < backend/db/seed_model_resources.sql
|
|
|
|
db-seed-assistants: ## 灌入 知识库 + 助手 种子(幂等;依赖模型资源已就绪)
|
|
$(PSQL) < backend/db/seed_assistants.sql
|
|
|
|
db-seed: db-init db-seed-model-resources db-seed-assistants ## 全量灌种子(接口定义→模型资源→知识库→助手,幂等,可重复执行)
|
|
|
|
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-up db-clear db-seed ## 启动库、建表/清空后重新灌全部种子
|
|
|
|
db-drop-schema: ## 删除并重建 public schema(开发用:表结构变更后会清空全部数据)
|
|
@$(PSQL) -c "DROP SCHEMA IF EXISTS public CASCADE; CREATE SCHEMA public;"
|
|
|
|
db-reset-hard: db-up db-drop-schema db-seed ## 启动库、重建 schema,建表,再灌种子
|