From 2f29d7c9ec1e83537d0d3f73ee311e6c6a7b9fe3 Mon Sep 17 00:00:00 2001 From: shiyuhang <1136742008@qq.com> Date: Thu, 28 Sep 2023 12:21:45 +0800 Subject: [PATCH 1/2] add new field in user table --- db.go | 10 +++++++++- main_test.go | 2 +- models.go | 1 + tidbcloud.yml | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/db.go b/db.go index 359d718..7b4eea3 100644 --- a/db.go +++ b/db.go @@ -116,6 +116,15 @@ func RunMigrations() { } return nil }, + }, { + // alter table + ID: "202307111200", + Migrate: func(db *gorm.DB) error { + if err := db.Exec("ALTER TABLE `users` ADD `new_wrong_field` varchar(255) NOT NULL").Error; err != nil { + return err + } + return nil + }, }}) if err = m.Migrate(); err != nil { @@ -123,5 +132,4 @@ func RunMigrations() { os.Exit(1) } log.Println("Migration did run successfully") - } diff --git a/main_test.go b/main_test.go index bb498d3..edbb822 100644 --- a/main_test.go +++ b/main_test.go @@ -9,7 +9,7 @@ import ( // TEST_DRIVERS: sqlite, mysql, postgres, sqlserver, tidb func TestGORM(t *testing.T) { - user := User{Name: "jinzhu"} + user := User{Name: "jinzhu", NewField: "new_field"} DB.Create(&user) diff --git a/models.go b/models.go index 692a684..798c4e4 100644 --- a/models.go +++ b/models.go @@ -27,6 +27,7 @@ type User struct { Languages []Language `gorm:"many2many:UserSpeak"` Friends []*User `gorm:"many2many:user_friends"` Active bool + NewField string } type Account struct { diff --git a/tidbcloud.yml b/tidbcloud.yml index f9338cc..00852ef 100644 --- a/tidbcloud.yml +++ b/tidbcloud.yml @@ -1,4 +1,4 @@ github: branch: allowList: - - "ci_example" + - "column_typo_example" From 482c9dd5a0441d07f05c7918c497a51090532bfc Mon Sep 17 00:00:00 2001 From: shiyuhang <1136742008@qq.com> Date: Thu, 28 Sep 2023 13:09:13 +0800 Subject: [PATCH 2/2] fix bug --- db.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db.go b/db.go index 7b4eea3..77a087e 100644 --- a/db.go +++ b/db.go @@ -120,7 +120,7 @@ func RunMigrations() { // alter table ID: "202307111200", Migrate: func(db *gorm.DB) error { - if err := db.Exec("ALTER TABLE `users` ADD `new_wrong_field` varchar(255) NOT NULL").Error; err != nil { + if err := db.Exec("ALTER TABLE `users` ADD `new_field` varchar(255) NOT NULL").Error; err != nil { return err } return nil