Skip to content

Commit

Permalink
fix: migration errors when using an empty mysql database
Browse files Browse the repository at this point in the history
The migration was removed in 5af692a because it failed when using SQlite
  • Loading branch information
libvoid committed Jul 26, 2023
1 parent 59d0356 commit 6a775ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
7 changes: 3 additions & 4 deletions pkg/bastion/dbinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,9 @@ func DBInit(db *gorm.DB) error {
}, {
ID: "10",
Migrate: func(tx *gorm.DB) error {
// This migration doesn't work anymore after upgrading to latest version of Gorm
// if err := tx.Migrator().DropIndex(&dbmodels.SSHKey{}, "uix_keys_name"); err != nil {
// return err
// }
if err := tx.Migrator().DropIndex(&dbmodels.SSHKey{}, "uix_keys_name"); err != nil {
log.Printf("%v\n[WORKAROUND] recreates uix_keys_name: ", err)
}
return tx.Migrator().CreateIndex(&dbmodels.SSHKey{}, "uix_keys_name")
},
Rollback: func(tx *gorm.DB) error {
Expand Down
3 changes: 2 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func server(c *serverConfig) (err error) {
// configure db logging

db, _ := dbConnect(c, &gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
DisableForeignKeyConstraintWhenMigrating: true,
Logger: logger.Default.LogMode(logger.Silent),
})
sqlDB, err := db.DB()

Expand Down

0 comments on commit 6a775ce

Please sign in to comment.