Skip to content

Commit

Permalink
storse: add index creation to migration code
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Nov 10, 2023
1 parent 6ea8a05 commit 83bbfe1
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions stores/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -1122,19 +1122,32 @@ func performMigration00024_slabIndices(txn *gorm.DB, logger *zap.SugaredLogger)

func performMigration00025_contractState(txn *gorm.DB, logger *zap.SugaredLogger) error {
logger.Info("performing migration 00025_contractState")
// create column
if !txn.Migrator().HasColumn(&dbContract{}, "State") {
if err := txn.Migrator().AddColumn(&dbContract{}, "State"); err != nil {
return err
}
if err := txn.Model(&dbContract{}).Where("TRUE").Update("State", contractStateActive).Error; err != nil {
return err
}
}
if !txn.Migrator().HasColumn(&dbArchivedContract{}, "State") {
if err := txn.Migrator().AddColumn(&dbArchivedContract{}, "State"); err != nil {
return err
}
if err := txn.Model(&dbArchivedContract{}).Where("TRUE").Update("State", contractStateComplete).Error; err != nil {
}
// update column
if err := txn.Model(&dbContract{}).Where("TRUE").Update("State", contractStateActive).Error; err != nil {
return err
}
if err := txn.Model(&dbArchivedContract{}).Where("TRUE").Update("State", contractStateComplete).Error; err != nil {
return err
}
// create index
if !txn.Migrator().HasIndex(&dbContract{}, "State") {
if err := txn.Migrator().CreateIndex(&dbContract{}, "State"); err != nil {
return err
}
}
if !txn.Migrator().HasIndex(&dbArchivedContract{}, "State") {
if err := txn.Migrator().CreateIndex(&dbArchivedContract{}, "State"); err != nil {
return err
}
}
Expand Down

0 comments on commit 83bbfe1

Please sign in to comment.