ddlreverser

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

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

func ReverseCreateTableStmts(ddlNodes interface{ DDLNodes() []ast.DDLNode }) string

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

func ReverseDDLWithSnapshot(tx *gorm.DB, ddl ast.DDLNode) (reversing string, ok bool, err error)

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)

func ReverseSlice

func ReverseSlice(s interface{})

func ShowCreateTable

func ShowCreateTable(tx *gorm.DB, tableName string) (create string, err error)

ShowCreateTable gets create table stmt by executing SHOW CREATE TABLE .

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL