Skip to content

Commit

Permalink
make sure the migration step runs with transactions, so that we can d…
Browse files Browse the repository at this point in the history
…ebug easier.

- related #256
  • Loading branch information
AnalogJ committed May 24, 2022
1 parent 1423f55 commit 97add04
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions webapp/backend/pkg/database/scrutiny_repository_migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ func (sr *scrutinyRepository) Migrate(ctx context.Context) error {

sr.logger.Infoln("Database migration starting")

m := gormigrate.New(sr.gormClient, gormigrate.DefaultOptions, []*gormigrate.Migration{
gormMigrateOptions := &gormigrate.Options{
TableName: "migrations",
IDColumnName: "id",
IDColumnSize: 255,
UseTransaction: true, //use transactions (easier to debug in the future).
ValidateUnknownMigrations: false,
}

m := gormigrate.New(sr.gormClient, gormMigrateOptions, []*gormigrate.Migration{
{
ID: "20201107210306", // v0.3.13 (pre-influxdb schema). 9fac3c6308dc6cb6cd5bbc43a68cd93e8fb20b87
Migrate: func(tx *gorm.DB) error {
Expand Down Expand Up @@ -264,7 +272,7 @@ func (sr *scrutinyRepository) Migrate(ctx context.Context) error {
})

if err := m.Migrate(); err != nil {
sr.logger.Errorf("Database migration failed with error: %w", err)
sr.logger.Errorf("Database migration failed with error. \n Please open a github issue at https://github.com/AnalogJ/scrutiny and attach a copy of your scrutiny.db file. \n %w", err)
return err
}
sr.logger.Infoln("Database migration completed successfully")
Expand Down

0 comments on commit 97add04

Please sign in to comment.