From e61b98d69677b8871d832baf2489942d79054a4a Mon Sep 17 00:00:00 2001 From: John Mai Date: Fri, 5 May 2023 15:58:27 +0800 Subject: [PATCH] feat: migrator support table comment (#6225) * feat: migrator support table comment * feat: migrator support tableType.It like ColumnTypes * Avoid updating the go.mod file. * Update tests_all.sh * Update migrator.go * remove Catalog() & Engine() methods. * remove CatalogValue & EngineValue. --------- Co-authored-by: Jinzhu --- migrator.go | 9 +++++++++ migrator/migrator.go | 5 +++++ migrator/table_type.go | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 migrator/table_type.go diff --git a/migrator.go b/migrator.go index 037afc35..0e01f567 100644 --- a/migrator.go +++ b/migrator.go @@ -56,6 +56,14 @@ type Index interface { Option() string } +// TableType table type interface +type TableType interface { + Schema() string + Name() string + Type() string + Comment() (comment string, ok bool) +} + // Migrator migrator interface type Migrator interface { // AutoMigrate @@ -72,6 +80,7 @@ type Migrator interface { HasTable(dst interface{}) bool RenameTable(oldName, newName interface{}) error GetTables() (tableList []string, err error) + TableType(dst interface{}) (TableType, error) // Columns AddColumn(dst interface{}, field string) error diff --git a/migrator/migrator.go b/migrator/migrator.go index 32c6a059..de60f91c 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -949,3 +949,8 @@ func (m Migrator) GetIndexes(dst interface{}) ([]gorm.Index, error) { func (m Migrator) GetTypeAliases(databaseTypeName string) []string { return nil } + +// TableType return tableType gorm.TableType and execErr error +func (m Migrator) TableType(dst interface{}) (gorm.TableType, error) { + return nil, errors.New("not support") +} diff --git a/migrator/table_type.go b/migrator/table_type.go new file mode 100644 index 00000000..ed6e42a0 --- /dev/null +++ b/migrator/table_type.go @@ -0,0 +1,33 @@ +package migrator + +import ( + "database/sql" +) + +// TableType table type implements TableType interface +type TableType struct { + SchemaValue string + NameValue string + TypeValue string + CommentValue sql.NullString +} + +// Schema returns the schema of the table. +func (ct TableType) Schema() string { + return ct.SchemaValue +} + +// Name returns the name of the table. +func (ct TableType) Name() string { + return ct.NameValue +} + +// Type returns the type of the table. +func (ct TableType) Type() string { + return ct.TypeValue +} + +// Comment returns the comment of current table. +func (ct TableType) Comment() (comment string, ok bool) { + return ct.CommentValue.String, ct.CommentValue.Valid +}