Skip to content

Commit

Permalink
made sure that all timestamp columns are defaulted and update as expe…
Browse files Browse the repository at this point in the history
…cted
  • Loading branch information
CommanderStorm committed Mar 17, 2024
1 parent a91bbca commit 221f79b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions server/backend/migration/20240319000000.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package migration

import (
"fmt"
"github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
)

// migrate20240319000000
// made sure that all timestamp columns are defaulted and update as expected
func migrate20240319000000() *gormigrate.Migration {
return &gormigrate.Migration{
ID: "20240319000000",
Migrate: func(tx *gorm.DB) error {
tables := []string{"cafeteria_rating", "canteen_head_count", "dish_rating"}
for _, t := range tables {
tx.Exec(fmt.Sprintf("alter table `%s` modify timestamp timestamp default current_timestamp() not null on update current_timestamp()", t))
}
return nil
},
Rollback: func(tx *gorm.DB) error {
tables := []string{"cafeteria_rating", "canteen_head_count", "dish_rating"}
for _, t := range tables {
tx.Exec(fmt.Sprintf("alter table `%s` modify timestamp timestamp not null", t))
}
return nil
},
}
}
1 change: 1 addition & 0 deletions server/backend/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func manualMigrate(db *gorm.DB) error {
migrate20240312000000(),
migrate20240316000000(),
migrate20240317000000(),
migrate20240319000000(),
}
return gormigrate.New(db, gormigrateOptions, migrations).Migrate()
}
Expand Down

0 comments on commit 221f79b

Please sign in to comment.