2026-05-01 16:01:55 +08:00
|
|
|
.PHONY: dev-init dev-api dev-worker-generate dev-scheduler dev-ops-api migrate-up migrate-down migrate-monitoring-up migrate-monitoring-down migrate-ops-up migrate-ops-down migrate-create migrate-ops-create sqlc-generate tenant-scope-guard lint test tidy seed seed-platform-templates
|
2026-04-01 00:58:42 +08:00
|
|
|
|
|
|
|
|
DB_URL ?= postgres://geo:geo_dev@localhost:5432/geo?sslmode=disable
|
2026-04-12 09:56:18 +08:00
|
|
|
MONITORING_DB_URL ?= postgres://geo:geo_dev@localhost:5433/geo_monitoring?sslmode=disable
|
2026-04-28 11:32:50 +08:00
|
|
|
# ops 迁移与主迁移共用 geo 数据库,必须使用独立 schema_migrations_ops 表,
|
|
|
|
|
# 否则两套迁移会互相看到对方的版本号并报 "no migration found"。
|
|
|
|
|
OPS_DB_URL ?= postgres://geo:geo_dev@localhost:5432/geo?sslmode=disable&x-migrations-table=schema_migrations_ops
|
2026-04-01 00:58:42 +08:00
|
|
|
MIGRATE_CMD ?= go run -tags postgres github.com/golang-migrate/migrate/v4/cmd/migrate@v4.19.1
|
|
|
|
|
|
|
|
|
|
dev-init: ## Start infra, run migrations, seed data
|
|
|
|
|
docker compose up -d
|
|
|
|
|
@echo "Waiting for postgres..."
|
|
|
|
|
@sleep 3
|
|
|
|
|
$(MAKE) migrate-up
|
2026-04-12 09:56:18 +08:00
|
|
|
$(MAKE) migrate-monitoring-up
|
2026-04-28 11:32:50 +08:00
|
|
|
$(MAKE) migrate-ops-up
|
2026-04-01 00:58:42 +08:00
|
|
|
$(MAKE) seed
|
|
|
|
|
|
|
|
|
|
dev-api: ## Run tenant-api server
|
|
|
|
|
go run ./cmd/tenant-api
|
|
|
|
|
|
2026-04-15 14:19:21 +08:00
|
|
|
dev-worker-generate: ## Run article generation worker
|
|
|
|
|
go run ./cmd/worker-generate
|
|
|
|
|
|
|
|
|
|
dev-scheduler: ## Run scheduler workers
|
|
|
|
|
go run ./cmd/scheduler
|
|
|
|
|
|
2026-04-28 11:32:50 +08:00
|
|
|
dev-ops-api: ## Run ops-api server (internal operations console backend)
|
2026-05-02 19:26:10 +08:00
|
|
|
go run ./cmd/ops-api
|
2026-04-28 11:32:50 +08:00
|
|
|
|
2026-04-01 00:58:42 +08:00
|
|
|
migrate-up: ## Run all pending migrations
|
|
|
|
|
$(MIGRATE_CMD) -path migrations -database "$(DB_URL)" up
|
|
|
|
|
|
|
|
|
|
migrate-down: ## Rollback last migration
|
|
|
|
|
$(MIGRATE_CMD) -path migrations -database "$(DB_URL)" down 1
|
|
|
|
|
|
2026-04-12 09:56:18 +08:00
|
|
|
migrate-monitoring-up: ## Run all pending monitoring migrations
|
|
|
|
|
$(MIGRATE_CMD) -path migrations_monitoring -database "$(MONITORING_DB_URL)" up
|
|
|
|
|
|
|
|
|
|
migrate-monitoring-down: ## Rollback last monitoring migration
|
|
|
|
|
$(MIGRATE_CMD) -path migrations_monitoring -database "$(MONITORING_DB_URL)" down 1
|
|
|
|
|
|
2026-04-28 11:32:50 +08:00
|
|
|
migrate-ops-up: ## Run all pending ops migrations (operator accounts, audit logs)
|
|
|
|
|
$(MIGRATE_CMD) -path migrations_ops -database "$(OPS_DB_URL)" up
|
|
|
|
|
|
|
|
|
|
migrate-ops-down: ## Rollback last ops migration
|
|
|
|
|
$(MIGRATE_CMD) -path migrations_ops -database "$(OPS_DB_URL)" down 1
|
|
|
|
|
|
2026-04-01 00:58:42 +08:00
|
|
|
migrate-create: ## Create new migration (usage: make migrate-create NAME=xxx)
|
|
|
|
|
$(MIGRATE_CMD) create -ext sql -dir migrations -seq $(NAME)
|
|
|
|
|
|
2026-04-28 11:32:50 +08:00
|
|
|
migrate-ops-create: ## Create new ops migration (usage: make migrate-ops-create NAME=xxx)
|
|
|
|
|
$(MIGRATE_CMD) create -ext sql -dir migrations_ops -seq $(NAME)
|
|
|
|
|
|
2026-04-01 00:58:42 +08:00
|
|
|
sqlc-generate: ## Generate typed Go code from SQL queries
|
|
|
|
|
cd internal/tenant/repository && sqlc generate
|
|
|
|
|
|
|
|
|
|
tenant-scope-guard: ## Ensure tenant-scoped SQL includes tenant_id filters
|
|
|
|
|
bash scripts/check_tenant_scope.sh
|
|
|
|
|
|
|
|
|
|
seed: ## Insert development seed data
|
|
|
|
|
go run ./cmd/dev-seed
|
|
|
|
|
|
2026-05-01 16:01:55 +08:00
|
|
|
seed-platform-templates: ## Insert or update built-in platform templates
|
|
|
|
|
go run ./cmd/seed-platform-templates
|
|
|
|
|
|
2026-04-01 00:58:42 +08:00
|
|
|
lint: ## Run linter
|
|
|
|
|
golangci-lint run ./...
|
|
|
|
|
|
|
|
|
|
test: ## Run all tests
|
|
|
|
|
go test ./... -count=1
|
|
|
|
|
|
|
|
|
|
tidy: ## Tidy go modules
|
|
|
|
|
go mod tidy
|