-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
made sure that all timestamp columns are defaulted and update as expe…
…cted
- Loading branch information
1 parent
a91bbca
commit 221f79b
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters