Skip to content

Commit

Permalink
fix(bug): generated ALTER TABLE codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Atlas Lee committed May 16, 2024
1 parent a843163 commit 7741797
Show file tree
Hide file tree
Showing 50 changed files with 155 additions and 154 deletions.
9 changes: 5 additions & 4 deletions codegen/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ func (g *Generator) createTableStmt() func(string, *templates.Model) string {
}
}

func (g *Generator) alterTableStmt() func(*templates.Model) string {
return func(model *templates.Model) string {
func (g *Generator) alterTableStmt() func(string, *templates.Model) string {
return func(n string, model *templates.Model) string {
buf := strpool.AcquireString()
defer strpool.ReleaseString(buf)
buf.WriteString("ALTER TABLE " + g.QuoteIdentifier(model.TableName) + " ")
buf.WriteString(g.Quote("ALTER TABLE "))
buf.WriteString("+ " + n + ".TableName() +" + g.QuoteStringBegin() + " (")
for i, f := range model.Fields {
if i > 0 {
buf.WriteByte(',')
Expand All @@ -116,7 +117,7 @@ func (g *Generator) alterTableStmt() func(*templates.Model) string {
// if model.PK != nil {
// buf.WriteString(",MODIFY PRIMARY KEY (" + model.PK.Field.ColumnName + ")")
// }
buf.WriteByte(';')
buf.WriteString(");" + g.QuoteStringEnd())
return buf.String()
}
}
Expand Down
4 changes: 2 additions & 2 deletions codegen/templates/model.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
func (v {{ $structName }}) CreateTableStmt() string {
return {{ createTable "v" . }}
}
func ({{ $structName }}) AlterTableStmt() string {
return {{ quote (alterTable .) }}
func (v {{ $structName }}) AlterTableStmt() string {
return {{ alterTable "v" . }}
}
{{ if not $hasCustomTabler -}}
func ({{ $structName }}) TableName() string {
Expand Down
4 changes: 2 additions & 2 deletions examples/testcase/schema/custom-declare/generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
func (v A) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (name VARCHAR(255) NOT NULL);"
}
func (A) AlterTableStmt() string {
return "ALTER TABLE a MODIFY name VARCHAR(255) NOT NULL;"
func (v A) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY name VARCHAR(255) NOT NULL);"
}
func (A) InsertVarQuery() string {
return "(?)"
Expand Down
4 changes: 2 additions & 2 deletions examples/testcase/schema/custom-declare/generated.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
func (v A) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (name VARCHAR(255) NOT NULL);"
}
func (A) AlterTableStmt() string {
return "ALTER TABLE a MODIFY name VARCHAR(255) NOT NULL;"
func (v A) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY name VARCHAR(255) NOT NULL);"
}
func (A) InsertVarQuery() string {
return "(?)"
Expand Down
8 changes: 4 additions & 4 deletions examples/testcase/schema/dynamic-table-name/generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
func (v Model) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (name VARCHAR(255) NOT NULL);"
}
func (Model) AlterTableStmt() string {
return "ALTER TABLE model MODIFY name VARCHAR(255) NOT NULL;"
func (v Model) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY name VARCHAR(255) NOT NULL);"
}
func (Model) InsertVarQuery() string {
return "(?)"
Expand All @@ -32,8 +32,8 @@ func (v Model) GetName() sequel.ColumnValuer[string] {
func (v A) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (id BIGINT NOT NULL,name VARCHAR(255) NOT NULL,PRIMARY KEY (id));"
}
func (A) AlterTableStmt() string {
return "ALTER TABLE a MODIFY id BIGINT NOT NULL,MODIFY name VARCHAR(255) NOT NULL AFTER id;"
func (v A) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY id BIGINT NOT NULL,MODIFY name VARCHAR(255) NOT NULL AFTER id);"
}
func (A) InsertVarQuery() string {
return "(?,?)"
Expand Down
8 changes: 4 additions & 4 deletions examples/testcase/schema/dynamic-table-name/generated.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
func (v Model) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (name VARCHAR(255) NOT NULL);"
}
func (Model) AlterTableStmt() string {
return "ALTER TABLE model MODIFY name VARCHAR(255) NOT NULL;"
func (v Model) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY name VARCHAR(255) NOT NULL);"
}
func (Model) InsertVarQuery() string {
return "(?)"
Expand All @@ -32,8 +32,8 @@ func (v Model) GetName() sequel.ColumnValuer[string] {
func (v A) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (id BIGINT NOT NULL,name VARCHAR(255) NOT NULL,PRIMARY KEY (id));"
}
func (A) AlterTableStmt() string {
return "ALTER TABLE a MODIFY id BIGINT NOT NULL,MODIFY name VARCHAR(255) NOT NULL AFTER id;"
func (v A) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY id BIGINT NOT NULL,MODIFY name VARCHAR(255) NOT NULL AFTER id);"
}
func (A) InsertVarQuery() string {
return "(?,?)"
Expand Down
16 changes: 8 additions & 8 deletions examples/testcase/schema/generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
func (v A) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (id VARCHAR(255) NOT NULL,text VARCHAR(255) NOT NULL,created_at DATETIME NOT NULL);"
}
func (A) AlterTableStmt() string {
return "ALTER TABLE Apple MODIFY id VARCHAR(255) NOT NULL,MODIFY text VARCHAR(255) NOT NULL AFTER id,MODIFY created_at DATETIME NOT NULL AFTER text;"
func (v A) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY id VARCHAR(255) NOT NULL,MODIFY text VARCHAR(255) NOT NULL AFTER id,MODIFY created_at DATETIME NOT NULL AFTER text);"
}
func (A) TableName() string {
return "Apple"
Expand Down Expand Up @@ -46,8 +46,8 @@ func (v A) GetCreatedAt() sequel.ColumnValuer[time.Time] {
func (v B) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (id VARCHAR(255) NOT NULL,created_at DATETIME NOT NULL);"
}
func (B) AlterTableStmt() string {
return "ALTER TABLE b MODIFY id VARCHAR(255) NOT NULL,MODIFY created_at DATETIME NOT NULL AFTER id;"
func (v B) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY id VARCHAR(255) NOT NULL,MODIFY created_at DATETIME NOT NULL AFTER id);"
}
func (B) TableName() string {
return "b"
Expand Down Expand Up @@ -77,8 +77,8 @@ func (v B) GetCreatedAt() sequel.ColumnValuer[time.Time] {
func (v C) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (id BIGINT NOT NULL,PRIMARY KEY (id));"
}
func (C) AlterTableStmt() string {
return "ALTER TABLE c MODIFY id BIGINT NOT NULL;"
func (v C) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY id BIGINT NOT NULL);"
}
func (C) TableName() string {
return "c"
Expand Down Expand Up @@ -108,8 +108,8 @@ func (v C) GetID() sequel.ColumnValuer[int64] {
func (v D) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (id VARCHAR(255) NOT NULL,PRIMARY KEY (id));"
}
func (D) AlterTableStmt() string {
return "ALTER TABLE d MODIFY id VARCHAR(255) NOT NULL;"
func (v D) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY id VARCHAR(255) NOT NULL);"
}
func (D) TableName() string {
return "d"
Expand Down
16 changes: 8 additions & 8 deletions examples/testcase/schema/generated.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
func (v A) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (id VARCHAR(255) NOT NULL,text VARCHAR(255) NOT NULL,created_at DATETIME NOT NULL);"
}
func (A) AlterTableStmt() string {
return "ALTER TABLE Apple MODIFY id VARCHAR(255) NOT NULL,MODIFY text VARCHAR(255) NOT NULL AFTER id,MODIFY created_at DATETIME NOT NULL AFTER text;"
func (v A) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY id VARCHAR(255) NOT NULL,MODIFY text VARCHAR(255) NOT NULL AFTER id,MODIFY created_at DATETIME NOT NULL AFTER text);"
}
func (A) TableName() string {
return "Apple"
Expand Down Expand Up @@ -46,8 +46,8 @@ func (v A) GetCreatedAt() sequel.ColumnValuer[time.Time] {
func (v B) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (id VARCHAR(255) NOT NULL,created_at DATETIME NOT NULL);"
}
func (B) AlterTableStmt() string {
return "ALTER TABLE b MODIFY id VARCHAR(255) NOT NULL,MODIFY created_at DATETIME NOT NULL AFTER id;"
func (v B) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY id VARCHAR(255) NOT NULL,MODIFY created_at DATETIME NOT NULL AFTER id);"
}
func (B) TableName() string {
return "b"
Expand Down Expand Up @@ -77,8 +77,8 @@ func (v B) GetCreatedAt() sequel.ColumnValuer[time.Time] {
func (v C) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (id BIGINT NOT NULL,PRIMARY KEY (id));"
}
func (C) AlterTableStmt() string {
return "ALTER TABLE c MODIFY id BIGINT NOT NULL;"
func (v C) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY id BIGINT NOT NULL);"
}
func (C) TableName() string {
return "c"
Expand Down Expand Up @@ -108,8 +108,8 @@ func (v C) GetID() sequel.ColumnValuer[int64] {
func (v D) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (id VARCHAR(255) NOT NULL,PRIMARY KEY (id));"
}
func (D) AlterTableStmt() string {
return "ALTER TABLE d MODIFY id VARCHAR(255) NOT NULL;"
func (v D) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY id VARCHAR(255) NOT NULL);"
}
func (D) TableName() string {
return "d"
Expand Down
4 changes: 2 additions & 2 deletions examples/testcase/schema/nopk/generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
func (v Customer) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (name VARCHAR(255) NOT NULL,age TINYINT UNSIGNED NOT NULL,married TINYINT NOT NULL);"
}
func (Customer) AlterTableStmt() string {
return "ALTER TABLE customer MODIFY name VARCHAR(255) NOT NULL,MODIFY age TINYINT UNSIGNED NOT NULL AFTER name,MODIFY married TINYINT NOT NULL AFTER age;"
func (v Customer) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY name VARCHAR(255) NOT NULL,MODIFY age TINYINT UNSIGNED NOT NULL AFTER name,MODIFY married TINYINT NOT NULL AFTER age);"
}
func (Customer) TableName() string {
return "customer"
Expand Down
4 changes: 2 additions & 2 deletions examples/testcase/schema/nopk/generated.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
func (v Customer) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (name VARCHAR(255) NOT NULL,age TINYINT UNSIGNED NOT NULL,married TINYINT NOT NULL);"
}
func (Customer) AlterTableStmt() string {
return "ALTER TABLE customer MODIFY name VARCHAR(255) NOT NULL,MODIFY age TINYINT UNSIGNED NOT NULL AFTER name,MODIFY married TINYINT NOT NULL AFTER age;"
func (v Customer) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY name VARCHAR(255) NOT NULL,MODIFY age TINYINT UNSIGNED NOT NULL AFTER name,MODIFY married TINYINT NOT NULL AFTER age);"
}
func (Customer) TableName() string {
return "customer"
Expand Down
12 changes: 6 additions & 6 deletions examples/testcase/schema/table-name/generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
func (v CustomTableName1) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (text VARCHAR(255) NOT NULL);"
}
func (CustomTableName1) AlterTableStmt() string {
return "ALTER TABLE CustomTableName_1 MODIFY text VARCHAR(255) NOT NULL;"
func (v CustomTableName1) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY text VARCHAR(255) NOT NULL);"
}
func (CustomTableName1) TableName() string {
return "CustomTableName_1"
Expand All @@ -38,8 +38,8 @@ func (v CustomTableName1) GetText() sequel.ColumnValuer[string] {
func (v CustomTableName2) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (text VARCHAR(255) NOT NULL);"
}
func (CustomTableName2) AlterTableStmt() string {
return "ALTER TABLE table_2 MODIFY text VARCHAR(255) NOT NULL;"
func (v CustomTableName2) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY text VARCHAR(255) NOT NULL);"
}
func (CustomTableName2) TableName() string {
return "table_2"
Expand All @@ -66,8 +66,8 @@ func (v CustomTableName2) GetText() sequel.ColumnValuer[string] {
func (v CustomTableName3) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (text VARCHAR(255) NOT NULL);"
}
func (CustomTableName3) AlterTableStmt() string {
return "ALTER TABLE table_3 MODIFY text VARCHAR(255) NOT NULL;"
func (v CustomTableName3) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY text VARCHAR(255) NOT NULL);"
}
func (CustomTableName3) TableName() string {
return "table_3"
Expand Down
12 changes: 6 additions & 6 deletions examples/testcase/schema/table-name/generated.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
func (v CustomTableName1) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (text VARCHAR(255) NOT NULL);"
}
func (CustomTableName1) AlterTableStmt() string {
return "ALTER TABLE CustomTableName_1 MODIFY text VARCHAR(255) NOT NULL;"
func (v CustomTableName1) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY text VARCHAR(255) NOT NULL);"
}
func (CustomTableName1) TableName() string {
return "CustomTableName_1"
Expand All @@ -38,8 +38,8 @@ func (v CustomTableName1) GetText() sequel.ColumnValuer[string] {
func (v CustomTableName2) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (text VARCHAR(255) NOT NULL);"
}
func (CustomTableName2) AlterTableStmt() string {
return "ALTER TABLE table_2 MODIFY text VARCHAR(255) NOT NULL;"
func (v CustomTableName2) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY text VARCHAR(255) NOT NULL);"
}
func (CustomTableName2) TableName() string {
return "table_2"
Expand All @@ -66,8 +66,8 @@ func (v CustomTableName2) GetText() sequel.ColumnValuer[string] {
func (v CustomTableName3) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (text VARCHAR(255) NOT NULL);"
}
func (CustomTableName3) AlterTableStmt() string {
return "ALTER TABLE table_3 MODIFY text VARCHAR(255) NOT NULL;"
func (v CustomTableName3) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY text VARCHAR(255) NOT NULL);"
}
func (CustomTableName3) TableName() string {
return "table_3"
Expand Down
12 changes: 6 additions & 6 deletions examples/testcase/struct-field/alias/generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
func (v AliasStruct) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (b FLOAT NOT NULL,Id BIGINT NOT NULL,header VARCHAR(255) NOT NULL,raw BLOB,text VARCHAR(255) NOT NULL,null_str VARCHAR(255) NOT NULL,created DATETIME NOT NULL,updated DATETIME NOT NULL,PRIMARY KEY (Id));"
}
func (AliasStruct) AlterTableStmt() string {
return "ALTER TABLE alias_struct MODIFY b FLOAT NOT NULL,MODIFY Id BIGINT NOT NULL AFTER b,MODIFY header VARCHAR(255) NOT NULL AFTER Id,MODIFY raw BLOB AFTER header,MODIFY text VARCHAR(255) NOT NULL AFTER raw,MODIFY null_str VARCHAR(255) NOT NULL AFTER text,MODIFY created DATETIME NOT NULL AFTER null_str,MODIFY updated DATETIME NOT NULL AFTER created;"
func (v AliasStruct) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY b FLOAT NOT NULL,MODIFY Id BIGINT NOT NULL AFTER b,MODIFY header VARCHAR(255) NOT NULL AFTER Id,MODIFY raw BLOB AFTER header,MODIFY text VARCHAR(255) NOT NULL AFTER raw,MODIFY null_str VARCHAR(255) NOT NULL AFTER text,MODIFY created DATETIME NOT NULL AFTER null_str,MODIFY updated DATETIME NOT NULL AFTER created);"
}
func (AliasStruct) TableName() string {
return "alias_struct"
Expand Down Expand Up @@ -70,8 +70,8 @@ func (v AliasStruct) GetUpdated() sequel.ColumnValuer[time.Time] {
func (v B) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (name VARCHAR(255) NOT NULL);"
}
func (B) AlterTableStmt() string {
return "ALTER TABLE b MODIFY name VARCHAR(255) NOT NULL;"
func (v B) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY name VARCHAR(255) NOT NULL);"
}
func (B) TableName() string {
return "b"
Expand All @@ -98,8 +98,8 @@ func (v B) GetName() sequel.ColumnValuer[string] {
func (v C) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (id BIGINT NOT NULL);"
}
func (C) AlterTableStmt() string {
return "ALTER TABLE c MODIFY id BIGINT NOT NULL;"
func (v C) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY id BIGINT NOT NULL);"
}
func (C) TableName() string {
return "c"
Expand Down
12 changes: 6 additions & 6 deletions examples/testcase/struct-field/alias/generated.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
func (v AliasStruct) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (b FLOAT NOT NULL,Id BIGINT NOT NULL,header VARCHAR(255) NOT NULL,raw BLOB,text VARCHAR(255) NOT NULL,null_str VARCHAR(255) NOT NULL,created DATETIME NOT NULL,updated DATETIME NOT NULL,PRIMARY KEY (Id));"
}
func (AliasStruct) AlterTableStmt() string {
return "ALTER TABLE alias_struct MODIFY b FLOAT NOT NULL,MODIFY Id BIGINT NOT NULL AFTER b,MODIFY header VARCHAR(255) NOT NULL AFTER Id,MODIFY raw BLOB AFTER header,MODIFY text VARCHAR(255) NOT NULL AFTER raw,MODIFY null_str VARCHAR(255) NOT NULL AFTER text,MODIFY created DATETIME NOT NULL AFTER null_str,MODIFY updated DATETIME NOT NULL AFTER created;"
func (v AliasStruct) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY b FLOAT NOT NULL,MODIFY Id BIGINT NOT NULL AFTER b,MODIFY header VARCHAR(255) NOT NULL AFTER Id,MODIFY raw BLOB AFTER header,MODIFY text VARCHAR(255) NOT NULL AFTER raw,MODIFY null_str VARCHAR(255) NOT NULL AFTER text,MODIFY created DATETIME NOT NULL AFTER null_str,MODIFY updated DATETIME NOT NULL AFTER created);"
}
func (AliasStruct) TableName() string {
return "alias_struct"
Expand Down Expand Up @@ -70,8 +70,8 @@ func (v AliasStruct) GetUpdated() sequel.ColumnValuer[time.Time] {
func (v B) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (name VARCHAR(255) NOT NULL);"
}
func (B) AlterTableStmt() string {
return "ALTER TABLE b MODIFY name VARCHAR(255) NOT NULL;"
func (v B) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY name VARCHAR(255) NOT NULL);"
}
func (B) TableName() string {
return "b"
Expand All @@ -98,8 +98,8 @@ func (v B) GetName() sequel.ColumnValuer[string] {
func (v C) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (id BIGINT NOT NULL);"
}
func (C) AlterTableStmt() string {
return "ALTER TABLE c MODIFY id BIGINT NOT NULL;"
func (v C) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY id BIGINT NOT NULL);"
}
func (C) TableName() string {
return "c"
Expand Down
4 changes: 2 additions & 2 deletions examples/testcase/struct-field/array/generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
func (v Array) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,bool_list JSON NOT NULL,str_list JSON NOT NULL,custom_str_list JSON NOT NULL,int_list JSON NOT NULL,int_8_list JSON NOT NULL,int_16_list JSON NOT NULL,int_32_list JSON NOT NULL,int_64_list JSON NOT NULL,uint_list JSON NOT NULL,uint_8_list JSON NOT NULL,uint_16_list JSON NOT NULL,uint_32_list JSON NOT NULL,uint_64_list JSON NOT NULL,f_32_list JSON NOT NULL,f_64_list JSON NOT NULL,PRIMARY KEY (id));"
}
func (Array) AlterTableStmt() string {
return "ALTER TABLE array MODIFY id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,MODIFY bool_list JSON NOT NULL AFTER id,MODIFY str_list JSON NOT NULL AFTER bool_list,MODIFY custom_str_list JSON NOT NULL AFTER str_list,MODIFY int_list JSON NOT NULL AFTER custom_str_list,MODIFY int_8_list JSON NOT NULL AFTER int_list,MODIFY int_16_list JSON NOT NULL AFTER int_8_list,MODIFY int_32_list JSON NOT NULL AFTER int_16_list,MODIFY int_64_list JSON NOT NULL AFTER int_32_list,MODIFY uint_list JSON NOT NULL AFTER int_64_list,MODIFY uint_8_list JSON NOT NULL AFTER uint_list,MODIFY uint_16_list JSON NOT NULL AFTER uint_8_list,MODIFY uint_32_list JSON NOT NULL AFTER uint_16_list,MODIFY uint_64_list JSON NOT NULL AFTER uint_32_list,MODIFY f_32_list JSON NOT NULL AFTER uint_64_list,MODIFY f_64_list JSON NOT NULL AFTER f_32_list;"
func (v Array) AlterTableStmt() string {
return "ALTER TABLE " + v.TableName() + " (MODIFY id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,MODIFY bool_list JSON NOT NULL AFTER id,MODIFY str_list JSON NOT NULL AFTER bool_list,MODIFY custom_str_list JSON NOT NULL AFTER str_list,MODIFY int_list JSON NOT NULL AFTER custom_str_list,MODIFY int_8_list JSON NOT NULL AFTER int_list,MODIFY int_16_list JSON NOT NULL AFTER int_8_list,MODIFY int_32_list JSON NOT NULL AFTER int_16_list,MODIFY int_64_list JSON NOT NULL AFTER int_32_list,MODIFY uint_list JSON NOT NULL AFTER int_64_list,MODIFY uint_8_list JSON NOT NULL AFTER uint_list,MODIFY uint_16_list JSON NOT NULL AFTER uint_8_list,MODIFY uint_32_list JSON NOT NULL AFTER uint_16_list,MODIFY uint_64_list JSON NOT NULL AFTER uint_32_list,MODIFY f_32_list JSON NOT NULL AFTER uint_64_list,MODIFY f_64_list JSON NOT NULL AFTER f_32_list);"
}
func (Array) TableName() string {
return "array"
Expand Down
Loading

0 comments on commit 7741797

Please sign in to comment.