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:
Mikhail ChusavitinandClaude Opus 5.5 committed 2026-09-24 12:21:53 +03:00
1 parent 259bd48d2e
commit a2a1904d91
12 files changed
+374 -107

No files matched your search

+19 -1
View File
@@ -1,4 +1,4 @@
.PHONY: build build-release clean test run version install-hooks
.PHONY: build build-release clean test run version install-hooks migrate migrate-status migrate-baseline
# Get version from git
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
@@ -55,6 +55,24 @@ clean:
rm -rf bin/
rm -f $(BINARY)
# Server (MariaDB) migrations — migrations/*.sql tracked in qt_schema_migrations.
# Always built from the current source (go run), never a possibly stale bin/ binary.
# Uses the connection saved in the local app settings.
# List migrations with applied/pending state (read-only)
migrate-status:
go run ./cmd/qfs -migrate-status
# Apply pending migrations
migrate:
go run ./cmd/qfs -migrate
# Record migrations up to UPTO as applied WITHOUT running them (one-time, for a server
# whose schema is already current): make migrate-baseline UPTO=033_add_price_quality_to_pricelist_items.sql
migrate-baseline:
@test -n "$(UPTO)" || (echo "usage: make migrate-baseline UPTO=<file.sql>"; exit 1)
go run ./cmd/qfs -migrate-baseline "$(UPTO)"
# Run tests
test:
go test -v ./...