Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDL: add column typo example #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,20 @@ func RunMigrations() {
}
return nil
},
}, {
// alter table
ID: "202307111200",
Migrate: func(db *gorm.DB) error {
if err := db.Exec("ALTER TABLE `users` ADD `new_field` varchar(255) NOT NULL").Error; err != nil {
return err
}
return nil
},
}})

if err = m.Migrate(); err != nil {
log.Fatalf("Migration failed: %v", err)
os.Exit(1)
}
log.Println("Migration did run successfully")

}
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tidbcloud.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github:
branch:
allowList:
- "ci_example"
- "column_typo_example"
Loading