mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 07:32:32 +01:00
feat(db): add embedded auto-migrating schema system
Replace 4 independent schema management code paths (Docker shell script, setup wizard pg_restore, test helpers, manual psql) with a single migration runner embedded in the server binary. The new server/migrations/ package uses Go embed to bundle all SQL schemas. On startup, Migrate() creates a schema_version tracking table, detects existing databases (auto-marks baseline as applied), and runs pending migrations in transactions. Key changes: - Consolidated init.sql + 9.2-update + 33 patches into 0001_init.sql - Setup wizard simplified to single "Apply schema" checkbox - Test helpers use migrations.Migrate() instead of pg_restore - Docker no longer needs schema volume mounts or init script - Seed data (shops, events, gacha) embedded and applied via API - Future migrations just add 0002_*.sql files — no manual steps
This commit is contained in:
11
main.go
11
main.go
@@ -16,6 +16,7 @@ import (
|
||||
"erupe-ce/server/channelserver"
|
||||
"erupe-ce/server/discordbot"
|
||||
"erupe-ce/server/entranceserver"
|
||||
"erupe-ce/server/migrations"
|
||||
"erupe-ce/server/setup"
|
||||
"erupe-ce/server/signserver"
|
||||
"strings"
|
||||
@@ -154,6 +155,16 @@ func main() {
|
||||
|
||||
logger.Info("Database: Started successfully")
|
||||
|
||||
// Run database migrations
|
||||
applied, migErr := migrations.Migrate(db, logger.Named("migrations"))
|
||||
if migErr != nil {
|
||||
preventClose(config, fmt.Sprintf("Database migration failed: %s", migErr.Error()))
|
||||
}
|
||||
if applied > 0 {
|
||||
ver, _ := migrations.Version(db)
|
||||
logger.Info(fmt.Sprintf("Database: Applied %d migration(s), now at version %d", applied, ver))
|
||||
}
|
||||
|
||||
// Pre-compute all server IDs this instance will own, so we only
|
||||
// delete our own rows (safe for multi-instance on the same DB).
|
||||
var ownedServerIDs []string
|
||||
|
||||
Reference in New Issue
Block a user