mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Fix various migration issues (#5723)
* Indicate while backing up database * Close migrate connection to db before optimising * Don't vacuum post-migration In most cases is probably not needed and can be an optonal user-initiated step * Ensure connection close on NewMigrator error * Perform post-migration using migrator connection Flush WAL file at end of migration
This commit is contained in:
@@ -39,6 +39,12 @@ func NewMigrator(db *Database) (*Migrator, error) {
|
||||
m.conn.SetConnMaxIdleTime(dbConnTimeout)
|
||||
|
||||
m.m, err = m.getMigrate()
|
||||
|
||||
// if error encountered, close the connection
|
||||
if err != nil {
|
||||
m.Close()
|
||||
}
|
||||
|
||||
return m, err
|
||||
}
|
||||
|
||||
@@ -124,6 +130,27 @@ func (m *Migrator) runCustomMigration(ctx context.Context, fn customMigrationFun
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Migrator) PostMigrate(ctx context.Context) error {
|
||||
// optimise the database
|
||||
var err error
|
||||
logger.Info("Running database analyze")
|
||||
|
||||
// don't use Optimize/vacuum as this adds a significant amount of time
|
||||
// to the migration
|
||||
err = analyze(ctx, m.conn)
|
||||
|
||||
if err == nil {
|
||||
logger.Debug("Flushing WAL")
|
||||
err = flushWAL(ctx, m.conn)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("error optimising database: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *Database) getDatabaseSchemaVersion() (uint, error) {
|
||||
m, err := NewMigrator(db)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user