I have a table user
that is really big, which causes AutoMigrate
to hangs when I try to use it to create new column or modify the column, which takes down my site for a bit.
One solution I am trying to implement is using a "Zero-Downtime Migration" method, which goes as follow:
user_temp
table.user_temp
table from existing user
table.user_temp
table.user
table to user_old
table.user_temp
table to user.user_old
table.However, since the way I migrate user
table is by updating the User
struct, and then run
db.AutoMigrate(&User{}).Error
I am not sure how to dynamically create the UserTemp
struct from the newly updated User
struct in Golang.
I am hoping to either:
a. Dynamically create UserTemp
struct that is identical to the newly updated User
struct, so i can run db.AutoMigrate(&UserTemp{})
b. use the AutoMigrate
func with the newly updated User
struct, but only on the user_temp
table, and not the user
table.
Thank you in advance.
ok, all I had to do was db.Table("user_temp").AutoMigrate(&User{})