Skip to content

Commit

Permalink
feat: migrator support table comment (#6225)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
maiqingqiang and jinzhu committed May 5, 2023
1 parent 32045fd commit e61b98d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
9 changes: 9 additions & 0 deletions migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions migrator/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
33 changes: 33 additions & 0 deletions migrator/table_type.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit e61b98d

Please sign in to comment.