Documentation ¶
Index ¶
- func GetExpandedColumnNames(sourceSharedColumns *ColumnList, targetSharedColumns *ColumnList) (expandedColumnNames []string, expandedDescriptions map[string]string)
- func GetNoDefaultColumnNames(columns *ColumnList) (names []string)
- func GetSharedColumns(sourceColumns, targetColumns *ColumnList, ...) (sourceSharedColumns *ColumnList, targetSharedColumns *ColumnList, ...)
- func RemovedForeignKeyNames(venv *vtenv.Environment, originalCreateTable string, vreplCreateTable string) (names []string, err error)
- func SourceUniqueKeyAsOrMoreConstrainedThanTarget(sourceUniqueKey, targetUniqueKey *UniqueKey, columnRenameMap map[string]string) bool
- func UniqueKeyValidForIteration(uniqueKey *UniqueKey) bool
- type AlterTableParser
- func (p *AlterTableParser) ColumnRenameMap() map[string]string
- func (p *AlterTableParser) DroppedColumnsMap() map[string]bool
- func (p *AlterTableParser) GetNonTrivialRenames() map[string]string
- func (p *AlterTableParser) HasNonTrivialRenames() bool
- func (p *AlterTableParser) IsAutoIncrementDefined() bool
- func (p *AlterTableParser) IsRenameTable() bool
- func (p *AlterTableParser) ParseAlterStatement(alterQuery string, parser *sqlparser.Parser) (err error)
- type Column
- type ColumnList
- func (l *ColumnList) ColumnExists(columnName string) bool
- func (l *ColumnList) Columns() []Column
- func (l *ColumnList) Difference(other *ColumnList) (diff *ColumnList)
- func (l *ColumnList) Equals(other *ColumnList) bool
- func (l *ColumnList) EqualsByNames(other *ColumnList) bool
- func (l *ColumnList) GetColumn(columnName string) *Column
- func (l *ColumnList) IsEnumToTextConversion(columnName string) bool
- func (l *ColumnList) IsSubsetOf(other *ColumnList) bool
- func (l *ColumnList) Len() int
- func (l *ColumnList) MappedNamesColumnList(columnNamesMap map[string]string) *ColumnList
- func (l *ColumnList) Names() []string
- func (l *ColumnList) SetEnumToTextConversion(columnName string, enumValues string)
- func (l *ColumnList) String() string
- type ColumnType
- type ColumnsMap
- type UniqueKey
- func AddedUniqueKeys(sourceUniqueKeys, targetUniqueKeys [](*UniqueKey), ...) (addedUKs [](*UniqueKey))
- func GetSharedUniqueKeys(sourceUniqueKeys, targetUniqueKeys [](*UniqueKey), ...) (chosenSourceUniqueKey, chosenTargetUniqueKey *UniqueKey)
- func GetUniqueKeyCoveredByColumns(uniqueKeys [](*UniqueKey), columns *ColumnList) (chosenUniqueKey *UniqueKey)
- func RemovedUniqueKeys(sourceUniqueKeys, targetUniqueKeys [](*UniqueKey), ...) (removedUKs [](*UniqueKey))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetExpandedColumnNames ¶
func GetExpandedColumnNames( sourceSharedColumns *ColumnList, targetSharedColumns *ColumnList, ) ( expandedColumnNames []string, expandedDescriptions map[string]string, )
GetExpandedColumnNames is given source and target shared columns, and returns the list of columns whose data type is expanded. An expanded data type is one where the target can have a value which the source does not. Examples: - any NOT NULL to NULLable (a NULL in the target cannot appear on source) - INT -> BIGINT (obvious) - BIGINT UNSIGNED -> INT SIGNED (negative values) - TIMESTAMP -> TIMESTAMP(3) etc.
func GetNoDefaultColumnNames ¶
func GetNoDefaultColumnNames(columns *ColumnList) (names []string)
GetNoDefaultColumnNames returns names of columns which have no default value, out of given list of columns
func GetSharedColumns ¶
func GetSharedColumns( sourceColumns, targetColumns *ColumnList, sourceVirtualColumns, targetVirtualColumns *ColumnList, parser *AlterTableParser, ) ( sourceSharedColumns *ColumnList, targetSharedColumns *ColumnList, droppedSourceNonGeneratedColumns *ColumnList, sharedColumnsMap map[string]string, )
GetSharedColumns returns the intersection of two lists of columns in same order as the first list
func RemovedForeignKeyNames ¶
func RemovedForeignKeyNames( venv *vtenv.Environment, originalCreateTable string, vreplCreateTable string, ) (names []string, err error)
RemovedForeignKeyNames returns the names of removed foreign keys, ignoring mere name changes
func SourceUniqueKeyAsOrMoreConstrainedThanTarget ¶
func SourceUniqueKeyAsOrMoreConstrainedThanTarget(sourceUniqueKey, targetUniqueKey *UniqueKey, columnRenameMap map[string]string) bool
SourceUniqueKeyAsOrMoreConstrainedThanTarget returns 'true' when sourceUniqueKey is at least as constrained as targetUniqueKey. "More constrained" means the uniqueness constraint is "stronger". Thus, if sourceUniqueKey is as-or-more constrained than targetUniqueKey, then rows valid under sourceUniqueKey must also be valid in targetUniqueKey. The opposite is not necessarily so: rows that are valid in targetUniqueKey may cause a unique key violation under sourceUniqueKey
func UniqueKeyValidForIteration ¶
UniqueKeyValidForIteration returns 'false' if we should not use this unique key as the main iteration key in vreplication.
Types ¶
type AlterTableParser ¶
type AlterTableParser struct {
// contains filtered or unexported fields
}
AlterTableParser is a parser tool for ALTER TABLE statements This is imported from gh-ost. In the future, we should replace that with Vitess parsing.
func NewAlterTableParser ¶
func NewAlterTableParser() *AlterTableParser
NewAlterTableParser creates a new parser
func NewParserFromAlterStatement ¶
func NewParserFromAlterStatement(alterTable *sqlparser.AlterTable) *AlterTableParser
NewParserFromAlterStatement creates a new parser with a ALTER TABLE statement
func (*AlterTableParser) ColumnRenameMap ¶
func (p *AlterTableParser) ColumnRenameMap() map[string]string
ColumnRenameMap returns the renamed column mapping
func (*AlterTableParser) DroppedColumnsMap ¶
func (p *AlterTableParser) DroppedColumnsMap() map[string]bool
DroppedColumnsMap returns list of dropped columns
func (*AlterTableParser) GetNonTrivialRenames ¶
func (p *AlterTableParser) GetNonTrivialRenames() map[string]string
GetNonTrivialRenames gets a list of renamed column
func (*AlterTableParser) HasNonTrivialRenames ¶
func (p *AlterTableParser) HasNonTrivialRenames() bool
HasNonTrivialRenames is true when columns have been renamed
func (*AlterTableParser) IsAutoIncrementDefined ¶
func (p *AlterTableParser) IsAutoIncrementDefined() bool
IsAutoIncrementDefined returns true when alter options include an explicit AUTO_INCREMENT value
func (*AlterTableParser) IsRenameTable ¶
func (p *AlterTableParser) IsRenameTable() bool
IsRenameTable returns true when the ALTER TABLE statement includes renaming the table
func (*AlterTableParser) ParseAlterStatement ¶
func (p *AlterTableParser) ParseAlterStatement(alterQuery string, parser *sqlparser.Parser) (err error)
ParseAlterStatement is the main function of th eparser, and parses an ALTER TABLE statement
type Column ¶
type Column struct { Name string IsUnsigned bool Charset string Collation string Type ColumnType EnumValues string EnumToTextConversion bool DataType string // from COLUMN_TYPE column IsNullable bool IsDefaultNull bool CharacterMaximumLength int64 NumericPrecision int64 NumericScale int64 DateTimePrecision int64 // add Octet length for binary type, fix bytes with suffix "00" get clipped in mysql binlog. // https://github.com/github/gh-ost/issues/909 BinaryOctetLength uint64 }
Column represents a table column
func NewColumns ¶
NewColumns creates a new column array from non empty names
func ParseColumns ¶
ParseColumns creates a new column array fby parsing comma delimited names list
func (*Column) HasDefault ¶
HasDefault returns true if the column at all has a default value (possibly NULL)
func (*Column) IsFloatingPoint ¶
IsFloatingPoint returns true if the column is of a floating point numeric type
func (*Column) IsIntegralType ¶
IsIntegralType returns true if the column is some form of an integer
func (*Column) IsTemporal ¶
IsFloatingPoint returns true if the column is of a temporal type
func (*Column) SetTypeIfUnknown ¶
func (c *Column) SetTypeIfUnknown(t ColumnType)
SetTypeIfUnknown will set a new column type only if the current type is unknown, otherwise silently skip
type ColumnList ¶
type ColumnList struct { Ordinals ColumnsMap // contains filtered or unexported fields }
ColumnList makes for a named list of columns
func NewColumnList ¶
func NewColumnList(names []string) *ColumnList
NewColumnList creates an object given ordered list of column names
func ParseColumnList ¶
func ParseColumnList(names string) *ColumnList
ParseColumnList parses a comma delimited list of column names
func (*ColumnList) ColumnExists ¶
func (l *ColumnList) ColumnExists(columnName string) bool
ColumnExists returns true if this column list has a column by a given name
func (*ColumnList) Columns ¶
func (l *ColumnList) Columns() []Column
Columns returns the list of columns
func (*ColumnList) Difference ¶
func (l *ColumnList) Difference(other *ColumnList) (diff *ColumnList)
Difference returns a (new copy) subset of this column list, consisting of all column NOT in given list. The result is never nil, even if the difference is empty
func (*ColumnList) Equals ¶
func (l *ColumnList) Equals(other *ColumnList) bool
Equals checks for complete (deep) identities of columns, in order.
func (*ColumnList) EqualsByNames ¶
func (l *ColumnList) EqualsByNames(other *ColumnList) bool
EqualsByNames checks if the names in this list equals the names of another list, in order. Type is ignored.
func (*ColumnList) GetColumn ¶
func (l *ColumnList) GetColumn(columnName string) *Column
GetColumn gets a column by name
func (*ColumnList) IsEnumToTextConversion ¶
func (l *ColumnList) IsEnumToTextConversion(columnName string) bool
IsEnumToTextConversion tells whether an enum was converted to text
func (*ColumnList) IsSubsetOf ¶
func (l *ColumnList) IsSubsetOf(other *ColumnList) bool
IsSubsetOf returns 'true' when column names of this list are a subset of another list, in arbitrary order (order agnostic)
func (*ColumnList) MappedNamesColumnList ¶
func (l *ColumnList) MappedNamesColumnList(columnNamesMap map[string]string) *ColumnList
MappedNamesColumnList returns a column list based on this list, with names possibly mapped by given map
func (*ColumnList) SetEnumToTextConversion ¶
func (l *ColumnList) SetEnumToTextConversion(columnName string, enumValues string)
SetEnumToTextConversion tells this column list that an enum is converted to text
func (*ColumnList) String ¶
func (l *ColumnList) String() string
String returns a comma separated list of column names
type ColumnType ¶
type ColumnType int
ColumnType indicated some MySQL data types
const ( UnknownColumnType ColumnType = iota TimestampColumnType DateTimeColumnType EnumColumnType SetColumnType MediumIntColumnType JSONColumnType FloatColumnType DoubleColumnType BinaryColumnType StringColumnType IntegerColumnType )
type ColumnsMap ¶
ColumnsMap maps a column name onto its ordinal position
func NewColumnsMap ¶
func NewColumnsMap(orderedColumns []Column) ColumnsMap
NewColumnsMap creates a column map based on ordered list of columns
func NewEmptyColumnsMap ¶
func NewEmptyColumnsMap() ColumnsMap
NewEmptyColumnsMap creates an empty map
type UniqueKey ¶
type UniqueKey struct { Name string Columns ColumnList HasNullable bool HasSubpart bool HasFloat bool IsAutoIncrement bool }
UniqueKey is the combination of a key's name and columns
func AddedUniqueKeys ¶
func AddedUniqueKeys(sourceUniqueKeys, targetUniqueKeys [](*UniqueKey), columnRenameMap map[string]string) (addedUKs [](*UniqueKey))
AddedUniqueKeys returns the unique key constraints added in target. This does not necessarily mean that the unique key itself is new, rather that there's a new, stricter constraint on a set of columns, that didn't exist before. Example:
before: unique key `my_key`(c1, c2, c3); after: unique key `my_key`(c1, c2) The constraint on (c1, c2) is new; and `my_key` in target table ("after") is considered a new key
Order of columns is immaterial to uniqueness of column combination.
func GetSharedUniqueKeys ¶
func GetSharedUniqueKeys(sourceUniqueKeys, targetUniqueKeys [](*UniqueKey), columnRenameMap map[string]string) (chosenSourceUniqueKey, chosenTargetUniqueKey *UniqueKey)
GetSharedUniqueKeys returns the unique keys shared between the source & target tables
func GetUniqueKeyCoveredByColumns ¶
func GetUniqueKeyCoveredByColumns(uniqueKeys [](*UniqueKey), columns *ColumnList) (chosenUniqueKey *UniqueKey)
GetUniqueKeyCoveredByColumns returns the first unique key from given list, whose columns all appear in given column list.
func RemovedUniqueKeys ¶
func RemovedUniqueKeys(sourceUniqueKeys, targetUniqueKeys [](*UniqueKey), columnRenameMap map[string]string) (removedUKs [](*UniqueKey))
RemovedUniqueKeys returns the list of unique key constraints _removed_ going from source to target.