vrepl

package
v0.19.4 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetExpandedColumnNames added in v0.13.0

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 added in v0.13.0

func GetNoDefaultColumnNames(columns *ColumnList) (names []string)

GetNoDefaultColumnNames returns names of columns which have no default value, out of given list of columns

func GetSharedColumns added in v0.13.0

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 added in v0.19.0

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 added in v0.13.0

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 added in v0.13.0

func UniqueKeyValidForIteration(uniqueKey *UniqueKey) bool

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

func NewColumns(names []string) []Column

NewColumns creates a new column array from non empty names

func ParseColumns

func ParseColumns(names string) []Column

ParseColumns creates a new column array fby parsing comma delimited names list

func (*Column) HasDefault added in v0.13.0

func (c *Column) HasDefault() bool

HasDefault returns true if the column at all has a default value (possibly NULL)

func (*Column) IsFloatingPoint added in v0.13.0

func (c *Column) IsFloatingPoint() bool

IsFloatingPoint returns true if the column is of a floating point numeric type

func (*Column) IsIntegralType added in v0.16.0

func (c *Column) IsIntegralType() bool

IsIntegralType returns true if the column is some form of an integer

func (*Column) IsNumeric added in v0.13.0

func (c *Column) IsNumeric() bool

IsNumeric returns true if the column is of a numeric type

func (*Column) IsTemporal added in v0.13.0

func (c *Column) IsTemporal() bool

IsFloatingPoint returns true if the column is of a temporal type

func (*Column) SetTypeIfUnknown added in v0.11.0

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 added in v0.12.0

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 added in v0.12.0

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 added in v0.11.0

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) Len

func (l *ColumnList) Len() int

Len returns the length of this list

func (*ColumnList) MappedNamesColumnList added in v0.12.0

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) Names

func (l *ColumnList) Names() []string

Names returns list of column names

func (*ColumnList) SetEnumToTextConversion added in v0.11.0

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

type ColumnsMap map[string]int

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 added in v0.13.0

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 added in v0.13.0

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 added in v0.13.0

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 added in v0.13.0

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.

func (*UniqueKey) IsPrimary

func (k *UniqueKey) IsPrimary() bool

IsPrimary checks if this unique key is primary

func (*UniqueKey) Len

func (k *UniqueKey) Len() int

Len returns the length of this list

func (*UniqueKey) String

func (k *UniqueKey) String() string

String returns a visual representation of this key

Jump to

Keyboard shortcuts

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