Documentation
¶
Index ¶
- func ReverseAlterWithCompares(compares *ast.CreateTableStmt, alter *ast.AlterTableStmt) (string, bool, error)
- func ReverseCreateTableStmt(in *ast.CreateTableStmt) string
- func ReverseCreateTableStmts(ddlNodes interface{ ... }) string
- func ReverseDDLWithSnapshot(tx *gorm.DB, ddl ast.DDLNode) (reversing string, ok bool, err error)
- func ReverseDropIndexStmtWithCompares(compares *ast.CreateTableStmt, drop *ast.DropIndexStmt) (string, bool, error)
- func ShowCreateTable(tx *gorm.DB, tableName string) (create string, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReverseAlterWithCompares ¶
func ReverseAlterWithCompares(compares *ast.CreateTableStmt, alter *ast.AlterTableStmt) (string, bool, error)
ReverseAlterWithCompares for giving compares, returns the reversed SQL of AlterTableStmt
func ReverseCreateTableStmt ¶
func ReverseCreateTableStmt(in *ast.CreateTableStmt) string
func ReverseCreateTableStmts ¶
ReverseCreateTableStmts reverses DDLs without snapshot. Generally, this function is used to process the baseline, because when processing the baseline, it only needs to Drop all the newly created tables.
func ReverseDDLWithSnapshot ¶
ReverseDDLWithSnapshot reverses a DDL. e.g.
CreateTableStmt ==reverse-to==> DropTableStmt RenameTableStmt a to b ==reverse-to==> RenameTableStmt b to a AlterTableAddColumns ==reverse-to==> AlterTableDropColumn AlterTableOption to new ==reverse-to==> AlterTableOption to old ... ....
How to do this ? First, to snapshot the table definition from database, then generate the reversed DDL.
tx *gorm.DB is used to connect to database for getting table's snapshot; ddl ast.DDLNode is is the stmt node for revering.
reversing is the reversed DDL text; ok is whether reversing is success, if not ok, reversing is ""; err is whether an error has occurred, if err is not nil, ok is false, reversing is "".
If the ddl is not allowed (e.g. DropDatabaseStmt, DropTableStmt, AlterTableDropColumnSpec), the function will not process it, and returned err is nil, ok is false, reversing is "".
func ReverseDropIndexStmtWithCompares ¶
func ReverseDropIndexStmtWithCompares(compares *ast.CreateTableStmt, drop *ast.DropIndexStmt) (string, bool, error)
Types ¶
This section is empty.