fix: add judge result of auto_migrate (#5306)

Co-authored-by: fredhan <fredhan@futunn.com>
This commit is contained in:
Heliner 2022-04-30 09:50:53 +08:00 committed by GitHub
parent bd7e42ec65
commit d3488ae6bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 3 deletions

View File

@ -639,9 +639,19 @@ func TestMigrateSerialColumn(t *testing.T) {
// https://github.com/go-gorm/gorm/issues/5300
func TestMigrateWithSpecialName(t *testing.T) {
DB.AutoMigrate(&Coupon{})
DB.Table("coupon_product_1").AutoMigrate(&CouponProduct{})
DB.Table("coupon_product_2").AutoMigrate(&CouponProduct{})
var err error
err = DB.AutoMigrate(&Coupon{})
if err != nil {
t.Fatalf("AutoMigrate err:%v", err)
}
err = DB.Table("coupon_product_1").AutoMigrate(&CouponProduct{})
if err != nil {
t.Fatalf("AutoMigrate err:%v", err)
}
err = DB.Table("coupon_product_2").AutoMigrate(&CouponProduct{})
if err != nil {
t.Fatalf("AutoMigrate err:%v", err)
}
AssertEqual(t, true, DB.Migrator().HasTable("coupons"))
AssertEqual(t, true, DB.Migrator().HasTable("coupon_product_1"))