fix: verify server snapshots and recover whole migration sessions (#3)
This commit is contained in:
1 parent
3d4101ecc0
commit
8569871a17
29 files changed
+1923
-133
No files matched your search
+13
-2
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
qfassets "git.mchus.pro/mchus/quoteforge"
|
||||
"git.mchus.pro/mchus/quoteforge/internal/appstate"
|
||||
"git.mchus.pro/mchus/quoteforge/internal/localdb"
|
||||
"git.mchus.pro/mchus/quoteforge/internal/models"
|
||||
mysqlDriver "github.com/go-sql-driver/mysql"
|
||||
@@ -39,6 +40,12 @@ func openMigrationDB(local *localdb.LocalDB) (*gorm.DB, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("connect to server: %w", err)
|
||||
}
|
||||
sqlDB, err := db.DB()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("migration pool: %w", err)
|
||||
}
|
||||
sqlDB.SetMaxOpenConns(1)
|
||||
sqlDB.SetMaxIdleConns(1)
|
||||
return db, nil
|
||||
}
|
||||
|
||||
@@ -68,7 +75,7 @@ func runMigrateStatus(db *gorm.DB) error {
|
||||
// runMigrateApply applies pending server migrations. Refuses on a server with no
|
||||
// migration history at all: its schema was built by other means, so every file would be
|
||||
// re-run — record a baseline with -migrate-baseline first.
|
||||
func runMigrateApply(db *gorm.DB) error {
|
||||
func runMigrateApply(db *gorm.DB, localDBPath string) error {
|
||||
migrations, err := qfassets.MigrationsFS()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -76,9 +83,13 @@ func runMigrateApply(db *gorm.DB) error {
|
||||
if err := requireMigrationHistory(db, migrations); err != nil {
|
||||
return err
|
||||
}
|
||||
backupRoot, err := appstate.ServerMigrationBackupDir(localDBPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
applied, err := models.RunSQLMigrations(db, migrations, func(filename string) {
|
||||
fmt.Printf(" applying %s ...\n", filename)
|
||||
})
|
||||
}, backupRoot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user