diff --git a/cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go b/cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go index 71818fb82dc..39e1eb54799 100644 --- a/cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go +++ b/cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go @@ -12,6 +12,7 @@ import ( "testing" "github.com/gogf/gf/cmd/gf/v2/internal/cmd/gendao" + "github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/test/gtest" "github.com/gogf/gf/v2/text/gstr" @@ -209,3 +210,83 @@ func Test_Gen_Dao_TypeMapping(t *testing.T) { } }) } + +func execSqlFile(db gdb.DB, filePath string, args ...any) error { + sqlContent := fmt.Sprintf( + gfile.GetContents(filePath), + args..., + ) + array := gstr.SplitAndTrim(sqlContent, ";") + for _, v := range array { + if _, err := db.Exec(ctx, v); err != nil { + return err + } + } + return nil +} + +func Test_Gen_Dao_Issue2572(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + var ( + err error + db = testDB + table1 = "user1" + table2 = "user2" + issueDirPath = gtest.DataPath(`issue`, `2572`) + ) + t.AssertNil(execSqlFile(db, gtest.DataPath(`issue`, `2572`, `sql1.sql`))) + t.AssertNil(execSqlFile(db, gtest.DataPath(`issue`, `2572`, `sql2.sql`))) + defer dropTableWithDb(db, table1) + defer dropTableWithDb(db, table2) + + var ( + path = gfile.Temp(guid.S()) + group = "test" + in = gendao.CGenDaoInput{ + Path: path, + Link: link, + Tables: "", + TablesEx: "", + Group: group, + Prefix: "", + RemovePrefix: "", + JsonCase: "SnakeScreaming", + ImportPrefix: "", + DaoPath: "", + DoPath: "", + EntityPath: "", + TplDaoIndexPath: "", + TplDaoInternalPath: "", + TplDaoDoPath: "", + TplDaoEntityPath: "", + StdTime: false, + WithTime: false, + GJsonSupport: false, + OverwriteDao: false, + DescriptionTag: false, + NoJsonTag: false, + NoModelComment: false, + Clear: false, + TypeMapping: nil, + } + ) + err = gutil.FillStructWithDefault(&in) + t.AssertNil(err) + + err = gfile.Copy(issueDirPath, path) + t.AssertNil(err) + + defer gfile.Remove(path) + + pwd := gfile.Pwd() + err = gfile.Chdir(path) + t.AssertNil(err) + + defer gfile.Chdir(pwd) + + _, err = gendao.CGenDao{}.Dao(ctx, in) + t.AssertNil(err) + + fmt.Println(path) + }) +} diff --git a/cmd/gf/internal/cmd/gendao/gendao.go b/cmd/gf/internal/cmd/gendao/gendao.go index 765c63a441b..51e97ab9bc7 100644 --- a/cmd/gf/internal/cmd/gendao/gendao.go +++ b/cmd/gf/internal/cmd/gendao/gendao.go @@ -201,7 +201,8 @@ type ( NoModelComment bool `name:"noModelComment" short:"m" brief:"{CGenDaoBriefNoModelComment}" orphan:"true"` Clear bool `name:"clear" short:"a" brief:"{CGenDaoBriefClear}" orphan:"true"` - TypeMapping map[DBFieldTypeName]CustomAttributeType `name:"typeMapping" short:"y" brief:"{CGenDaoBriefTypeMapping}" orphan:"true"` + TypeMapping map[DBFieldTypeName]CustomAttributeType `name:"typeMapping" short:"y" brief:"{CGenDaoBriefTypeMapping}" orphan:"true"` + generatedFilePaths *CGenDaoInternalGeneratedFilePaths } CGenDaoOutput struct{} @@ -212,6 +213,13 @@ type ( NewTableNames []string } + CGenDaoInternalGeneratedFilePaths struct { + DaoFilePaths []string + DaoInternalFilePaths []string + DoFilePaths []string + EntityFilePaths []string + } + DBFieldTypeName = string CustomAttributeType struct { Type string `brief:"custom attribute type name"` @@ -220,6 +228,12 @@ type ( ) func (c CGenDao) Dao(ctx context.Context, in CGenDaoInput) (out *CGenDaoOutput, err error) { + in.generatedFilePaths = &CGenDaoInternalGeneratedFilePaths{ + DaoFilePaths: make([]string, 0), + DaoInternalFilePaths: make([]string, 0), + DoFilePaths: make([]string, 0), + EntityFilePaths: make([]string, 0), + } if g.Cfg().Available(ctx) { v := g.Cfg().MustGet(ctx, CGenDaoConfig) if v.IsSlice() { @@ -333,6 +347,10 @@ func doGenDaoForArray(ctx context.Context, index int, in CGenDaoInput) { TableNames: tableNames, NewTableNames: newTableNames, }) + + if in.Clear { + doClear(ctx, in) + } } func getImportPartContent(ctx context.Context, source string, isDo bool, appendImports []string) string { diff --git a/cmd/gf/internal/cmd/gendao/gendao_clear.go b/cmd/gf/internal/cmd/gendao/gendao_clear.go index 0a420dab912..bdaffd06d5c 100644 --- a/cmd/gf/internal/cmd/gendao/gendao_clear.go +++ b/cmd/gf/internal/cmd/gendao/gendao_clear.go @@ -10,19 +10,24 @@ import ( "context" "github.com/gogf/gf/v2/os/gfile" + "github.com/gogf/gf/v2/text/gstr" "github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog" - "github.com/gogf/gf/cmd/gf/v2/internal/utility/utils" ) -func doClear(ctx context.Context, dirPath string, force bool) { - files, err := gfile.ScanDirFile(dirPath, "*.go", true) +func doClear(ctx context.Context, in CGenDaoInput) { + filePaths, err := gfile.ScanDirFile(in.Path, "*.go", true) if err != nil { mlog.Fatal(err) } - for _, file := range files { - if force || utils.IsFileDoNotEdit(file) { - if err = gfile.Remove(file); err != nil { + var allGeneratedFilePaths = make([]string, 0) + allGeneratedFilePaths = append(allGeneratedFilePaths, in.generatedFilePaths.DaoFilePaths...) + allGeneratedFilePaths = append(allGeneratedFilePaths, in.generatedFilePaths.DaoInternalFilePaths...) + allGeneratedFilePaths = append(allGeneratedFilePaths, in.generatedFilePaths.EntityFilePaths...) + allGeneratedFilePaths = append(allGeneratedFilePaths, in.generatedFilePaths.DoFilePaths...) + for _, filePath := range filePaths { + if !gstr.InArray(allGeneratedFilePaths, filePath) { + if err = gfile.Remove(filePath); err != nil { mlog.Print(err) } } diff --git a/cmd/gf/internal/cmd/gendao/gendao_dao.go b/cmd/gf/internal/cmd/gendao/gendao_dao.go index 0b572405e0c..73fe05f8b18 100644 --- a/cmd/gf/internal/cmd/gendao/gendao_dao.go +++ b/cmd/gf/internal/cmd/gendao/gendao_dao.go @@ -30,9 +30,6 @@ func generateDao(ctx context.Context, in CGenDaoInternalInput) { dirPathDao = gfile.Join(in.Path, in.DaoPath) dirPathDaoInternal = gfile.Join(dirPathDao, "internal") ) - if in.Clear { - doClear(ctx, dirPathDao, true) - } for i := 0; i < len(in.TableNames); i++ { generateDaoSingle(ctx, generateDaoSingleInput{ CGenDaoInternalInput: in, @@ -118,6 +115,10 @@ func generateDaoIndex(in generateDaoIndexInput) { tplVarTableNameCamelLowerCase: in.TableNameCamelLowerCase, }) indexContent = replaceDefaultVar(in.CGenDaoInternalInput, indexContent) + in.generatedFilePaths.DaoFilePaths = append( + in.generatedFilePaths.DaoFilePaths, + path, + ) if err := gfile.PutContents(path, strings.TrimSpace(indexContent)); err != nil { mlog.Fatalf("writing content to '%s' failed: %v", path, err) } else { @@ -151,6 +152,10 @@ func generateDaoInternal(in generateDaoInternalInput) { tplVarColumnNames: gstr.Trim(generateColumnNamesForDao(in.FieldMap, removeFieldPrefixArray)), }) modelContent = replaceDefaultVar(in.CGenDaoInternalInput, modelContent) + in.generatedFilePaths.DaoInternalFilePaths = append( + in.generatedFilePaths.DaoInternalFilePaths, + path, + ) if err := gfile.PutContents(path, strings.TrimSpace(modelContent)); err != nil { mlog.Fatalf("writing content to '%s' failed: %v", path, err) } else { diff --git a/cmd/gf/internal/cmd/gendao/gendao_do.go b/cmd/gf/internal/cmd/gendao/gendao_do.go index 85828d4d48f..d52c28e7e9e 100644 --- a/cmd/gf/internal/cmd/gendao/gendao_do.go +++ b/cmd/gf/internal/cmd/gendao/gendao_do.go @@ -24,9 +24,6 @@ import ( func generateDo(ctx context.Context, in CGenDaoInternalInput) { var dirPathDo = filepath.FromSlash(gfile.Join(in.Path, in.DoPath)) - if in.Clear { - doClear(ctx, dirPathDo, false) - } in.NoJsonTag = true in.DescriptionTag = false in.NoModelComment = false @@ -66,6 +63,10 @@ func generateDo(ctx context.Context, in CGenDaoInternalInput) { gstr.CaseCamel(newTableName), structDefinition, ) + in.generatedFilePaths.DoFilePaths = append( + in.generatedFilePaths.DoFilePaths, + doFilePath, + ) err = gfile.PutContents(doFilePath, strings.TrimSpace(modelContent)) if err != nil { mlog.Fatalf(`writing content to "%s" failed: %v`, doFilePath, err) diff --git a/cmd/gf/internal/cmd/gendao/gendao_entity.go b/cmd/gf/internal/cmd/gendao/gendao_entity.go index 00e9239e62e..e21129efb36 100644 --- a/cmd/gf/internal/cmd/gendao/gendao_entity.go +++ b/cmd/gf/internal/cmd/gendao/gendao_entity.go @@ -22,9 +22,6 @@ import ( func generateEntity(ctx context.Context, in CGenDaoInternalInput) { var dirPathEntity = gfile.Join(in.Path, in.EntityPath) - if in.Clear { - doClear(ctx, dirPathEntity, false) - } // Model content. for i, tableName := range in.TableNames { fieldMap, err := in.DB.TableFields(ctx, tableName) @@ -51,7 +48,10 @@ func generateEntity(ctx context.Context, in CGenDaoInternalInput) { appendImports, ) ) - + in.generatedFilePaths.EntityFilePaths = append( + in.generatedFilePaths.EntityFilePaths, + entityFilePath, + ) err = gfile.PutContents(entityFilePath, strings.TrimSpace(entityContent)) if err != nil { mlog.Fatalf("writing content to '%s' failed: %v", entityFilePath, err) diff --git a/cmd/gf/internal/cmd/testdata/issue/2572/config.yaml b/cmd/gf/internal/cmd/testdata/issue/2572/config.yaml new file mode 100644 index 00000000000..82e437f7899 --- /dev/null +++ b/cmd/gf/internal/cmd/testdata/issue/2572/config.yaml @@ -0,0 +1,20 @@ +gfcli: + gen: + dao: + - link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test" + tables: "user1" + descriptionTag: true + noModelComment: true + group: "sys" + clear: true + overwriteDao: true + - link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test" + tables: "user2" + descriptionTag: true + noModelComment: true + group: "book" + clear: true + overwriteDao: true + + + diff --git a/cmd/gf/internal/cmd/testdata/issue/2572/dao/internal/user_3.go b/cmd/gf/internal/cmd/testdata/issue/2572/dao/internal/user_3.go new file mode 100644 index 00000000000..db59440164d --- /dev/null +++ b/cmd/gf/internal/cmd/testdata/issue/2572/dao/internal/user_3.go @@ -0,0 +1,85 @@ +// ========================================================================== +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ========================================================================== + +package internal + +import ( + "context" + + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" +) + +// User3Dao is the data access object for table user3. +type User3Dao struct { + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of current DAO. + columns User3Columns // columns contains all the column names of Table for convenient usage. +} + +// User3Columns defines and stores column names for table user3. +type User3Columns struct { + Id string // User ID + Passport string // User Passport + Password string // User Password + Nickname string // User Nickname + Score string // Total score amount. + CreateAt string // Created Time + UpdateAt string // Updated Time +} + +// user3Columns holds the columns for table user3. +var user3Columns = User3Columns{ + Id: "id", + Passport: "passport", + Password: "password", + Nickname: "nickname", + Score: "score", + CreateAt: "create_at", + UpdateAt: "update_at", +} + +// NewUser3Dao creates and returns a new DAO object for table data access. +func NewUser3Dao() *User3Dao { + return &User3Dao{ + group: "sys", + table: "user3", + columns: user3Columns, + } +} + +// DB retrieves and returns the underlying raw database management object of current DAO. +func (dao *User3Dao) DB() gdb.DB { + return g.DB(dao.group) +} + +// Table returns the table name of current dao. +func (dao *User3Dao) Table() string { + return dao.table +} + +// Columns returns all column names of current dao. +func (dao *User3Dao) Columns() User3Columns { + return dao.columns +} + +// Group returns the configuration group name of database of current dao. +func (dao *User3Dao) Group() string { + return dao.group +} + +// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +func (dao *User3Dao) Ctx(ctx context.Context) *gdb.Model { + return dao.DB().Model(dao.table).Safe().Ctx(ctx) +} + +// Transaction wraps the transaction logic using function f. +// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It commits the transaction and returns nil if function f returns nil. +// +// Note that, you should not Commit or Rollback the transaction in function f +// as it is automatically handled by this function. +func (dao *User3Dao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { + return dao.Ctx(ctx).Transaction(ctx, f) +} diff --git a/cmd/gf/internal/cmd/testdata/issue/2572/dao/internal/user_4.go b/cmd/gf/internal/cmd/testdata/issue/2572/dao/internal/user_4.go new file mode 100644 index 00000000000..0488034d842 --- /dev/null +++ b/cmd/gf/internal/cmd/testdata/issue/2572/dao/internal/user_4.go @@ -0,0 +1,85 @@ +// ========================================================================== +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ========================================================================== + +package internal + +import ( + "context" + + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" +) + +// User4Dao is the data access object for table user4. +type User4Dao struct { + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of current DAO. + columns User4Columns // columns contains all the column names of Table for convenient usage. +} + +// User4Columns defines and stores column names for table user4. +type User4Columns struct { + Id string // User ID + Passport string // User Passport + Password string // User Password + Nickname string // User Nickname + Score string // Total score amount. + CreateAt string // Created Time + UpdateAt string // Updated Time +} + +// user4Columns holds the columns for table user4. +var user4Columns = User4Columns{ + Id: "id", + Passport: "passport", + Password: "password", + Nickname: "nickname", + Score: "score", + CreateAt: "create_at", + UpdateAt: "update_at", +} + +// NewUser4Dao creates and returns a new DAO object for table data access. +func NewUser4Dao() *User4Dao { + return &User4Dao{ + group: "book", + table: "user4", + columns: user4Columns, + } +} + +// DB retrieves and returns the underlying raw database management object of current DAO. +func (dao *User4Dao) DB() gdb.DB { + return g.DB(dao.group) +} + +// Table returns the table name of current dao. +func (dao *User4Dao) Table() string { + return dao.table +} + +// Columns returns all column names of current dao. +func (dao *User4Dao) Columns() User4Columns { + return dao.columns +} + +// Group returns the configuration group name of database of current dao. +func (dao *User4Dao) Group() string { + return dao.group +} + +// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +func (dao *User4Dao) Ctx(ctx context.Context) *gdb.Model { + return dao.DB().Model(dao.table).Safe().Ctx(ctx) +} + +// Transaction wraps the transaction logic using function f. +// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It commits the transaction and returns nil if function f returns nil. +// +// Note that, you should not Commit or Rollback the transaction in function f +// as it is automatically handled by this function. +func (dao *User4Dao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { + return dao.Ctx(ctx).Transaction(ctx, f) +} diff --git a/cmd/gf/internal/cmd/testdata/issue/2572/dao/user_3.go b/cmd/gf/internal/cmd/testdata/issue/2572/dao/user_3.go new file mode 100644 index 00000000000..375276e4823 --- /dev/null +++ b/cmd/gf/internal/cmd/testdata/issue/2572/dao/user_3.go @@ -0,0 +1,27 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package dao + +import ( + "/internal" +) + +// internalUser3Dao is internal type for wrapping internal DAO implements. +type internalUser3Dao = *internal.User3Dao + +// user3Dao is the data access object for table user3. +// You can define custom methods on it to extend its functionality as you wish. +type user3Dao struct { + internalUser3Dao +} + +var ( + // User3 is globally public accessible object for table user3 operations. + User3 = user3Dao{ + internal.NewUser3Dao(), + } +) + +// Fill with you ideas below. diff --git a/cmd/gf/internal/cmd/testdata/issue/2572/dao/user_4.go b/cmd/gf/internal/cmd/testdata/issue/2572/dao/user_4.go new file mode 100644 index 00000000000..7d023591979 --- /dev/null +++ b/cmd/gf/internal/cmd/testdata/issue/2572/dao/user_4.go @@ -0,0 +1,27 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package dao + +import ( + "/internal" +) + +// internalUser4Dao is internal type for wrapping internal DAO implements. +type internalUser4Dao = *internal.User4Dao + +// user4Dao is the data access object for table user4. +// You can define custom methods on it to extend its functionality as you wish. +type user4Dao struct { + internalUser4Dao +} + +var ( + // User4 is globally public accessible object for table user4 operations. + User4 = user4Dao{ + internal.NewUser4Dao(), + } +) + +// Fill with you ideas below. diff --git a/cmd/gf/internal/cmd/testdata/issue/2572/model/do/user_3.go b/cmd/gf/internal/cmd/testdata/issue/2572/model/do/user_3.go new file mode 100644 index 00000000000..14a1bf4e3d7 --- /dev/null +++ b/cmd/gf/internal/cmd/testdata/issue/2572/model/do/user_3.go @@ -0,0 +1,22 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package do + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gtime" +) + +// User1 is the golang structure of table user1 for DAO operations like Where/Data. +type User1 struct { + g.Meta `orm:"table:user1, do:true"` + Id interface{} // User ID + Passport interface{} // User Passport + Password interface{} // User Password + Nickname interface{} // User Nickname + Score interface{} // Total score amount. + CreateAt *gtime.Time // Created Time + UpdateAt *gtime.Time // Updated Time +} diff --git a/cmd/gf/internal/cmd/testdata/issue/2572/model/do/user_4.go b/cmd/gf/internal/cmd/testdata/issue/2572/model/do/user_4.go new file mode 100644 index 00000000000..8019772551f --- /dev/null +++ b/cmd/gf/internal/cmd/testdata/issue/2572/model/do/user_4.go @@ -0,0 +1,22 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package do + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gtime" +) + +// User2 is the golang structure of table user2 for DAO operations like Where/Data. +type User2 struct { + g.Meta `orm:"table:user2, do:true"` + Id interface{} // User ID + Passport interface{} // User Passport + Password interface{} // User Password + Nickname interface{} // User Nickname + Score interface{} // Total score amount. + CreateAt *gtime.Time // Created Time + UpdateAt *gtime.Time // Updated Time +} diff --git a/cmd/gf/internal/cmd/testdata/issue/2572/model/entity/user_3.go b/cmd/gf/internal/cmd/testdata/issue/2572/model/entity/user_3.go new file mode 100644 index 00000000000..de4cd54fb8d --- /dev/null +++ b/cmd/gf/internal/cmd/testdata/issue/2572/model/entity/user_3.go @@ -0,0 +1,20 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package entity + +import ( + "github.com/gogf/gf/v2/os/gtime" +) + +// User1 is the golang structure for table user1. +type User1 struct { + Id uint `json:"ID" description:"User ID"` + Passport string `json:"PASSPORT" description:"User Passport"` + Password string `json:"PASSWORD" description:"User Password"` + Nickname string `json:"NICKNAME" description:"User Nickname"` + Score float64 `json:"SCORE" description:"Total score amount."` + CreateAt *gtime.Time `json:"CREATE_AT" description:"Created Time"` + UpdateAt *gtime.Time `json:"UPDATE_AT" description:"Updated Time"` +} diff --git a/cmd/gf/internal/cmd/testdata/issue/2572/model/entity/user_4.go b/cmd/gf/internal/cmd/testdata/issue/2572/model/entity/user_4.go new file mode 100644 index 00000000000..4727f6260df --- /dev/null +++ b/cmd/gf/internal/cmd/testdata/issue/2572/model/entity/user_4.go @@ -0,0 +1,20 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package entity + +import ( + "github.com/gogf/gf/v2/os/gtime" +) + +// User2 is the golang structure for table user2. +type User2 struct { + Id uint `json:"ID" description:"User ID"` + Passport string `json:"PASSPORT" description:"User Passport"` + Password string `json:"PASSWORD" description:"User Password"` + Nickname string `json:"NICKNAME" description:"User Nickname"` + Score float64 `json:"SCORE" description:"Total score amount."` + CreateAt *gtime.Time `json:"CREATE_AT" description:"Created Time"` + UpdateAt *gtime.Time `json:"UPDATE_AT" description:"Updated Time"` +} diff --git a/cmd/gf/internal/cmd/testdata/issue/2572/sql1.sql b/cmd/gf/internal/cmd/testdata/issue/2572/sql1.sql new file mode 100644 index 00000000000..2877f1f0d06 --- /dev/null +++ b/cmd/gf/internal/cmd/testdata/issue/2572/sql1.sql @@ -0,0 +1,10 @@ +CREATE TABLE `user1` ( + `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'User ID', + `passport` varchar(45) NOT NULL COMMENT 'User Passport', + `password` varchar(45) NOT NULL COMMENT 'User Password', + `nickname` varchar(45) NOT NULL COMMENT 'User Nickname', + `score` decimal(10,2) unsigned DEFAULT NULL COMMENT 'Total score amount.', + `create_at` datetime DEFAULT NULL COMMENT 'Created Time', + `update_at` datetime DEFAULT NULL COMMENT 'Updated Time', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/cmd/gf/internal/cmd/testdata/issue/2572/sql2.sql b/cmd/gf/internal/cmd/testdata/issue/2572/sql2.sql new file mode 100644 index 00000000000..ca450aa72f0 --- /dev/null +++ b/cmd/gf/internal/cmd/testdata/issue/2572/sql2.sql @@ -0,0 +1,10 @@ +CREATE TABLE `user2` ( + `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'User ID', + `passport` varchar(45) NOT NULL COMMENT 'User Passport', + `password` varchar(45) NOT NULL COMMENT 'User Password', + `nickname` varchar(45) NOT NULL COMMENT 'User Nickname', + `score` decimal(10,2) unsigned DEFAULT NULL COMMENT 'Total score amount.', + `create_at` datetime DEFAULT NULL COMMENT 'Created Time', + `update_at` datetime DEFAULT NULL COMMENT 'Updated Time', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8;