Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SortMigrationsByOperationPriority ¶
func SortMigrationsByOperationPriority(migrations []*ColumnMigration)
This function sorts the given column migrations list by operation priority. The priority of the operation is determined by it's value, smaller value means higher priority
Types ¶
type Column ¶
type Column struct {
TableName string
Name string
ColumnType string
Null string
PrimaryKey bool
ForeignKey bool
UniqueIndex bool
DefaultValue sql.NullString
Extra string
}
func (*Column) ComparePrimary ¶
0 -> same primary. 1 -> c is not primary, col is primary. -1 -> c is primary, col is not primary.
func (*Column) PrettyPrint ¶
func (c *Column) PrettyPrint()
type ColumnMigration ¶
type ColumnMigration struct {
ApplyOn interface{}
Old interface{}
Operation ColumnOperation
}
func NewColumnMigration ¶
func NewColumnMigration(applyOn interface{}, old interface{}, operation ColumnOperation) *ColumnMigration
type ColumnOperation ¶
type ColumnOperation int
const ( DROP_FOREIGN_KEY ColumnOperation = iota DROP_UNIQUE_INDEX DROP_COLUMN RENAME_COLUMN MODIFY_COLUMN ADD_COLUMN UPDATE_FOREIGN_KEY ADD_FOREIGN_KEY ADD_UNIQUE_INDEX )
type Reference ¶
type Reference struct {
TableName string
ColumnName string
ReferencedTableName string
ReferencedColumnName string
DeleteOption ReferenceOption
UpdateOption ReferenceOption
IsUnique bool
}
func NewReference ¶
func NewReference(tableName string, columnName string, referencedTableName string, referencedColumnName string, deleteOption ReferenceOption, updateOption ReferenceOption) *Reference
func (*Reference) PrettyPrint ¶
func (r *Reference) PrettyPrint()
type ReferenceOption ¶
type ReferenceOption string
const ( RESTRICT_OPTION ReferenceOption = "RESTRICT" CASCADE_OPTION ReferenceOption = "CASCADE" SET_NULL_OPTION ReferenceOption = "SET NULL" NO_ACTION_OPTION ReferenceOption = "NO ACTION" SET_DEFAULT_OPTION ReferenceOption = "SET DEFAULT" )
type Table ¶
type Table struct {
Name string
Columns []*Column
References []Reference
IndexToUniqueCols map[string][]string // index name maps to list of column names
PrimaryCols []string
}
func (*Table) CompareUniqueIndex ¶
0 -> same \r 1 -> t does not have the index or some columns are missing. Indexes are not same
func (*Table) CompareWith ¶
func (t *Table) CompareWith(dst *Table) []*ColumnMigration
Compares the caller table with the given dst table and creates migrations to change caller table into given 'dst' table
func (*Table) GetPrimaryKeyColumn ¶
TODO: handle composite primary keys Returns primaryKey column. If not found returns nil
func (*Table) HasColumn ¶
Checks columns existance by name, returns its index if exists. Returns -1 if column not found
func (*Table) PrettyPrint ¶
func (t *Table) PrettyPrint()