feat(server/ops-api): add operations console backend

Stand up an internal ops-api service with operator account, auth, and
audit log subsystems backed by a dedicated migrations_ops migration set.
Wire Makefile targets and the migrate Dockerfile stage so the new schema
ships alongside the existing tenant + monitoring databases.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-28 11:32:50 +08:00
parent 299e7c311e
commit c091ad7aed
20 changed files with 1778 additions and 1 deletions
+17 -1
View File
@@ -1,7 +1,10 @@
.PHONY: dev-init dev-api dev-worker-generate dev-scheduler migrate-up migrate-down migrate-monitoring-up migrate-monitoring-down migrate-create sqlc-generate tenant-scope-guard lint test tidy seed
.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
DB_URL ?= postgres://geo:geo_dev@localhost:5432/geo?sslmode=disable
MONITORING_DB_URL ?= postgres://geo:geo_dev@localhost:5433/geo_monitoring?sslmode=disable
# 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
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
@@ -10,6 +13,7 @@ dev-init: ## Start infra, run migrations, seed data
@sleep 3
$(MAKE) migrate-up
$(MAKE) migrate-monitoring-up
$(MAKE) migrate-ops-up
$(MAKE) seed
dev-api: ## Run tenant-api server
@@ -21,6 +25,9 @@ dev-worker-generate: ## Run article generation worker
dev-scheduler: ## Run scheduler workers
go run ./cmd/scheduler
dev-ops-api: ## Run ops-api server (internal operations console backend)
CONFIG_PATH=configs/ops-config.yaml go run ./cmd/ops-api
migrate-up: ## Run all pending migrations
$(MIGRATE_CMD) -path migrations -database "$(DB_URL)" up
@@ -33,9 +40,18 @@ migrate-monitoring-up: ## Run all pending monitoring migrations
migrate-monitoring-down: ## Rollback last monitoring migration
$(MIGRATE_CMD) -path migrations_monitoring -database "$(MONITORING_DB_URL)" down 1
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
migrate-create: ## Create new migration (usage: make migrate-create NAME=xxx)
$(MIGRATE_CMD) create -ext sql -dir migrations -seq $(NAME)
migrate-ops-create: ## Create new ops migration (usage: make migrate-ops-create NAME=xxx)
$(MIGRATE_CMD) create -ext sql -dir migrations_ops -seq $(NAME)
sqlc-generate: ## Generate typed Go code from SQL queries
cd internal/tenant/repository && sqlc generate