feat: make migrate — серверные SQL-миграции вместо AutoMigrate
`qfs -migrate` теперь применяет только migrations/*.sql (встроены в бинарник) с учётом в qt_schema_migrations и завершается, не запуская приложение. Новые команды: make migrate-status (read-only список applied/pending), make migrate, make migrate-baseline UPTO=<file> (пометить как применённые без выполнения). migrate отказывается работать, если в истории нет ни одной применённой миграции — иначе все файлы пошли бы заново. Удалён GORM AutoMigrate против MariaDB (models.Migrate, SeedCategories): устаревший бинарник v1.18 с -migrate прогнал по боевой базе AutoMigrate своих моделей. Миграции идут через отдельное соединение без read/write таймаутов — 3s-таймаут sync-соединения обрывал backfill в 032. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
259bd48d2e
commit
a2a1904d91
12 files changed
+374
-107
No files matched your search
@@ -57,7 +57,7 @@ Server-side only (not queried by client runtime):
|
||||
- `qt_lot_metadata` — component metadata / price settings; the Go server-side component/category management layer (`ComponentRepository`, `CategoryRepository`, `ComponentService`) was removed — no client code reads this table
|
||||
- `qt_component_usage_stats` — aggregated component popularity stats (written by server jobs)
|
||||
- `qt_pricing_alerts` — price anomaly alerts (models exist in Go; feature disabled in runtime)
|
||||
- `qt_schema_migrations` — server migration history (applied via `go run ./cmd/qfs -migrate`)
|
||||
- `qt_schema_migrations` — server migration history (applied via `make migrate`, see [Migrations](#migrations))
|
||||
- `qt_scheduler_runs` — server background job tracking (no Go code references it in this repo)
|
||||
|
||||
### Competitor subsystem (server-side only, not used by QuoteForge Go code)
|
||||
@@ -427,5 +427,20 @@ SQLite:
|
||||
- local migration state is tracked in `local_schema_migrations`.
|
||||
|
||||
MariaDB:
|
||||
- SQL files live in `migrations/`;
|
||||
- they are applied by `go run ./cmd/qfs -migrate`.
|
||||
- SQL files live in `migrations/` (embedded into the binary), one file per change,
|
||||
`NNN_short_topic.sql`, with the recovery/verify header used by the existing files;
|
||||
filenames containing `local_` are SQLite-only and skipped;
|
||||
- applied state is tracked per filename in `qt_schema_migrations`;
|
||||
- commands (always from current source — never run a `bin/` binary of unknown age):
|
||||
- `make migrate-status` (`qfs -migrate-status`) — list applied/pending, read-only;
|
||||
- `make migrate` (`qfs -migrate`) — apply pending files in filename order, then exit;
|
||||
refuses when `qt_schema_migrations` has no applied rows at all (every file would re-run);
|
||||
- `make migrate-baseline UPTO=<file.sql>` (`qfs -migrate-baseline`) — record files up to
|
||||
`UPTO` as applied **without running them**, for a server whose schema is already current;
|
||||
- migrations use their own connection without read/write timeouts (`openMigrationDB`),
|
||||
not the app's 3s-timeout sync connection — a long backfill must not be cut mid-file;
|
||||
- a file is recorded only after all its statements succeed, so each file must be safe to
|
||||
re-run (`ADD COLUMN IF NOT EXISTS`, idempotent `UPDATE ... WHERE <not yet done>`);
|
||||
- there is no GORM `AutoMigrate` against MariaDB: it retypes production columns to match the
|
||||
running binary's models. On 2026-09-24 a stale v1.18 binary run with the old AutoMigrate
|
||||
`-migrate` did exactly that, which is why it was removed.
|
||||
Reference in new issue
Block a user