feat: add idempotent calendar bootstrap

Bootstrap independently reviewed catalogs through audited import, approval, and initial activation transitions, then resume insight scheduling safely.
This commit is contained in:
2026-08-23 02:24:16 +08:00
parent 72238e7e87
commit 5673b60ba6
7 changed files with 671 additions and 49 deletions

View File

@@ -12,7 +12,7 @@ Go backend for merchant authentication, one-time payment-data ingestion, determi
| `go run ./cmd/api` | Start the HTTP API on `HTTP_ADDR` | Long-running |
| `go run ./cmd/worker` | Process queued growth reports, page insights, and growth-coach jobs | Long-running alongside the API |
| `go run ./cmd/scheduler` | Enqueue due growth-coach work when `AI_COACH_ENABLED=true` | Optional long-running process |
| `go run ./cmd/calendar --help` | Import, approve, or activate reviewed calendar catalogs | Administrative/optional |
| `go run ./cmd/calendar --help` | Bootstrap or rotate independently reviewed calendar catalogs | Administrative/optional |
| `go run ./cmd/admin-reset-ai` | Reset AI-related administrative state | Administrative/recovery only |
The importer is checksum-idempotent: importing the same archive again is a safe no-op. It is not a file watcher or scheduled ETL process. The worker does not replace the API; both processes should run at the same time.
@@ -122,6 +122,17 @@ Run these commands from the repository root and in this order:
go mod download
go run ./cmd/migrate
go run ./cmd/importer
```
When calendar-dependent growth features are enabled, bootstrap an independently reviewed external catalog after the importer and before `cmd/admin`/application startup:
```bash
go run ./cmd/calendar -action bootstrap -file /path/to/reviewed-calendar.json -current-jalali-year 1405 -reviewer reviewer-id -actor operator-id
```
The command rejects bundled review candidates, resumes the same reviewed version safely, and refuses to replace a different active version. Catalog rotation continues to use the explicit import, approve, and activate actions. Finish setup by creating the demo user:
```bash
go run ./cmd/admin
```
@@ -243,6 +254,7 @@ docker compose build backend frontend
docker compose up -d postgres redis
docker compose --profile tools run --rm migrate
docker compose --profile import run --rm importer
docker compose --profile tools run --rm calendar
docker compose --profile tools run --rm admin
docker compose up -d backend worker frontend
docker compose ps