Documentation ¶
Index ¶
- Constants
- Variables
- func AddInstantAlgorithm(alterTable *sqlparser.AlterTable)
- func AlterTableCapableOfInstantDDL(alterTable *sqlparser.AlterTable, createTable *sqlparser.CreateTable, ...) (bool, error)
- func AlterTableRotatesRangePartition(createTable *sqlparser.CreateTable, alterTable *sqlparser.AlterTable) (bool, error)
- func AnalyzeSharedColumns(sourceColumns, targetColumns *ColumnDefinitionEntityList, ...) (sourceSharedColumns *ColumnDefinitionEntityList, ...)
- func BlobTypeStorage(columnType string) int
- func ColumnChangeExpandsDataRange(source *ColumnDefinitionEntity, target *ColumnDefinitionEntity) (bool, string)
- func DDLActionStr(diff EntityDiff) (string, error)
- func DuplicateCreateTable(originalCreateTable *sqlparser.CreateTable, baseUUID string, ...) (newCreateTable *sqlparser.CreateTable, constraintMap map[string]string, ...)
- func ExtractConstraintOriginalName(tableName string, constraintName string) string
- func FloatingPointTypeStorage(columnType string) int
- func IntegralTypeStorage(columnType string) int
- func IsDecimalType(columnType string) bool
- func IsExpandingDataType(sourceType string, targetType string) bool
- func IsFloatingPointType(columnType string) bool
- func IsGeneratedColumn(col *sqlparser.ColumnDefinition) (bool, sqlparser.ColumnStorage)
- func IsIntegralType(columnType string) bool
- func IsValidIterationKey(key *IndexDefinitionEntity) bool
- func KeyAtLeastConstrainedAs(sourceUniqueKey *IndexDefinitionEntity, targetUniqueKey *IndexDefinitionEntity, ...) bool
- func MappedColumnNames(columnsList *ColumnDefinitionEntityList, columnNamesMap map[string]string) []string
- func RemovedForeignKeyNames(source *CreateTableEntity, target *CreateTableEntity) (names []string, err error)
- func ValidateAndEditAlterTableStatement(originalTableName string, baseUUID string, capableOf capabilities.CapableOf, ...) (alters []*sqlparser.AlterTable, err error)
- func ValidateAndEditCreateTableStatement(originalTableName string, baseUUID string, createTable *sqlparser.CreateTable, ...) (constraintMap map[string]string, err error)
- type AlterTableAnalysis
- type AlterTableEntityDiff
- func (d *AlterTableEntityDiff) AlterTable() *sqlparser.AlterTable
- func (d *AlterTableEntityDiff) Annotated() (from *TextualAnnotations, to *TextualAnnotations, unified *TextualAnnotations)
- func (d *AlterTableEntityDiff) CanonicalStatementString() string
- func (d *AlterTableEntityDiff) Clone() EntityDiff
- func (d *AlterTableEntityDiff) Entities() (from Entity, to Entity)
- func (d *AlterTableEntityDiff) EntityName() string
- func (d *AlterTableEntityDiff) InstantDDLCapability() InstantDDLCapability
- func (d *AlterTableEntityDiff) IsEmpty() bool
- func (d *AlterTableEntityDiff) SetSubsequentDiff(subDiff EntityDiff)
- func (d *AlterTableEntityDiff) Statement() sqlparser.Statement
- func (d *AlterTableEntityDiff) StatementString() (s string)
- func (d *AlterTableEntityDiff) SubsequentDiff() EntityDiff
- type AlterViewEntityDiff
- func (d *AlterViewEntityDiff) AlterView() *sqlparser.AlterView
- func (d *AlterViewEntityDiff) Annotated() (from *TextualAnnotations, to *TextualAnnotations, unified *TextualAnnotations)
- func (d *AlterViewEntityDiff) CanonicalStatementString() string
- func (d *AlterViewEntityDiff) Clone() EntityDiff
- func (d *AlterViewEntityDiff) Entities() (from Entity, to Entity)
- func (d *AlterViewEntityDiff) EntityName() string
- func (d *AlterViewEntityDiff) InstantDDLCapability() InstantDDLCapability
- func (d *AlterViewEntityDiff) IsEmpty() bool
- func (d *AlterViewEntityDiff) SetSubsequentDiff(EntityDiff)
- func (d *AlterViewEntityDiff) Statement() sqlparser.Statement
- func (d *AlterViewEntityDiff) StatementString() (s string)
- func (d *AlterViewEntityDiff) SubsequentDiff() EntityDiff
- type AnnotatedText
- type ApplyColumnAfterNotFoundError
- type ApplyColumnNotFoundError
- type ApplyConstraintNotFoundError
- type ApplyDuplicateColumnError
- type ApplyDuplicateConstraintError
- type ApplyDuplicateEntityError
- type ApplyDuplicateKeyError
- type ApplyDuplicatePartitionError
- type ApplyKeyNotFoundError
- type ApplyNoPartitionsError
- type ApplyPartitionNotFoundError
- type ApplyTableNotFoundError
- type ApplyViewNotFoundError
- type ColumnDefinitionEntity
- func (c *ColumnDefinitionEntity) Charset() string
- func (c *ColumnDefinitionEntity) Clone() *ColumnDefinitionEntity
- func (c *ColumnDefinitionEntity) Collate() string
- func (c *ColumnDefinitionEntity) ColumnDiff(env *Environment, tableName string, other *ColumnDefinitionEntity, ...) (*ModifyColumnDiff, error)
- func (c *ColumnDefinitionEntity) EnumOrdinalValues() map[int]string
- func (c *ColumnDefinitionEntity) EnumValues() []string
- func (c *ColumnDefinitionEntity) EnumValuesOrdinals() map[string]int
- func (c *ColumnDefinitionEntity) HasBlobTypeStorage() bool
- func (c *ColumnDefinitionEntity) HasDefault() bool
- func (c *ColumnDefinitionEntity) HasEnumValues() bool
- func (c *ColumnDefinitionEntity) IsAutoIncrement() bool
- func (c *ColumnDefinitionEntity) IsDecimalType() bool
- func (c *ColumnDefinitionEntity) IsDefaultNull() bool
- func (c *ColumnDefinitionEntity) IsFloatingPointType() bool
- func (c *ColumnDefinitionEntity) IsGenerated() bool
- func (c *ColumnDefinitionEntity) IsIntegralType() bool
- func (c *ColumnDefinitionEntity) IsNullable() bool
- func (c *ColumnDefinitionEntity) IsTextual() bool
- func (c *ColumnDefinitionEntity) IsUnsigned() bool
- func (c *ColumnDefinitionEntity) Length() int
- func (c *ColumnDefinitionEntity) Name() string
- func (c *ColumnDefinitionEntity) NameLowered() string
- func (c *ColumnDefinitionEntity) Scale() int
- func (c *ColumnDefinitionEntity) SetExplicitCharsetCollate() error
- func (c *ColumnDefinitionEntity) SetExplicitDefaultAndNull()
- func (c *ColumnDefinitionEntity) Type() string
- type ColumnDefinitionEntityList
- func (l *ColumnDefinitionEntityList) Clone() *ColumnDefinitionEntityList
- func (l *ColumnDefinitionEntityList) Contains(other *ColumnDefinitionEntityList) bool
- func (l *ColumnDefinitionEntityList) Filter(include func(entity *ColumnDefinitionEntity) bool) *ColumnDefinitionEntityList
- func (l *ColumnDefinitionEntityList) GetColumn(name string) *ColumnDefinitionEntity
- func (l *ColumnDefinitionEntityList) Len() int
- func (l *ColumnDefinitionEntityList) Names() []string
- func (l *ColumnDefinitionEntityList) Union(other *ColumnDefinitionEntityList) *ColumnDefinitionEntityList
- type ConstraintType
- type CreateTableEntity
- func (c *CreateTableEntity) Apply(diff EntityDiff) (Entity, error)
- func (c *CreateTableEntity) AutoIncrementValue() (autoIncrement uint64, err error)
- func (c *CreateTableEntity) Clone() Entity
- func (c *CreateTableEntity) ColumnDefinitionEntities() []*ColumnDefinitionEntity
- func (c *CreateTableEntity) ColumnDefinitionEntitiesList() *ColumnDefinitionEntityList
- func (c *CreateTableEntity) ColumnDefinitionEntitiesMap() map[string]*ColumnDefinitionEntity
- func (c *CreateTableEntity) Create() EntityDiff
- func (c *CreateTableEntity) Diff(other Entity, hints *DiffHints) (EntityDiff, error)
- func (c *CreateTableEntity) Drop() EntityDiff
- func (c *CreateTableEntity) GetCharset() string
- func (c *CreateTableEntity) GetCollation() string
- func (c *CreateTableEntity) IndexDefinitionEntities() []*IndexDefinitionEntity
- func (c *CreateTableEntity) IndexDefinitionEntitiesList() *IndexDefinitionEntityList
- func (c *CreateTableEntity) IndexDefinitionEntitiesMap() map[string]*IndexDefinitionEntity
- func (c *CreateTableEntity) Name() string
- func (c *CreateTableEntity) TableDiff(other *CreateTableEntity, hints *DiffHints) (*AlterTableEntityDiff, error)
- type CreateTableEntityDiff
- func (d *CreateTableEntityDiff) Annotated() (from *TextualAnnotations, to *TextualAnnotations, unified *TextualAnnotations)
- func (d *CreateTableEntityDiff) CanonicalStatementString() string
- func (d *CreateTableEntityDiff) Clone() EntityDiff
- func (d *CreateTableEntityDiff) CreateTable() *sqlparser.CreateTable
- func (d *CreateTableEntityDiff) Entities() (from Entity, to Entity)
- func (d *CreateTableEntityDiff) EntityName() string
- func (d *CreateTableEntityDiff) InstantDDLCapability() InstantDDLCapability
- func (d *CreateTableEntityDiff) IsEmpty() bool
- func (d *CreateTableEntityDiff) SetSubsequentDiff(EntityDiff)
- func (d *CreateTableEntityDiff) Statement() sqlparser.Statement
- func (d *CreateTableEntityDiff) StatementString() (s string)
- func (d *CreateTableEntityDiff) SubsequentDiff() EntityDiff
- type CreateViewEntity
- func (c *CreateViewEntity) Apply(diff EntityDiff) (Entity, error)
- func (c *CreateViewEntity) Clone() Entity
- func (c *CreateViewEntity) Create() EntityDiff
- func (c *CreateViewEntity) Diff(other Entity, hints *DiffHints) (EntityDiff, error)
- func (c *CreateViewEntity) Drop() EntityDiff
- func (c *CreateViewEntity) Name() string
- func (c *CreateViewEntity) ViewDiff(other *CreateViewEntity, _ *DiffHints) (*AlterViewEntityDiff, error)
- type CreateViewEntityDiff
- func (d *CreateViewEntityDiff) Annotated() (from *TextualAnnotations, to *TextualAnnotations, unified *TextualAnnotations)
- func (d *CreateViewEntityDiff) CanonicalStatementString() string
- func (d *CreateViewEntityDiff) Clone() EntityDiff
- func (d *CreateViewEntityDiff) CreateView() *sqlparser.CreateView
- func (d *CreateViewEntityDiff) Entities() (from Entity, to Entity)
- func (d *CreateViewEntityDiff) EntityName() string
- func (d *CreateViewEntityDiff) InstantDDLCapability() InstantDDLCapability
- func (d *CreateViewEntityDiff) IsEmpty() bool
- func (d *CreateViewEntityDiff) SetSubsequentDiff(EntityDiff)
- func (d *CreateViewEntityDiff) Statement() sqlparser.Statement
- func (d *CreateViewEntityDiff) StatementString() (s string)
- func (d *CreateViewEntityDiff) SubsequentDiff() EntityDiff
- type DiffDependency
- type DiffDependencyType
- type DiffHints
- type DropTableEntityDiff
- func (d *DropTableEntityDiff) Annotated() (from *TextualAnnotations, to *TextualAnnotations, unified *TextualAnnotations)
- func (d *DropTableEntityDiff) CanonicalStatementString() string
- func (d *DropTableEntityDiff) Clone() EntityDiff
- func (d *DropTableEntityDiff) DropTable() *sqlparser.DropTable
- func (d *DropTableEntityDiff) Entities() (from Entity, to Entity)
- func (d *DropTableEntityDiff) EntityName() string
- func (d *DropTableEntityDiff) InstantDDLCapability() InstantDDLCapability
- func (d *DropTableEntityDiff) IsEmpty() bool
- func (d *DropTableEntityDiff) SetSubsequentDiff(EntityDiff)
- func (d *DropTableEntityDiff) Statement() sqlparser.Statement
- func (d *DropTableEntityDiff) StatementString() (s string)
- func (d *DropTableEntityDiff) SubsequentDiff() EntityDiff
- type DropViewEntityDiff
- func (d *DropViewEntityDiff) Annotated() (from *TextualAnnotations, to *TextualAnnotations, unified *TextualAnnotations)
- func (d *DropViewEntityDiff) CanonicalStatementString() string
- func (d *DropViewEntityDiff) Clone() EntityDiff
- func (d *DropViewEntityDiff) DropView() *sqlparser.DropView
- func (d *DropViewEntityDiff) Entities() (from Entity, to Entity)
- func (d *DropViewEntityDiff) EntityName() string
- func (d *DropViewEntityDiff) InstantDDLCapability() InstantDDLCapability
- func (d *DropViewEntityDiff) IsEmpty() bool
- func (d *DropViewEntityDiff) SetSubsequentDiff(EntityDiff)
- func (d *DropViewEntityDiff) Statement() sqlparser.Statement
- func (d *DropViewEntityDiff) StatementString() (s string)
- func (d *DropViewEntityDiff) SubsequentDiff() EntityDiff
- type DuplicateKeyNameError
- type Entity
- type EntityDiff
- func AllSubsequent(diff EntityDiff) (diffs []EntityDiff)
- func AtomicDiffs(diff EntityDiff) []EntityDiff
- func DiffCreateTablesQueries(env *Environment, query1 string, query2 string, hints *DiffHints) (EntityDiff, error)
- func DiffCreateViewsQueries(env *Environment, query1 string, query2 string, hints *DiffHints) (EntityDiff, error)
- func DiffTables(env *Environment, create1 *sqlparser.CreateTable, ...) (EntityDiff, error)
- func DiffViews(env *Environment, create1 *sqlparser.CreateView, create2 *sqlparser.CreateView, ...) (EntityDiff, error)
- func EntityDiffByStatement(statement sqlparser.Statement) EntityDiff
- type EntityNotFoundError
- type EnumValueOrdinalChangedError
- type Environment
- type ForeignKeyColumnCountMismatchError
- type ForeignKeyColumnTypeMismatchError
- type ForeignKeyDependencyUnresolvedError
- type ForeignKeyNonexistentReferencedTableError
- type ForeignKeyReferencesViewError
- type ForeignKeyTableColumns
- type ImpossibleApplyDiffOrderError
- type IndexDefinitionEntity
- func (i *IndexDefinitionEntity) Clone() *IndexDefinitionEntity
- func (i *IndexDefinitionEntity) ColumnNames() []string
- func (i *IndexDefinitionEntity) ContainsColumns(columns *ColumnDefinitionEntityList) bool
- func (i *IndexDefinitionEntity) CoveredByColumns(columns *ColumnDefinitionEntityList) bool
- func (i *IndexDefinitionEntity) HasColumnPrefix() bool
- func (i *IndexDefinitionEntity) HasFloat() bool
- func (i *IndexDefinitionEntity) HasNullable() bool
- func (i *IndexDefinitionEntity) IsPrimary() bool
- func (i *IndexDefinitionEntity) IsUnique() bool
- func (i *IndexDefinitionEntity) Len() int
- func (i *IndexDefinitionEntity) Name() string
- func (i *IndexDefinitionEntity) NameLowered() string
- type IndexDefinitionEntityList
- func IntroducedUniqueConstraints(sourceUniqueKeys *IndexDefinitionEntityList, ...) *IndexDefinitionEntityList
- func IterationKeysByColumns(keys *IndexDefinitionEntityList, columns *ColumnDefinitionEntityList) *IndexDefinitionEntityList
- func NewIndexDefinitionEntityList(entities []*IndexDefinitionEntity) *IndexDefinitionEntityList
- func PrioritizedUniqueKeys(createTableEntity *CreateTableEntity) *IndexDefinitionEntityList
- func RemovedUniqueConstraints(sourceUniqueKeys *IndexDefinitionEntityList, ...) *IndexDefinitionEntityList
- type IndexNeededByForeignKeyError
- type InstantDDLCapability
- type InvalidColumnInCheckConstraintError
- type InvalidColumnInForeignKeyConstraintError
- type InvalidColumnInGeneratedColumnError
- type InvalidColumnInKeyError
- type InvalidColumnInPartitionError
- type InvalidColumnReferencedInViewError
- type InvalidReferencedColumnInForeignKeyConstraintError
- type InvalidStarExprInViewError
- type MigrationTablesAnalysis
- type MissingForeignKeyReferencedIndexError
- type MissingPartitionColumnInUniqueKeyError
- type ModifyColumnDiff
- type NonDeterministicDefaultError
- type NotFullyParsedError
- type PartitionSpecNonExclusiveError
- type RenameTableEntityDiff
- func (d *RenameTableEntityDiff) Annotated() (from *TextualAnnotations, to *TextualAnnotations, unified *TextualAnnotations)
- func (d *RenameTableEntityDiff) CanonicalStatementString() string
- func (d *RenameTableEntityDiff) Clone() EntityDiff
- func (d *RenameTableEntityDiff) Entities() (from Entity, to Entity)
- func (d *RenameTableEntityDiff) EntityName() string
- func (d *RenameTableEntityDiff) InstantDDLCapability() InstantDDLCapability
- func (d *RenameTableEntityDiff) IsEmpty() bool
- func (d *RenameTableEntityDiff) RenameTable() *sqlparser.RenameTable
- func (d *RenameTableEntityDiff) SetSubsequentDiff(EntityDiff)
- func (d *RenameTableEntityDiff) Statement() sqlparser.Statement
- func (d *RenameTableEntityDiff) StatementString() (s string)
- func (d *RenameTableEntityDiff) SubsequentDiff() EntityDiff
- type Schema
- func NewSchemaFromEntities(env *Environment, entities []Entity) (*Schema, error)
- func NewSchemaFromQueries(env *Environment, queries []string) (*Schema, error)
- func NewSchemaFromSQL(env *Environment, sql string) (*Schema, error)
- func NewSchemaFromStatements(env *Environment, statements []sqlparser.Statement) (*Schema, error)
- func (s *Schema) Apply(diffs []EntityDiff) (*Schema, error)
- func (s *Schema) Entities() []Entity
- func (s *Schema) Entity(name string) Entity
- func (s *Schema) EntityNames() []string
- func (s *Schema) SchemaDiff(other *Schema, hints *DiffHints) (*SchemaDiff, error)
- func (s *Schema) Table(name string) *CreateTableEntity
- func (s *Schema) TableNames() []string
- func (s *Schema) Tables() []*CreateTableEntity
- func (s *Schema) ToQueries() []string
- func (s *Schema) ToSQL() string
- func (s *Schema) ToStatements() []sqlparser.Statement
- func (s *Schema) ValidateViewReferences() error
- func (s *Schema) View(name string) *CreateViewEntity
- func (s *Schema) ViewNames() []string
- func (s *Schema) Views() []*CreateViewEntity
- type SchemaDiff
- func (d *SchemaDiff) AllDependenciess() (deps []*DiffDependency)
- func (d *SchemaDiff) AllSequentialExecutionDependencies() (deps []*DiffDependency)
- func (d *SchemaDiff) Empty() bool
- func (d *SchemaDiff) HasDependencies() bool
- func (d *SchemaDiff) HasSequentialExecutionDependencies() bool
- func (d *SchemaDiff) InstantDDLCapability() InstantDDLCapability
- func (d *SchemaDiff) OrderedDiffs(ctx context.Context) ([]EntityDiff, error)
- func (d *SchemaDiff) UnorderedDiffs() []EntityDiff
- type SubsequentDiffRejectedError
- type TextualAnnotationType
- type TextualAnnotations
- func (a *TextualAnnotations) Added() (r []*AnnotatedText)
- func (a *TextualAnnotations) ByType(typ TextualAnnotationType) (r []*AnnotatedText)
- func (a *TextualAnnotations) Export() string
- func (a *TextualAnnotations) Len() int
- func (a *TextualAnnotations) MarkAdded(text string)
- func (a *TextualAnnotations) MarkRemoved(text string)
- func (a *TextualAnnotations) MarkUnchanged(text string)
- func (a *TextualAnnotations) Removed() (r []*AnnotatedText)
- type UnknownColumnCharsetCollationError
- type UnknownColumnCollationCharsetError
- type UnsupportedApplyOperationError
- type UnsupportedEntityError
- type UnsupportedStatementError
- type UnsupportedTableOptionError
- type ViewDependencyUnresolvedError
Constants ¶
const ( AutoIncrementIgnore int = iota AutoIncrementApplyHigher AutoIncrementApplyAlways )
const ( RangeRotationFullSpec = iota RangeRotationDistinctStatements RangeRotationIgnore )
const ( ConstraintNamesIgnoreVitess = iota ConstraintNamesIgnoreAll ConstraintNamesStrict )
const ( ColumnRenameAssumeDifferent = iota ColumnRenameHeuristicStatement )
const ( TableRenameAssumeDifferent = iota TableRenameHeuristicStatement )
const ( FullTextKeyDistinctStatements = iota FullTextKeyUnifyStatements )
const ( TableCharsetCollateStrict int = iota TableCharsetCollateIgnoreEmpty TableCharsetCollateIgnoreAlways )
const ( TableQualifierDefault int = iota TableQualifierDeclared )
const ( AlterTableAlgorithmStrategyNone int = iota AlterTableAlgorithmStrategyInstant AlterTableAlgorithmStrategyInplace AlterTableAlgorithmStrategyCopy )
const ( EnumReorderStrategyAllow int = iota EnumReorderStrategyReject )
const ( ForeignKeyCheckStrategyStrict int = iota ForeignKeyCheckStrategyCreateTableFirst ForeignKeyCheckStrategyIgnore )
const ( SubsequentDiffStrategyAllow int = iota SubsequentDiffStrategyReject )
const ( ApplyDiffsNoConstraint = "ApplyDiffsNoConstraint" ApplyDiffsInOrder = "ApplyDiffsInOrder" ApplyDiffsSequential = "ApplyDiffsSequential" )
Variables ¶
var ( ErrEntityTypeMismatch = errors.New("mismatched entity type") ErrStrictIndexOrderingUnsupported = errors.New("strict index ordering is unsupported") ErrUnexpectedDiffAction = errors.New("unexpected diff action") ErrUnexpectedTableSpec = errors.New("unexpected table spec") ErrExpectedCreateTable = errors.New("expected a CREATE TABLE statement") ErrExpectedCreateView = errors.New("expected a CREATE VIEW statement") )
var (
ErrForeignKeyFound = errors.New("Foreign key found")
)
Functions ¶
func AddInstantAlgorithm ¶ added in v0.21.0
func AddInstantAlgorithm(alterTable *sqlparser.AlterTable)
AddInstantAlgorithm adds or modifies the AlterTable's ALGORITHM to INSTANT
func AlterTableCapableOfInstantDDL ¶ added in v0.19.0
func AlterTableCapableOfInstantDDL(alterTable *sqlparser.AlterTable, createTable *sqlparser.CreateTable, capableOf capabilities.CapableOf) (bool, error)
AlterTableCapableOfInstantDDL checks if the specific ALTER TABLE is eligible to run via ALGORITHM=INSTANT, given the existing table schema and the MySQL server capabilities. The function is intentionally public, as it is intended to be used by other packages, such as onlineddl.
func AlterTableRotatesRangePartition ¶ added in v0.20.0
func AlterTableRotatesRangePartition(createTable *sqlparser.CreateTable, alterTable *sqlparser.AlterTable) (bool, error)
AlterTableRotatesRangePartition answers `true` when the given ALTER TABLE statement performs any sort of range partition rotation, that is applicable immediately and without moving data. Such would be: - Dropping any partition(s) - Adding a new partition (empty, at the end of the list)
func AnalyzeSharedColumns ¶ added in v0.21.0
func AnalyzeSharedColumns( sourceColumns, targetColumns *ColumnDefinitionEntityList, alterTableAnalysis *AlterTableAnalysis, ) ( sourceSharedColumns *ColumnDefinitionEntityList, targetSharedColumns *ColumnDefinitionEntityList, droppedSourceNonGeneratedColumns *ColumnDefinitionEntityList, sharedColumnsMap map[string]string, )
AnalyzeSharedColumns returns the intersection of two lists of columns in same order as the first list
func BlobTypeStorage ¶ added in v0.21.0
func ColumnChangeExpandsDataRange ¶ added in v0.21.0
func ColumnChangeExpandsDataRange(source *ColumnDefinitionEntity, target *ColumnDefinitionEntity) (bool, string)
ColumnChangeExpandsDataRange sees if target column has any value set/range that is impossible in source column.
func DDLActionStr ¶
func DDLActionStr(diff EntityDiff) (string, error)
DDLActionStr returns the action implied by the given diff: CREATE", "DROP", "ALTER" or empty
func DuplicateCreateTable ¶ added in v0.21.0
func DuplicateCreateTable(originalCreateTable *sqlparser.CreateTable, baseUUID string, newTableName string, allowForeignKeys bool) ( newCreateTable *sqlparser.CreateTable, constraintMap map[string]string, err error, )
DuplicateCreateTable parses the given `CREATE TABLE` statement, and returns: - The format CreateTable AST - A new CreateTable AST, with the table renamed as `newTableName`, and with constraints renamed deterministically - Map of renamed constraints
func ExtractConstraintOriginalName ¶
ExtractConstraintOriginalName extracts what used to be the constraint name before schemadiff/vitess generated a replacement name. e.g. input: "check1_7no794p1x6zw6je1gfqmt7bca", output: "check1"
func FloatingPointTypeStorage ¶ added in v0.21.0
func IntegralTypeStorage ¶ added in v0.21.0
func IsDecimalType ¶ added in v0.21.0
func IsExpandingDataType ¶ added in v0.21.0
func IsFloatingPointType ¶ added in v0.21.0
func IsGeneratedColumn ¶ added in v0.21.0
func IsGeneratedColumn(col *sqlparser.ColumnDefinition) (bool, sqlparser.ColumnStorage)
IsGenerated returns true when this column is generated, and indicates the storage type (virtual/stored)
func IsIntegralType ¶ added in v0.16.0
func IsValidIterationKey ¶ added in v0.21.0
func IsValidIterationKey(key *IndexDefinitionEntity) bool
IsValidIterationKey returns true if the key is eligible for Online DDL iteration.
func KeyAtLeastConstrainedAs ¶ added in v0.21.0
func KeyAtLeastConstrainedAs( sourceUniqueKey *IndexDefinitionEntity, targetUniqueKey *IndexDefinitionEntity, columnRenameMap map[string]string, ) bool
KeyAtLeastConstrainedAs 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 MappedColumnNames ¶ added in v0.21.0
func MappedColumnNames(columnsList *ColumnDefinitionEntityList, columnNamesMap map[string]string) []string
MappedColumnNames
func RemovedForeignKeyNames ¶ added in v0.21.0
func RemovedForeignKeyNames(source *CreateTableEntity, target *CreateTableEntity) (names []string, err error)
RemovedForeignKeyNames returns the names of removed foreign keys, ignoring mere name changes
func ValidateAndEditAlterTableStatement ¶ added in v0.21.0
func ValidateAndEditAlterTableStatement(originalTableName string, baseUUID string, capableOf capabilities.CapableOf, alterTable *sqlparser.AlterTable, constraintMap map[string]string) (alters []*sqlparser.AlterTable, err error)
ValidateAndEditAlterTableStatement inspects the AlterTable statement and: - modifies any CONSTRAINT name according to given name mapping - explode ADD FULLTEXT KEY into multiple statements
func ValidateAndEditCreateTableStatement ¶ added in v0.21.0
func ValidateAndEditCreateTableStatement(originalTableName string, baseUUID string, createTable *sqlparser.CreateTable, allowForeignKeys bool) (constraintMap map[string]string, err error)
ValidateAndEditCreateTableStatement inspects the CreateTable AST and does the following: - extra validation (no FKs for now...) - generate new and unique names for all constraints (CHECK and FK; yes, why not handle FK names; even as we don't support FKs today, we may in the future)
Types ¶
type AlterTableAnalysis ¶ added in v0.21.0
type AlterTableAnalysis struct { ColumnRenameMap map[string]string DroppedColumnsMap map[string]bool IsRenameTable bool IsAutoIncrementChangeRequested bool }
AlterTableAnalysis contains useful Online DDL information about an AlterTable statement
func OnlineDDLAlterTableAnalysis ¶ added in v0.21.0
func OnlineDDLAlterTableAnalysis(alterTable *sqlparser.AlterTable) *AlterTableAnalysis
AnalyzeAlter looks for specific changes in the AlterTable statement, that are relevant to OnlineDDL/VReplication
type AlterTableEntityDiff ¶
type AlterTableEntityDiff struct {
// contains filtered or unexported fields
}
func (*AlterTableEntityDiff) AlterTable ¶
func (d *AlterTableEntityDiff) AlterTable() *sqlparser.AlterTable
AlterTable returns the underlying sqlparser.AlterTable that was generated for the diff.
func (*AlterTableEntityDiff) Annotated ¶ added in v0.20.0
func (d *AlterTableEntityDiff) Annotated() (from *TextualAnnotations, to *TextualAnnotations, unified *TextualAnnotations)
func (*AlterTableEntityDiff) CanonicalStatementString ¶
func (d *AlterTableEntityDiff) CanonicalStatementString() string
CanonicalStatementString implements EntityDiff
func (*AlterTableEntityDiff) Clone ¶ added in v0.20.0
func (d *AlterTableEntityDiff) Clone() EntityDiff
Clone implements EntityDiff
func (*AlterTableEntityDiff) Entities ¶
func (d *AlterTableEntityDiff) Entities() (from Entity, to Entity)
Entities implements EntityDiff
func (*AlterTableEntityDiff) EntityName ¶ added in v0.17.0
func (d *AlterTableEntityDiff) EntityName() string
EntityName implements EntityDiff
func (*AlterTableEntityDiff) InstantDDLCapability ¶ added in v0.19.0
func (d *AlterTableEntityDiff) InstantDDLCapability() InstantDDLCapability
InstantDDLCapability implements EntityDiff
func (*AlterTableEntityDiff) IsEmpty ¶
func (d *AlterTableEntityDiff) IsEmpty() bool
IsEmpty implements EntityDiff
func (*AlterTableEntityDiff) SetSubsequentDiff ¶
func (d *AlterTableEntityDiff) SetSubsequentDiff(subDiff EntityDiff)
SetSubsequentDiff implements EntityDiff
func (*AlterTableEntityDiff) Statement ¶
func (d *AlterTableEntityDiff) Statement() sqlparser.Statement
Statement implements EntityDiff
func (*AlterTableEntityDiff) StatementString ¶
func (d *AlterTableEntityDiff) StatementString() (s string)
StatementString implements EntityDiff
func (*AlterTableEntityDiff) SubsequentDiff ¶
func (d *AlterTableEntityDiff) SubsequentDiff() EntityDiff
SubsequentDiff implements EntityDiff
type AlterViewEntityDiff ¶
type AlterViewEntityDiff struct {
// contains filtered or unexported fields
}
func (*AlterViewEntityDiff) AlterView ¶
func (d *AlterViewEntityDiff) AlterView() *sqlparser.AlterView
AlterView returns the underlying sqlparser.AlterView that was generated for the diff.
func (*AlterViewEntityDiff) Annotated ¶ added in v0.20.0
func (d *AlterViewEntityDiff) Annotated() (from *TextualAnnotations, to *TextualAnnotations, unified *TextualAnnotations)
func (*AlterViewEntityDiff) CanonicalStatementString ¶
func (d *AlterViewEntityDiff) CanonicalStatementString() string
CanonicalStatementString implements EntityDiff
func (*AlterViewEntityDiff) Clone ¶ added in v0.20.0
func (d *AlterViewEntityDiff) Clone() EntityDiff
Clone implements EntityDiff
func (*AlterViewEntityDiff) Entities ¶
func (d *AlterViewEntityDiff) Entities() (from Entity, to Entity)
Entities implements EntityDiff
func (*AlterViewEntityDiff) EntityName ¶ added in v0.17.0
func (d *AlterViewEntityDiff) EntityName() string
EntityName implements EntityDiff
func (*AlterViewEntityDiff) InstantDDLCapability ¶ added in v0.19.0
func (d *AlterViewEntityDiff) InstantDDLCapability() InstantDDLCapability
InstantDDLCapability implements EntityDiff
func (*AlterViewEntityDiff) IsEmpty ¶
func (d *AlterViewEntityDiff) IsEmpty() bool
IsEmpty implements EntityDiff
func (*AlterViewEntityDiff) SetSubsequentDiff ¶
func (d *AlterViewEntityDiff) SetSubsequentDiff(EntityDiff)
SetSubsequentDiff implements EntityDiff
func (*AlterViewEntityDiff) Statement ¶
func (d *AlterViewEntityDiff) Statement() sqlparser.Statement
Statement implements EntityDiff
func (*AlterViewEntityDiff) StatementString ¶
func (d *AlterViewEntityDiff) StatementString() (s string)
StatementString implements EntityDiff
func (*AlterViewEntityDiff) SubsequentDiff ¶
func (d *AlterViewEntityDiff) SubsequentDiff() EntityDiff
SubsequentDiff implements EntityDiff
type AnnotatedText ¶ added in v0.20.0
type AnnotatedText struct {
// contains filtered or unexported fields
}
AnnotatedText is a some text and its annotation type. The text is usually single-line, but it can be multi-line, as in the case of partition specs.
type ApplyColumnAfterNotFoundError ¶
func (*ApplyColumnAfterNotFoundError) Error ¶
func (e *ApplyColumnAfterNotFoundError) Error() string
type ApplyColumnNotFoundError ¶
func (*ApplyColumnNotFoundError) Error ¶
func (e *ApplyColumnNotFoundError) Error() string
type ApplyConstraintNotFoundError ¶
func (*ApplyConstraintNotFoundError) Error ¶
func (e *ApplyConstraintNotFoundError) Error() string
type ApplyDuplicateColumnError ¶
func (*ApplyDuplicateColumnError) Error ¶
func (e *ApplyDuplicateColumnError) Error() string
type ApplyDuplicateConstraintError ¶
func (*ApplyDuplicateConstraintError) Error ¶
func (e *ApplyDuplicateConstraintError) Error() string
type ApplyDuplicateEntityError ¶
type ApplyDuplicateEntityError struct {
Entity string
}
func (*ApplyDuplicateEntityError) Error ¶
func (e *ApplyDuplicateEntityError) Error() string
type ApplyDuplicateKeyError ¶
func (*ApplyDuplicateKeyError) Error ¶
func (e *ApplyDuplicateKeyError) Error() string
type ApplyDuplicatePartitionError ¶
func (*ApplyDuplicatePartitionError) Error ¶
func (e *ApplyDuplicatePartitionError) Error() string
type ApplyKeyNotFoundError ¶
func (*ApplyKeyNotFoundError) Error ¶
func (e *ApplyKeyNotFoundError) Error() string
type ApplyNoPartitionsError ¶
type ApplyNoPartitionsError struct {
Table string
}
func (*ApplyNoPartitionsError) Error ¶
func (e *ApplyNoPartitionsError) Error() string
type ApplyPartitionNotFoundError ¶
func (*ApplyPartitionNotFoundError) Error ¶
func (e *ApplyPartitionNotFoundError) Error() string
type ApplyTableNotFoundError ¶
type ApplyTableNotFoundError struct {
Table string
}
func (*ApplyTableNotFoundError) Error ¶
func (e *ApplyTableNotFoundError) Error() string
type ApplyViewNotFoundError ¶
type ApplyViewNotFoundError struct {
View string
}
func (*ApplyViewNotFoundError) Error ¶
func (e *ApplyViewNotFoundError) Error() string
type ColumnDefinitionEntity ¶
type ColumnDefinitionEntity struct { ColumnDefinition *sqlparser.ColumnDefinition Env *Environment // contains filtered or unexported fields }
func NewColumnDefinitionEntity ¶
func NewColumnDefinitionEntity(env *Environment, c *sqlparser.ColumnDefinition, inPK bool, tableCharsetCollate *charsetCollate) *ColumnDefinitionEntity
func (*ColumnDefinitionEntity) Charset ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) Charset() string
Charset returns the column's charset
func (*ColumnDefinitionEntity) Clone ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) Clone() *ColumnDefinitionEntity
func (*ColumnDefinitionEntity) Collate ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) Collate() string
Collate returns the column's collation
func (*ColumnDefinitionEntity) ColumnDiff ¶
func (c *ColumnDefinitionEntity) ColumnDiff( env *Environment, tableName string, other *ColumnDefinitionEntity, hints *DiffHints, ) (*ModifyColumnDiff, error)
ColumnDiff compares this table statement with another table statement, and sees what it takes to change this table to look like the other table. It returns an ModifyColumnDiff statement if changes are found, or nil if not. The function also requires the charset/collate on the source & target tables. This is because the column's charset & collation, if undefined, are really defined by the table's charset & collation.
Anecdotally, in CreateTableEntity.normalize() we actually actively strip away the charset/collate properties from the column definition, to get a cleaner table definition.
Things get complicated when we consider hints.TableCharsetCollateStrategy. Consider this test case:
from: "create table t (a varchar(64)) default charset=latin1", to: "create table t (a varchar(64) CHARACTER SET latin1 COLLATE latin1_bin)",
In both cases, the column is really a latin1. But the tables themselves have different collations. We need to denormalize the column's charset/collate properties, so that the comparison can be done.
func (*ColumnDefinitionEntity) EnumOrdinalValues ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) EnumOrdinalValues() map[int]string
EnumOrdinalValues returns a map of enum ordinals to their values
func (*ColumnDefinitionEntity) EnumValues ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) EnumValues() []string
func (*ColumnDefinitionEntity) EnumValuesOrdinals ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) EnumValuesOrdinals() map[string]int
EnumValuesOrdinals returns a map of enum values to their ordinals
func (*ColumnDefinitionEntity) HasBlobTypeStorage ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) HasBlobTypeStorage() bool
HasBlobTypeStorage returns true when this column is a text/blob type
func (*ColumnDefinitionEntity) HasDefault ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) HasDefault() bool
IsDefaultNull returns true when this column has DEFAULT NULL
func (*ColumnDefinitionEntity) HasEnumValues ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) HasEnumValues() bool
func (*ColumnDefinitionEntity) IsAutoIncrement ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) IsAutoIncrement() bool
IsAutoIncrement returns true when this column is AUTO_INCREMENT
func (*ColumnDefinitionEntity) IsDecimalType ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) IsDecimalType() bool
IsDecimalType returns true when this column is a decimal type
func (*ColumnDefinitionEntity) IsDefaultNull ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) IsDefaultNull() bool
IsDefaultNull returns true when this column has DEFAULT NULL
func (*ColumnDefinitionEntity) IsFloatingPointType ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) IsFloatingPointType() bool
IsFloatingPointType returns true when this column is a floating point type
func (*ColumnDefinitionEntity) IsGenerated ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) IsGenerated() bool
IsGenerated returns true when this column is generated, and indicates the storage type (virtual/stored)
func (*ColumnDefinitionEntity) IsIntegralType ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) IsIntegralType() bool
IsNumeric returns true when this column is a numeric type
func (*ColumnDefinitionEntity) IsNullable ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) IsNullable() bool
IsNullable returns true when this column is NULLable
func (*ColumnDefinitionEntity) IsTextual ¶
func (c *ColumnDefinitionEntity) IsTextual() bool
IsTextual returns true when this column is of textual type, and is capable of having a character set property
func (*ColumnDefinitionEntity) IsUnsigned ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) IsUnsigned() bool
IsUnsigned returns true when this column is UNSIGNED
func (*ColumnDefinitionEntity) Length ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) Length() int
Length returns the type length (e.g. 17 for VARCHAR(17), 10 for DECIMAL(10,2), 6 for TIMESTAMP(6), etc.)
func (*ColumnDefinitionEntity) Name ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) Name() string
func (*ColumnDefinitionEntity) NameLowered ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) NameLowered() string
func (*ColumnDefinitionEntity) Scale ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) Scale() int
Scale returns the type scale (e.g. 2 for DECIMAL(10,2))
func (*ColumnDefinitionEntity) SetExplicitCharsetCollate ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) SetExplicitCharsetCollate() error
SetExplicitCharsetCollate enriches this column definition with collation and charset. Those may be already present, or perhaps just one of them is present (in which case we use the one to populate the other), or both might be missing, in which case we use the table's charset/collation. Normally in schemadiff we work the opposite way: we strive to have the minimal equivalent representation of a definition. But this function can be used (often in conjunction with Clone()) to enrich a column definition so as to have explicit and authoritative view on any particular column.
func (*ColumnDefinitionEntity) SetExplicitDefaultAndNull ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) SetExplicitDefaultAndNull()
SetExplicitDefaultAndNull sets: - NOT NULL, if the columns is part of the PRIMARY KEY - DEFAULT NULL, if the columns is NULLable and no DEFAULT was mentioned Normally in schemadiff we work the opposite way: we strive to have the minimal equivalent representation of a definition. But this function can be used (often in conjunction with Clone()) to enrich a column definition so as to have explicit and authoritative view on any particular column.
func (*ColumnDefinitionEntity) Type ¶ added in v0.21.0
func (c *ColumnDefinitionEntity) Type() string
Type returns the column's type
type ColumnDefinitionEntityList ¶ added in v0.21.0
type ColumnDefinitionEntityList struct { Entities []*ColumnDefinitionEntity // contains filtered or unexported fields }
ColumnDefinitionEntityList is a formalized list of ColumnDefinitionEntity, with some utility functions.
func GetExpandedColumns ¶ added in v0.21.0
func GetExpandedColumns( sourceColumns *ColumnDefinitionEntityList, targetColumns *ColumnDefinitionEntityList, ) ( expandedColumns *ColumnDefinitionEntityList, expandedDescriptions map[string]string, err error, )
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 NewColumnDefinitionEntityList ¶ added in v0.21.0
func NewColumnDefinitionEntityList(entities []*ColumnDefinitionEntity) *ColumnDefinitionEntityList
func (*ColumnDefinitionEntityList) Clone ¶ added in v0.21.0
func (l *ColumnDefinitionEntityList) Clone() *ColumnDefinitionEntityList
Clone creates a copy of this list, with copies of the entities
func (*ColumnDefinitionEntityList) Contains ¶ added in v0.21.0
func (l *ColumnDefinitionEntityList) Contains(other *ColumnDefinitionEntityList) bool
Contains returns true when this list contains all the entities from the other list
func (*ColumnDefinitionEntityList) Filter ¶ added in v0.21.0
func (l *ColumnDefinitionEntityList) Filter(include func(entity *ColumnDefinitionEntity) bool) *ColumnDefinitionEntityList
Filter returns a new subset ColumnDefinitionEntityList with only the entities that pass the filter
func (*ColumnDefinitionEntityList) GetColumn ¶ added in v0.21.0
func (l *ColumnDefinitionEntityList) GetColumn(name string) *ColumnDefinitionEntity
GetColumn returns the column with the given name, or nil if not found
func (*ColumnDefinitionEntityList) Len ¶ added in v0.21.0
func (l *ColumnDefinitionEntityList) Len() int
func (*ColumnDefinitionEntityList) Names ¶ added in v0.21.0
func (l *ColumnDefinitionEntityList) Names() []string
Names returns the names of all the columns in this list
func (*ColumnDefinitionEntityList) Union ¶ added in v0.21.0
func (l *ColumnDefinitionEntityList) Union(other *ColumnDefinitionEntityList) *ColumnDefinitionEntityList
Union returns a new ColumnDefinitionEntityList with all the entities from this list and the other list
type ConstraintType ¶ added in v0.21.0
type ConstraintType int
const ( UnknownConstraintType ConstraintType = iota CheckConstraintType ForeignKeyConstraintType )
func GetConstraintType ¶ added in v0.21.0
func GetConstraintType(constraintInfo sqlparser.ConstraintInfo) ConstraintType
type CreateTableEntity ¶
type CreateTableEntity struct { *sqlparser.CreateTable Env *Environment }
CreateTableEntity stands for a TABLE construct. It contains the table's CREATE statement.
func NewCreateTableEntity ¶
func NewCreateTableEntity(env *Environment, c *sqlparser.CreateTable) (*CreateTableEntity, error)
func NewCreateTableEntityFromSQL ¶ added in v0.21.0
func NewCreateTableEntityFromSQL(env *Environment, sql string) (*CreateTableEntity, error)
func (*CreateTableEntity) Apply ¶
func (c *CreateTableEntity) Apply(diff EntityDiff) (Entity, error)
Apply attempts to apply given ALTER TABLE diff onto the table defined by this entity. This entity is unmodified. If successful, a new CREATE TABLE entity is returned.
func (*CreateTableEntity) AutoIncrementValue ¶ added in v0.21.0
func (c *CreateTableEntity) AutoIncrementValue() (autoIncrement uint64, err error)
AutoIncrementValue returns the value of the AUTO_INCREMENT option, or zero if not exists.
func (*CreateTableEntity) Clone ¶ added in v0.15.0
func (c *CreateTableEntity) Clone() Entity
func (*CreateTableEntity) ColumnDefinitionEntities ¶ added in v0.21.0
func (c *CreateTableEntity) ColumnDefinitionEntities() []*ColumnDefinitionEntity
ColumnDefinitionEntities returns the list of column entities for the table.
func (*CreateTableEntity) ColumnDefinitionEntitiesList ¶ added in v0.21.0
func (c *CreateTableEntity) ColumnDefinitionEntitiesList() *ColumnDefinitionEntityList
ColumnDefinitionEntities returns the list of column entities for the table.
func (*CreateTableEntity) ColumnDefinitionEntitiesMap ¶ added in v0.21.0
func (c *CreateTableEntity) ColumnDefinitionEntitiesMap() map[string]*ColumnDefinitionEntity
ColumnDefinitionEntities returns column entities mapped by their lower cased name
func (*CreateTableEntity) Create ¶
func (c *CreateTableEntity) Create() EntityDiff
Create implements Entity interface
func (*CreateTableEntity) Diff ¶
func (c *CreateTableEntity) Diff(other Entity, hints *DiffHints) (EntityDiff, error)
Diff implements Entity interface function
func (*CreateTableEntity) Drop ¶
func (c *CreateTableEntity) Drop() EntityDiff
Drop implements Entity interface
func (*CreateTableEntity) GetCharset ¶ added in v0.17.0
func (c *CreateTableEntity) GetCharset() string
GetCharset returns the explicit character set name specified in the CREATE TABLE statement (if any).
func (*CreateTableEntity) GetCollation ¶ added in v0.17.0
func (c *CreateTableEntity) GetCollation() string
GetCollation returns the explicit collation name specified in the CREATE TABLE statement (if any).
func (*CreateTableEntity) IndexDefinitionEntities ¶ added in v0.21.0
func (c *CreateTableEntity) IndexDefinitionEntities() []*IndexDefinitionEntity
IndexDefinitionEntities returns the list of index entities for the table.
func (*CreateTableEntity) IndexDefinitionEntitiesList ¶ added in v0.21.0
func (c *CreateTableEntity) IndexDefinitionEntitiesList() *IndexDefinitionEntityList
IndexDefinitionEntityList returns the list of index entities for the table.
func (*CreateTableEntity) IndexDefinitionEntitiesMap ¶ added in v0.21.0
func (c *CreateTableEntity) IndexDefinitionEntitiesMap() map[string]*IndexDefinitionEntity
IndexDefinitionEntitiesMap returns index entities mapped by their lower cased name.
func (*CreateTableEntity) Name ¶
func (c *CreateTableEntity) Name() string
Name implements Entity interface
func (*CreateTableEntity) TableDiff ¶
func (c *CreateTableEntity) TableDiff(other *CreateTableEntity, hints *DiffHints) (*AlterTableEntityDiff, error)
TableDiff compares this table statement with another table statement, and sees what it takes to change this table to look like the other table. It returns an AlterTable statement if changes are found, or nil if not. the other table may be of different name; its name is ignored.
type CreateTableEntityDiff ¶
type CreateTableEntityDiff struct {
// contains filtered or unexported fields
}
func (*CreateTableEntityDiff) Annotated ¶ added in v0.20.0
func (d *CreateTableEntityDiff) Annotated() (from *TextualAnnotations, to *TextualAnnotations, unified *TextualAnnotations)
func (*CreateTableEntityDiff) CanonicalStatementString ¶
func (d *CreateTableEntityDiff) CanonicalStatementString() string
CanonicalStatementString implements EntityDiff
func (*CreateTableEntityDiff) Clone ¶ added in v0.20.0
func (d *CreateTableEntityDiff) Clone() EntityDiff
Clone implements EntityDiff
func (*CreateTableEntityDiff) CreateTable ¶
func (d *CreateTableEntityDiff) CreateTable() *sqlparser.CreateTable
CreateTable returns the underlying sqlparser.CreateTable that was generated for the diff.
func (*CreateTableEntityDiff) Entities ¶
func (d *CreateTableEntityDiff) Entities() (from Entity, to Entity)
Entities implements EntityDiff
func (*CreateTableEntityDiff) EntityName ¶ added in v0.17.0
func (d *CreateTableEntityDiff) EntityName() string
EntityName implements EntityDiff
func (*CreateTableEntityDiff) InstantDDLCapability ¶ added in v0.19.0
func (d *CreateTableEntityDiff) InstantDDLCapability() InstantDDLCapability
InstantDDLCapability implements EntityDiff
func (*CreateTableEntityDiff) IsEmpty ¶
func (d *CreateTableEntityDiff) IsEmpty() bool
IsEmpty implements EntityDiff
func (*CreateTableEntityDiff) SetSubsequentDiff ¶
func (d *CreateTableEntityDiff) SetSubsequentDiff(EntityDiff)
SetSubsequentDiff implements EntityDiff
func (*CreateTableEntityDiff) Statement ¶
func (d *CreateTableEntityDiff) Statement() sqlparser.Statement
Statement implements EntityDiff
func (*CreateTableEntityDiff) StatementString ¶
func (d *CreateTableEntityDiff) StatementString() (s string)
StatementString implements EntityDiff
func (*CreateTableEntityDiff) SubsequentDiff ¶
func (d *CreateTableEntityDiff) SubsequentDiff() EntityDiff
SubsequentDiff implements EntityDiff
type CreateViewEntity ¶
type CreateViewEntity struct { *sqlparser.CreateView // contains filtered or unexported fields }
CreateViewEntity stands for a VIEW construct. It contains the view's CREATE statement.
func NewCreateViewEntity ¶
func NewCreateViewEntity(env *Environment, c *sqlparser.CreateView) (*CreateViewEntity, error)
func NewCreateViewEntityFromSQL ¶ added in v0.21.0
func NewCreateViewEntityFromSQL(env *Environment, sql string) (*CreateViewEntity, error)
func (*CreateViewEntity) Apply ¶
func (c *CreateViewEntity) Apply(diff EntityDiff) (Entity, error)
Apply attempts to apply given ALTER VIEW diff onto the view defined by this entity. This entity is unmodified. If successful, a new CREATE VIEW entity is returned.
func (*CreateViewEntity) Clone ¶ added in v0.15.0
func (c *CreateViewEntity) Clone() Entity
func (*CreateViewEntity) Create ¶
func (c *CreateViewEntity) Create() EntityDiff
Create implements Entity interface
func (*CreateViewEntity) Diff ¶
func (c *CreateViewEntity) Diff(other Entity, hints *DiffHints) (EntityDiff, error)
Diff implements Entity interface function
func (*CreateViewEntity) Drop ¶
func (c *CreateViewEntity) Drop() EntityDiff
Drop implements Entity interface
func (*CreateViewEntity) Name ¶
func (c *CreateViewEntity) Name() string
Name implements Entity interface
func (*CreateViewEntity) ViewDiff ¶
func (c *CreateViewEntity) ViewDiff(other *CreateViewEntity, _ *DiffHints) (*AlterViewEntityDiff, error)
ViewDiff compares this view statement with another view statement, and sees what it takes to change this view to look like the other view. It returns an AlterView statement if changes are found, or nil if not. the other view may be of different name; its name is ignored.
type CreateViewEntityDiff ¶
type CreateViewEntityDiff struct {
// contains filtered or unexported fields
}
func (*CreateViewEntityDiff) Annotated ¶ added in v0.20.0
func (d *CreateViewEntityDiff) Annotated() (from *TextualAnnotations, to *TextualAnnotations, unified *TextualAnnotations)
func (*CreateViewEntityDiff) CanonicalStatementString ¶
func (d *CreateViewEntityDiff) CanonicalStatementString() string
CanonicalStatementString implements EntityDiff
func (*CreateViewEntityDiff) Clone ¶ added in v0.20.0
func (d *CreateViewEntityDiff) Clone() EntityDiff
Clone implements EntityDiff
func (*CreateViewEntityDiff) CreateView ¶
func (d *CreateViewEntityDiff) CreateView() *sqlparser.CreateView
CreateView returns the underlying sqlparser.CreateView that was generated for the diff.
func (*CreateViewEntityDiff) Entities ¶
func (d *CreateViewEntityDiff) Entities() (from Entity, to Entity)
Entities implements EntityDiff
func (*CreateViewEntityDiff) EntityName ¶ added in v0.17.0
func (d *CreateViewEntityDiff) EntityName() string
EntityName implements EntityDiff
func (*CreateViewEntityDiff) InstantDDLCapability ¶ added in v0.19.0
func (d *CreateViewEntityDiff) InstantDDLCapability() InstantDDLCapability
InstantDDLCapability implements EntityDiff
func (*CreateViewEntityDiff) IsEmpty ¶
func (d *CreateViewEntityDiff) IsEmpty() bool
IsEmpty implements EntityDiff
func (*CreateViewEntityDiff) SetSubsequentDiff ¶
func (d *CreateViewEntityDiff) SetSubsequentDiff(EntityDiff)
SetSubsequentDiff implements EntityDiff
func (*CreateViewEntityDiff) Statement ¶
func (d *CreateViewEntityDiff) Statement() sqlparser.Statement
Statement implements EntityDiff
func (*CreateViewEntityDiff) StatementString ¶
func (d *CreateViewEntityDiff) StatementString() (s string)
StatementString implements EntityDiff
func (*CreateViewEntityDiff) SubsequentDiff ¶
func (d *CreateViewEntityDiff) SubsequentDiff() EntityDiff
SubsequentDiff implements EntityDiff
type DiffDependency ¶ added in v0.17.0
type DiffDependency struct {
// contains filtered or unexported fields
}
DiffDependency indicates a dependency between two diffs, and the type of that dependency
func NewDiffDependency ¶ added in v0.17.0
func NewDiffDependency(diff EntityDiff, dependentDiff EntityDiff, typ DiffDependencyType) *DiffDependency
NewDiffDependency returns a new diff dependency pairing.
func (*DiffDependency) DependentDiff ¶ added in v0.17.0
func (d *DiffDependency) DependentDiff() EntityDiff
DependentDiff returns the diff that depends on the "benefactor" diff, ie must run 2nd
func (*DiffDependency) Diff ¶ added in v0.17.0
func (d *DiffDependency) Diff() EntityDiff
Diff returns the "benefactor" diff, on which DependentDiff() depends on, ie, should run 1st.
func (*DiffDependency) IsInOrder ¶ added in v0.19.0
func (d *DiffDependency) IsInOrder() bool
IsInOrder returns true if this dependency indicates a known order
func (*DiffDependency) IsSequential ¶ added in v0.19.0
func (d *DiffDependency) IsSequential() bool
IsSequential returns true if this is a sequential dependency
func (*DiffDependency) Type ¶ added in v0.17.0
func (d *DiffDependency) Type() DiffDependencyType
Type returns the dependency type. Types are numeric and comparable: the higher the value, the stricter, or more constrained, the dependency is.
type DiffDependencyType ¶ added in v0.17.0
type DiffDependencyType int
const ( DiffDependencyNone DiffDependencyType = iota // not a dependency DiffDependencyOrderUnknown DiffDependencyInOrderCompletion DiffDependencySequentialExecution )
diff dependencies in increasing restriction severity
type DiffHints ¶
type DiffHints struct { StrictIndexOrdering bool AutoIncrementStrategy int RangeRotationStrategy int ConstraintNamesStrategy int ColumnRenameStrategy int TableRenameStrategy int FullTextKeyStrategy int TableCharsetCollateStrategy int TableQualifierHint int AlterTableAlgorithmStrategy int EnumReorderStrategy int ForeignKeyCheckStrategy int SubsequentDiffStrategy int }
DiffHints is an assortment of rules for diffing entities
func EmptyDiffHints ¶ added in v0.20.0
func EmptyDiffHints() *DiffHints
type DropTableEntityDiff ¶
type DropTableEntityDiff struct {
// contains filtered or unexported fields
}
func (*DropTableEntityDiff) Annotated ¶ added in v0.20.0
func (d *DropTableEntityDiff) Annotated() (from *TextualAnnotations, to *TextualAnnotations, unified *TextualAnnotations)
func (*DropTableEntityDiff) CanonicalStatementString ¶
func (d *DropTableEntityDiff) CanonicalStatementString() string
CanonicalStatementString implements EntityDiff
func (*DropTableEntityDiff) Clone ¶ added in v0.20.0
func (d *DropTableEntityDiff) Clone() EntityDiff
Clone implements EntityDiff
func (*DropTableEntityDiff) DropTable ¶
func (d *DropTableEntityDiff) DropTable() *sqlparser.DropTable
DropTable returns the underlying sqlparser.DropTable that was generated for the diff.
func (*DropTableEntityDiff) Entities ¶
func (d *DropTableEntityDiff) Entities() (from Entity, to Entity)
Entities implements EntityDiff
func (*DropTableEntityDiff) EntityName ¶ added in v0.17.0
func (d *DropTableEntityDiff) EntityName() string
EntityName implements EntityDiff
func (*DropTableEntityDiff) InstantDDLCapability ¶ added in v0.19.0
func (d *DropTableEntityDiff) InstantDDLCapability() InstantDDLCapability
InstantDDLCapability implements EntityDiff
func (*DropTableEntityDiff) IsEmpty ¶
func (d *DropTableEntityDiff) IsEmpty() bool
IsEmpty implements EntityDiff
func (*DropTableEntityDiff) SetSubsequentDiff ¶
func (d *DropTableEntityDiff) SetSubsequentDiff(EntityDiff)
SetSubsequentDiff implements EntityDiff
func (*DropTableEntityDiff) Statement ¶
func (d *DropTableEntityDiff) Statement() sqlparser.Statement
Statement implements EntityDiff
func (*DropTableEntityDiff) StatementString ¶
func (d *DropTableEntityDiff) StatementString() (s string)
StatementString implements EntityDiff
func (*DropTableEntityDiff) SubsequentDiff ¶
func (d *DropTableEntityDiff) SubsequentDiff() EntityDiff
SubsequentDiff implements EntityDiff
type DropViewEntityDiff ¶
type DropViewEntityDiff struct {
// contains filtered or unexported fields
}
func (*DropViewEntityDiff) Annotated ¶ added in v0.20.0
func (d *DropViewEntityDiff) Annotated() (from *TextualAnnotations, to *TextualAnnotations, unified *TextualAnnotations)
func (*DropViewEntityDiff) CanonicalStatementString ¶
func (d *DropViewEntityDiff) CanonicalStatementString() string
CanonicalStatementString implements EntityDiff
func (*DropViewEntityDiff) Clone ¶ added in v0.20.0
func (d *DropViewEntityDiff) Clone() EntityDiff
Clone implements EntityDiff
func (*DropViewEntityDiff) DropView ¶
func (d *DropViewEntityDiff) DropView() *sqlparser.DropView
DropView returns the underlying sqlparser.DropView that was generated for the diff.
func (*DropViewEntityDiff) Entities ¶
func (d *DropViewEntityDiff) Entities() (from Entity, to Entity)
Entities implements EntityDiff
func (*DropViewEntityDiff) EntityName ¶ added in v0.17.0
func (d *DropViewEntityDiff) EntityName() string
EntityName implements EntityDiff
func (*DropViewEntityDiff) InstantDDLCapability ¶ added in v0.19.0
func (d *DropViewEntityDiff) InstantDDLCapability() InstantDDLCapability
InstantDDLCapability implements EntityDiff
func (*DropViewEntityDiff) IsEmpty ¶
func (d *DropViewEntityDiff) IsEmpty() bool
IsEmpty implements EntityDiff
func (*DropViewEntityDiff) SetSubsequentDiff ¶
func (d *DropViewEntityDiff) SetSubsequentDiff(EntityDiff)
SetSubsequentDiff implements EntityDiff
func (*DropViewEntityDiff) Statement ¶
func (d *DropViewEntityDiff) Statement() sqlparser.Statement
Statement implements EntityDiff
func (*DropViewEntityDiff) StatementString ¶
func (d *DropViewEntityDiff) StatementString() (s string)
StatementString implements EntityDiff
func (*DropViewEntityDiff) SubsequentDiff ¶
func (d *DropViewEntityDiff) SubsequentDiff() EntityDiff
SubsequentDiff implements EntityDiff
type DuplicateKeyNameError ¶ added in v0.16.0
func (*DuplicateKeyNameError) Error ¶ added in v0.16.0
func (e *DuplicateKeyNameError) Error() string
type Entity ¶
type Entity interface { // Name of entity, ie table name, view name, etc. Name() string // Diff returns an entitty diff given another entity. The diff direction is from this entity and to the other entity. Diff(other Entity, hints *DiffHints) (diff EntityDiff, err error) // Create returns an entity diff that describes how to create this entity Create() EntityDiff // Drop returns an entity diff that describes how to drop this entity Drop() EntityDiff // Clone returns a deep copy of the entity. Clone() Entity }
Entity stands for a database object we can diff: - A table - A view
type EntityDiff ¶
type EntityDiff interface { // IsEmpty returns true when the two entities are considered identical IsEmpty() bool // EntityName returns the name of affected entity EntityName() string // Entities returns the two diffed entitied, aka "from" and "to" Entities() (from Entity, to Entity) // Statement returns a valid SQL statement that applies the diff, e.g. an ALTER TABLE ... // It returns nil if the diff is empty Statement() sqlparser.Statement // StatementString "stringifies" this diff's Statement(). It returns an empty string if the diff is empty StatementString() string // CanonicalStatementString "stringifies" this diff's Statement() to a canonical string. It returns an empty string if the diff is empty CanonicalStatementString() string // SubsequentDiff returns a followup diff to this one, if exists SubsequentDiff() EntityDiff // SetSubsequentDiff updates the existing subsequent diff to the given one SetSubsequentDiff(EntityDiff) // InstantDDLCapability returns the ability of this diff to run with ALGORITHM=INSTANT InstantDDLCapability() InstantDDLCapability // Clone returns a deep copy of the entity diff, and of all referenced entities. Clone() EntityDiff Annotated() (from *TextualAnnotations, to *TextualAnnotations, unified *TextualAnnotations) }
EntityDiff represents the diff between two entities
func AllSubsequent ¶
func AllSubsequent(diff EntityDiff) (diffs []EntityDiff)
AllSubsequent returns a list of diffs starting the given diff and followed by all subsequent diffs, if any
func AtomicDiffs ¶ added in v0.20.0
func AtomicDiffs(diff EntityDiff) []EntityDiff
AtomicDiffs attempts to break a given diff statement into its smallest components. This isn't necessarily the _correct_ thing to do, as MySQL goes, but it assists in identifying the distinct changes that are being made. Currently, the only implementation is to break up `ALTER TABLE ... DROP PARTITION` statements.
func DiffCreateTablesQueries ¶
func DiffCreateTablesQueries(env *Environment, query1 string, query2 string, hints *DiffHints) (EntityDiff, error)
DiffCreateTablesQueries compares two `CREATE TABLE ...` queries (in string form) and returns the diff from table1 to table2. Either or both of the queries can be empty. Based on this, the diff could be nil, CreateTable, DropTable or AlterTable
func DiffCreateViewsQueries ¶
func DiffCreateViewsQueries(env *Environment, query1 string, query2 string, hints *DiffHints) (EntityDiff, error)
DiffCreateViewsQueries compares two `CREATE TABLE ...` queries (in string form) and returns the diff from table1 to table2. Either or both of the queries can be empty. Based on this, the diff could be nil, CreateView, DropView or AlterView
func DiffTables ¶
func DiffTables(env *Environment, create1 *sqlparser.CreateTable, create2 *sqlparser.CreateTable, hints *DiffHints) (EntityDiff, error)
DiffTables compares two tables and returns the diff from table1 to table2. Either or both of the CreateTable statements can be nil. Based on this, the diff could be nil, CreateTable, DropTable or AlterTable
func DiffViews ¶
func DiffViews(env *Environment, create1 *sqlparser.CreateView, create2 *sqlparser.CreateView, hints *DiffHints) (EntityDiff, error)
DiffViews compares two views and returns the diff from view1 to view2 Either or both of the CreateView statements can be nil. Based on this, the diff could be nil, CreateView, DropView or AlterView
func EntityDiffByStatement ¶ added in v0.20.0
func EntityDiffByStatement(statement sqlparser.Statement) EntityDiff
EntityDiffByStatement is a helper function that returns a simplified and incomplete EntityDiff based on the given SQL statement. It is useful for testing purposes as a quick mean to wrap a statement with a diff.
type EntityNotFoundError ¶ added in v0.17.0
type EntityNotFoundError struct {
Name string
}
func (*EntityNotFoundError) Error ¶ added in v0.17.0
func (e *EntityNotFoundError) Error() string
type EnumValueOrdinalChangedError ¶ added in v0.19.0
type EnumValueOrdinalChangedError struct { Table string Column string Value string Ordinal int NewOrdinal int }
func (*EnumValueOrdinalChangedError) Error ¶ added in v0.19.0
func (e *EnumValueOrdinalChangedError) Error() string
type Environment ¶ added in v0.19.0
type Environment struct { *vtenv.Environment DefaultColl collations.ID }
func NewEnv ¶ added in v0.19.0
func NewEnv(env *vtenv.Environment, defaultColl collations.ID) *Environment
func NewTestEnv ¶ added in v0.19.0
func NewTestEnv() *Environment
type ForeignKeyColumnCountMismatchError ¶ added in v0.16.0
type ForeignKeyColumnCountMismatchError struct { Table string Constraint string ColumnCount int ReferencedTable string ReferencedColumnCount int }
func (*ForeignKeyColumnCountMismatchError) Error ¶ added in v0.16.0
func (e *ForeignKeyColumnCountMismatchError) Error() string
type ForeignKeyColumnTypeMismatchError ¶ added in v0.16.0
type ForeignKeyColumnTypeMismatchError struct { Table string Constraint string Column string ReferencedTable string ReferencedColumn string }
func (*ForeignKeyColumnTypeMismatchError) Error ¶ added in v0.16.0
func (e *ForeignKeyColumnTypeMismatchError) Error() string
type ForeignKeyDependencyUnresolvedError ¶ added in v0.16.0
type ForeignKeyDependencyUnresolvedError struct {
Table string
}
func (*ForeignKeyDependencyUnresolvedError) Error ¶ added in v0.16.0
func (e *ForeignKeyDependencyUnresolvedError) Error() string
type ForeignKeyNonexistentReferencedTableError ¶ added in v0.19.0
func (*ForeignKeyNonexistentReferencedTableError) Error ¶ added in v0.19.0
func (e *ForeignKeyNonexistentReferencedTableError) Error() string
type ForeignKeyReferencesViewError ¶ added in v0.19.0
func (*ForeignKeyReferencesViewError) Error ¶ added in v0.19.0
func (e *ForeignKeyReferencesViewError) Error() string
type ForeignKeyTableColumns ¶ added in v0.20.0
func (ForeignKeyTableColumns) Escaped ¶ added in v0.20.0
func (f ForeignKeyTableColumns) Escaped() string
type ImpossibleApplyDiffOrderError ¶ added in v0.17.0
type ImpossibleApplyDiffOrderError struct { UnorderedDiffs []EntityDiff ConflictingDiffs []EntityDiff }
func (*ImpossibleApplyDiffOrderError) ConflictingStatements ¶ added in v0.17.0
func (e *ImpossibleApplyDiffOrderError) ConflictingStatements() (result []string)
func (*ImpossibleApplyDiffOrderError) Error ¶ added in v0.17.0
func (e *ImpossibleApplyDiffOrderError) Error() string
type IndexDefinitionEntity ¶ added in v0.21.0
type IndexDefinitionEntity struct { IndexDefinition *sqlparser.IndexDefinition ColumnList *ColumnDefinitionEntityList Env *Environment }
IndexDefinitionEntity represents an index definition in a CREATE TABLE statement, and includes the list of columns that are part of the index.
func NewIndexDefinitionEntity ¶ added in v0.21.0
func NewIndexDefinitionEntity(env *Environment, indexDefinition *sqlparser.IndexDefinition, columnDefinitionEntitiesList *ColumnDefinitionEntityList) *IndexDefinitionEntity
func (*IndexDefinitionEntity) Clone ¶ added in v0.21.0
func (i *IndexDefinitionEntity) Clone() *IndexDefinitionEntity
Clone returns a copy of this list, with copies of all the entities.
func (*IndexDefinitionEntity) ColumnNames ¶ added in v0.21.0
func (i *IndexDefinitionEntity) ColumnNames() []string
ColumnNames returns the names of the columns in the index.
func (*IndexDefinitionEntity) ContainsColumns ¶ added in v0.21.0
func (i *IndexDefinitionEntity) ContainsColumns(columns *ColumnDefinitionEntityList) bool
ContainsColumns returns true if the index contains all the columns in the given list.
func (*IndexDefinitionEntity) CoveredByColumns ¶ added in v0.21.0
func (i *IndexDefinitionEntity) CoveredByColumns(columns *ColumnDefinitionEntityList) bool
CoveredByColumns returns true if the index is covered by the given list of columns.
func (*IndexDefinitionEntity) HasColumnPrefix ¶ added in v0.21.0
func (i *IndexDefinitionEntity) HasColumnPrefix() bool
HasColumnPrefix returns true if any of the columns in the index have a length prefix.
func (*IndexDefinitionEntity) HasFloat ¶ added in v0.21.0
func (i *IndexDefinitionEntity) HasFloat() bool
HasFloat returns true if any of the columns in the index are floating point types.
func (*IndexDefinitionEntity) HasNullable ¶ added in v0.21.0
func (i *IndexDefinitionEntity) HasNullable() bool
HasNullable returns true if any of the columns in the index are nullable.
func (*IndexDefinitionEntity) IsPrimary ¶ added in v0.21.0
func (i *IndexDefinitionEntity) IsPrimary() bool
IsPrimary returns true if the index is a primary key.
func (*IndexDefinitionEntity) IsUnique ¶ added in v0.21.0
func (i *IndexDefinitionEntity) IsUnique() bool
IsUnique returns true if the index is a unique key.
func (*IndexDefinitionEntity) Len ¶ added in v0.21.0
func (i *IndexDefinitionEntity) Len() int
func (*IndexDefinitionEntity) Name ¶ added in v0.21.0
func (i *IndexDefinitionEntity) Name() string
func (*IndexDefinitionEntity) NameLowered ¶ added in v0.21.0
func (i *IndexDefinitionEntity) NameLowered() string
type IndexDefinitionEntityList ¶ added in v0.21.0
type IndexDefinitionEntityList struct {
Entities []*IndexDefinitionEntity
}
IndexDefinitionEntityList is a formalized list of IndexDefinitionEntity objects with a few utility methods.
func IntroducedUniqueConstraints ¶ added in v0.21.0
func IntroducedUniqueConstraints(sourceUniqueKeys *IndexDefinitionEntityList, targetUniqueKeys *IndexDefinitionEntityList, columnRenameMap map[string]string) *IndexDefinitionEntityList
IntroducedUniqueConstraints 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 `other_key`(c1, c2) Synopsis: the constraint on (c1, c2) is new; and `other_key` in target table is considered a new key
Order of columns is immaterial to uniqueness of column combination.
func IterationKeysByColumns ¶ added in v0.21.0
func IterationKeysByColumns(keys *IndexDefinitionEntityList, columns *ColumnDefinitionEntityList) *IndexDefinitionEntityList
IterationKeysByColumns returns the Online DDL compliant unique keys from given list, whose columns are all covered by the given column list.
func NewIndexDefinitionEntityList ¶ added in v0.21.0
func NewIndexDefinitionEntityList(entities []*IndexDefinitionEntity) *IndexDefinitionEntityList
func PrioritizedUniqueKeys ¶ added in v0.21.0
func PrioritizedUniqueKeys(createTableEntity *CreateTableEntity) *IndexDefinitionEntityList
PrioritizedUniqueKeys returns all unique keys on given table, ordered from "best" to "worst", for Online DDL purposes. The list of keys includes some that are not eligible for Online DDL iteration.
func RemovedUniqueConstraints ¶ added in v0.21.0
func RemovedUniqueConstraints(sourceUniqueKeys *IndexDefinitionEntityList, targetUniqueKeys *IndexDefinitionEntityList, columnRenameMap map[string]string) *IndexDefinitionEntityList
RemovedUniqueConstraints returns the list of unique key constraints _removed_ going from source to target.
func (*IndexDefinitionEntityList) First ¶ added in v0.21.0
func (l *IndexDefinitionEntityList) First() *IndexDefinitionEntity
First returns the first index in the list, or nil if the list is empty.
func (*IndexDefinitionEntityList) Len ¶ added in v0.21.0
func (l *IndexDefinitionEntityList) Len() int
func (*IndexDefinitionEntityList) Names ¶ added in v0.21.0
func (l *IndexDefinitionEntityList) Names() []string
Names returns the names of the indexes in the list.
func (*IndexDefinitionEntityList) SubsetCoveredByColumns ¶ added in v0.21.0
func (l *IndexDefinitionEntityList) SubsetCoveredByColumns(columns *ColumnDefinitionEntityList) *IndexDefinitionEntityList
SubsetCoveredByColumns returns a new list of indexes that are covered by the given list of columns.
type IndexNeededByForeignKeyError ¶ added in v0.16.0
func (*IndexNeededByForeignKeyError) Error ¶ added in v0.16.0
func (e *IndexNeededByForeignKeyError) Error() string
type InstantDDLCapability ¶ added in v0.19.0
type InstantDDLCapability int
const ( InstantDDLCapabilityUnknown InstantDDLCapability = iota InstantDDLCapabilityIrrelevant InstantDDLCapabilityImpossible InstantDDLCapabilityPossible )
type InvalidColumnInCheckConstraintError ¶
func (*InvalidColumnInCheckConstraintError) Error ¶
func (e *InvalidColumnInCheckConstraintError) Error() string
type InvalidColumnInForeignKeyConstraintError ¶
type InvalidColumnInForeignKeyConstraintError struct { Table string Constraint string Column string }
func (*InvalidColumnInForeignKeyConstraintError) Error ¶
func (e *InvalidColumnInForeignKeyConstraintError) Error() string
type InvalidColumnInGeneratedColumnError ¶
type InvalidColumnInGeneratedColumnError struct { Table string Column string GeneratedColumn string }
func (*InvalidColumnInGeneratedColumnError) Error ¶
func (e *InvalidColumnInGeneratedColumnError) Error() string
type InvalidColumnInKeyError ¶
func (*InvalidColumnInKeyError) Error ¶
func (e *InvalidColumnInKeyError) Error() string
type InvalidColumnInPartitionError ¶
func (*InvalidColumnInPartitionError) Error ¶
func (e *InvalidColumnInPartitionError) Error() string
type InvalidColumnReferencedInViewError ¶ added in v0.17.0
func (*InvalidColumnReferencedInViewError) Error ¶ added in v0.17.0
func (e *InvalidColumnReferencedInViewError) Error() string
type InvalidReferencedColumnInForeignKeyConstraintError ¶ added in v0.16.0
type InvalidReferencedColumnInForeignKeyConstraintError struct { Table string Constraint string ReferencedTable string ReferencedColumn string }
func (*InvalidReferencedColumnInForeignKeyConstraintError) Error ¶ added in v0.16.0
func (e *InvalidReferencedColumnInForeignKeyConstraintError) Error() string
type InvalidStarExprInViewError ¶ added in v0.17.0
type InvalidStarExprInViewError struct {
View string
}
func (*InvalidStarExprInViewError) Error ¶ added in v0.17.0
func (e *InvalidStarExprInViewError) Error() string
type MigrationTablesAnalysis ¶ added in v0.21.0
type MigrationTablesAnalysis struct { DroppedNoDefaultColumns *ColumnDefinitionEntityList ExpandedColumns *ColumnDefinitionEntityList ChosenSourceUniqueKey *IndexDefinitionEntity ChosenTargetUniqueKey *IndexDefinitionEntity AddedUniqueKeys *IndexDefinitionEntityList RemovedUniqueKeys *IndexDefinitionEntityList RemovedForeignKeyNames []string IntToEnumMap map[string]bool SourceAutoIncrement uint64 RevertibleNotes []string }
AlterTableAnalysis contains useful Online DDL information about an AlterTable statement
func OnlineDDLMigrationTablesAnalysis ¶ added in v0.21.0
func OnlineDDLMigrationTablesAnalysis( sourceCreateTableEntity *CreateTableEntity, targetCreateTableEntity *CreateTableEntity, alterTableAnalysis *AlterTableAnalysis, ) (analysis *MigrationTablesAnalysis, err error)
type MissingForeignKeyReferencedIndexError ¶ added in v0.16.0
type MissingForeignKeyReferencedIndexError struct { Table string Constraint string ReferencedTable string }
func (*MissingForeignKeyReferencedIndexError) Error ¶ added in v0.16.0
func (e *MissingForeignKeyReferencedIndexError) Error() string
type MissingPartitionColumnInUniqueKeyError ¶
func (*MissingPartitionColumnInUniqueKeyError) Error ¶
func (e *MissingPartitionColumnInUniqueKeyError) Error() string
type ModifyColumnDiff ¶
type ModifyColumnDiff struct {
// contains filtered or unexported fields
}
func NewModifyColumnDiff ¶
func NewModifyColumnDiff(modifyColumn *sqlparser.ModifyColumn) *ModifyColumnDiff
func NewModifyColumnDiffByDefinition ¶
func NewModifyColumnDiffByDefinition(definition *sqlparser.ColumnDefinition) *ModifyColumnDiff
type NonDeterministicDefaultError ¶ added in v0.21.0
func (*NonDeterministicDefaultError) Error ¶ added in v0.21.0
func (e *NonDeterministicDefaultError) Error() string
type NotFullyParsedError ¶
func (*NotFullyParsedError) Error ¶
func (e *NotFullyParsedError) Error() string
type PartitionSpecNonExclusiveError ¶ added in v0.20.0
type PartitionSpecNonExclusiveError struct { Table string PartitionSpec *sqlparser.PartitionSpec ConflictingStatement string }
PartitionSpecNonExclusiveError is returned when a partition spec change is found alongside other changes. for example, in MySQL it is invalid to both DROP PARTITION (a partition spec change) and ADD COLUMN in the same ALTER TABLE statement. In fact, even two partition spec changes in the same ALTER TABLE statement are not allowed. This error should never be encountered in normal circumstances, because: - `sqlparser` should not allow such statements to be parsed. - schemadiff's `Diff()` function will never generate a single `ALTER TABLE` statement with such multiple changes. The error is used for integrity checks only, and should be considered a bug if encountered.
func (*PartitionSpecNonExclusiveError) Error ¶ added in v0.20.0
func (e *PartitionSpecNonExclusiveError) Error() string
type RenameTableEntityDiff ¶ added in v0.15.0
type RenameTableEntityDiff struct {
// contains filtered or unexported fields
}
func (*RenameTableEntityDiff) Annotated ¶ added in v0.20.0
func (d *RenameTableEntityDiff) Annotated() (from *TextualAnnotations, to *TextualAnnotations, unified *TextualAnnotations)
func (*RenameTableEntityDiff) CanonicalStatementString ¶ added in v0.15.0
func (d *RenameTableEntityDiff) CanonicalStatementString() string
CanonicalStatementString implements EntityDiff
func (*RenameTableEntityDiff) Clone ¶ added in v0.20.0
func (d *RenameTableEntityDiff) Clone() EntityDiff
Clone implements EntityDiff
func (*RenameTableEntityDiff) Entities ¶ added in v0.15.0
func (d *RenameTableEntityDiff) Entities() (from Entity, to Entity)
Entities implements EntityDiff
func (*RenameTableEntityDiff) EntityName ¶ added in v0.17.0
func (d *RenameTableEntityDiff) EntityName() string
EntityName implements EntityDiff
func (*RenameTableEntityDiff) InstantDDLCapability ¶ added in v0.19.0
func (d *RenameTableEntityDiff) InstantDDLCapability() InstantDDLCapability
InstantDDLCapability implements EntityDiff
func (*RenameTableEntityDiff) IsEmpty ¶ added in v0.15.0
func (d *RenameTableEntityDiff) IsEmpty() bool
IsEmpty implements EntityDiff
func (*RenameTableEntityDiff) RenameTable ¶ added in v0.15.0
func (d *RenameTableEntityDiff) RenameTable() *sqlparser.RenameTable
RenameTable returns the underlying sqlparser.RenameTable that was generated for the diff.
func (*RenameTableEntityDiff) SetSubsequentDiff ¶ added in v0.15.0
func (d *RenameTableEntityDiff) SetSubsequentDiff(EntityDiff)
SetSubsequentDiff implements EntityDiff
func (*RenameTableEntityDiff) Statement ¶ added in v0.15.0
func (d *RenameTableEntityDiff) Statement() sqlparser.Statement
Statement implements EntityDiff
func (*RenameTableEntityDiff) StatementString ¶ added in v0.15.0
func (d *RenameTableEntityDiff) StatementString() (s string)
StatementString implements EntityDiff
func (*RenameTableEntityDiff) SubsequentDiff ¶ added in v0.15.0
func (d *RenameTableEntityDiff) SubsequentDiff() EntityDiff
SubsequentDiff implements EntityDiff
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema represents a database schema, which may contain entities such as tables and views. Schema is not in itself an Entity, since it is more of a collection of entities.
func NewSchemaFromEntities ¶
func NewSchemaFromEntities(env *Environment, entities []Entity) (*Schema, error)
NewSchemaFromEntities creates a valid and normalized schema based on list of entities
func NewSchemaFromQueries ¶
func NewSchemaFromQueries(env *Environment, queries []string) (*Schema, error)
NewSchemaFromQueries creates a valid and normalized schema based on list of queries
func NewSchemaFromSQL ¶
func NewSchemaFromSQL(env *Environment, sql string) (*Schema, error)
NewSchemaFromSQL creates a valid and normalized schema based on a SQL blob that contains CREATE statements for various objects (tables, views)
func NewSchemaFromStatements ¶
func NewSchemaFromStatements(env *Environment, statements []sqlparser.Statement) (*Schema, error)
NewSchemaFromStatements creates a valid and normalized schema based on list of valid statements
func (*Schema) Apply ¶
func (s *Schema) Apply(diffs []EntityDiff) (*Schema, error)
Apply attempts to apply given list of diffs to the schema described by this object. These diffs are CREATE/DROP/ALTER TABLE/VIEW. The operation does not modify this object. Instead, if successful, a new (modified) Schema is returned.
func (*Schema) Entities ¶
Entities returns this schema's entities in good order (may be applied without error)
func (*Schema) EntityNames ¶
EntityNames is a convenience function that returns just the names of entities, in good order
func (*Schema) SchemaDiff ¶ added in v0.17.0
func (s *Schema) SchemaDiff(other *Schema, hints *DiffHints) (*SchemaDiff, error)
SchemaDiff calculates a rich diff between this schema and the given schema. It builds on top of diff(): on top of the list of diffs that can take this schema into the given schema, this function also evaluates the dependencies between those diffs, if any, and the resulting SchemaDiff object offers OrderedDiffs(), the safe ordering of diffs that, when applied sequentially, does not produce any conflicts and keeps schema valid at each step.
func (*Schema) Table ¶
func (s *Schema) Table(name string) *CreateTableEntity
Table returns a table by name, or nil if nonexistent
func (*Schema) TableNames ¶
TableNames is a convenience function that returns just the names of tables, in good order
func (*Schema) Tables ¶
func (s *Schema) Tables() []*CreateTableEntity
Tables returns this schema's tables in good order (may be applied without error)
func (*Schema) ToQueries ¶
ToQueries returns an ordered list of queries which can be applied to create the schema
func (*Schema) ToSQL ¶
ToSQL returns a SQL blob with ordered sequence of queries which can be applied to create the schema
func (*Schema) ToStatements ¶
ToStatements returns an ordered list of statements which can be applied to create the schema
func (*Schema) ValidateViewReferences ¶ added in v0.17.0
func (*Schema) View ¶
func (s *Schema) View(name string) *CreateViewEntity
View returns a view by name, or nil if nonexistent
func (*Schema) ViewNames ¶
ViewNames is a convenience function that returns just the names of views, in good order
func (*Schema) Views ¶
func (s *Schema) Views() []*CreateViewEntity
Views returns this schema's views in good order (may be applied without error)
type SchemaDiff ¶ added in v0.17.0
type SchemaDiff struct {
// contains filtered or unexported fields
}
SchemaDiff is a rich diff between two schemas. It includes the following: - The source schema (on which the diff would operate) - A list of SQL diffs (e.g. CREATE VIEW, ALTER TABLE, ...) - A map of dependencies between the diffs Operations on SchemaDiff are not concurrency-safe.
func DiffSchemas ¶
func DiffSchemas(env *Environment, schema1 *Schema, schema2 *Schema, hints *DiffHints) (*SchemaDiff, error)
DiffSchemas compares two schemas and returns the list of diffs that turn 1st schema into 2nd. Any of the schemas may be nil.
func DiffSchemasSQL ¶
func DiffSchemasSQL(env *Environment, sql1 string, sql2 string, hints *DiffHints) (*SchemaDiff, error)
DiffSchemasSQL compares two schemas and returns the rich diff that turns 1st schema into 2nd. Schemas are build from SQL, each of which can contain an arbitrary number of CREATE TABLE and CREATE VIEW statements.
func NewSchemaDiff ¶ added in v0.17.0
func NewSchemaDiff(schema *Schema, hints *DiffHints) *SchemaDiff
func (*SchemaDiff) AllDependenciess ¶ added in v0.17.0
func (d *SchemaDiff) AllDependenciess() (deps []*DiffDependency)
AllDependenciess returns all known dependencies
func (*SchemaDiff) AllSequentialExecutionDependencies ¶ added in v0.17.0
func (d *SchemaDiff) AllSequentialExecutionDependencies() (deps []*DiffDependency)
AllSequentialExecutionDependencies returns all diffs that are of "sequential execution" type.
func (*SchemaDiff) Empty ¶ added in v0.17.0
func (d *SchemaDiff) Empty() bool
Empty returns 'true' when there are no diff entries
func (*SchemaDiff) HasDependencies ¶ added in v0.17.0
func (d *SchemaDiff) HasDependencies() bool
HasDependencies returns `true` if there is at least one known diff dependency. If this function returns `false` then that means there is no restriction whatsoever to the order of diffs.
func (*SchemaDiff) HasSequentialExecutionDependencies ¶ added in v0.17.0
func (d *SchemaDiff) HasSequentialExecutionDependencies() bool
HasSequentialExecutionDependencies return `true` if there is at least one "subsequential execution" type diff. If not, that means all diffs can be applied in parallel.
func (*SchemaDiff) InstantDDLCapability ¶ added in v0.19.0
func (d *SchemaDiff) InstantDDLCapability() InstantDDLCapability
InstantDDLCapability returns an overall summary of the ability of the diffs to run with ALGORITHM=INSTANT. It is a convenience method, whose logic anyone can reimplement.
func (*SchemaDiff) OrderedDiffs ¶ added in v0.17.0
func (d *SchemaDiff) OrderedDiffs(ctx context.Context) ([]EntityDiff, error)
OrderedDiffs returns the list of diff in applicable order, if possible. This is a linearized representation where diffs may be applied in-order one after another, keeping the schema in valid state at all times.
func (*SchemaDiff) UnorderedDiffs ¶ added in v0.17.0
func (d *SchemaDiff) UnorderedDiffs() []EntityDiff
UnorderedDiffs returns all the diffs. These are not sorted by dependencies. These are basically the original diffs, but "flattening" any subsequent diffs they may have. as result: - Diffs in the returned slice have no subsequent diffs - The returned slice may be longer than the number of diffs supplied by loadDiffs()
type SubsequentDiffRejectedError ¶ added in v0.20.0
type SubsequentDiffRejectedError struct { Table string Diffs []EntityDiff }
func (*SubsequentDiffRejectedError) Error ¶ added in v0.20.0
func (e *SubsequentDiffRejectedError) Error() string
type TextualAnnotationType ¶ added in v0.20.0
type TextualAnnotationType int
TextualAnnotationType is an enum for the type of annotation that can be applied to a line of text.
const ( UnchangedTextualAnnotationType TextualAnnotationType = iota AddedTextualAnnotationType RemovedTextualAnnotationType )
type TextualAnnotations ¶ added in v0.20.0
type TextualAnnotations struct {
// contains filtered or unexported fields
}
TextualAnnotations is a sequence of annotated texts. It is the annotated representation of a statement.
func NewTextualAnnotations ¶ added in v0.20.0
func NewTextualAnnotations() *TextualAnnotations
func (*TextualAnnotations) Added ¶ added in v0.20.0
func (a *TextualAnnotations) Added() (r []*AnnotatedText)
func (*TextualAnnotations) ByType ¶ added in v0.20.0
func (a *TextualAnnotations) ByType(typ TextualAnnotationType) (r []*AnnotatedText)
ByType returns the subset of annotations by given type.
func (*TextualAnnotations) Export ¶ added in v0.20.0
func (a *TextualAnnotations) Export() string
Export beautifies the annotated text and returns it as a string.
func (*TextualAnnotations) Len ¶ added in v0.20.0
func (a *TextualAnnotations) Len() int
func (*TextualAnnotations) MarkAdded ¶ added in v0.20.0
func (a *TextualAnnotations) MarkAdded(text string)
func (*TextualAnnotations) MarkRemoved ¶ added in v0.20.0
func (a *TextualAnnotations) MarkRemoved(text string)
func (*TextualAnnotations) MarkUnchanged ¶ added in v0.20.0
func (a *TextualAnnotations) MarkUnchanged(text string)
func (*TextualAnnotations) Removed ¶ added in v0.20.0
func (a *TextualAnnotations) Removed() (r []*AnnotatedText)
type UnknownColumnCharsetCollationError ¶ added in v0.19.0
func (*UnknownColumnCharsetCollationError) Error ¶ added in v0.19.0
func (e *UnknownColumnCharsetCollationError) Error() string
type UnknownColumnCollationCharsetError ¶ added in v0.19.0
func (*UnknownColumnCollationCharsetError) Error ¶ added in v0.19.0
func (e *UnknownColumnCollationCharsetError) Error() string
type UnsupportedApplyOperationError ¶
type UnsupportedApplyOperationError struct {
Statement string
}
func (*UnsupportedApplyOperationError) Error ¶
func (e *UnsupportedApplyOperationError) Error() string
type UnsupportedEntityError ¶
func (*UnsupportedEntityError) Error ¶
func (e *UnsupportedEntityError) Error() string
type UnsupportedStatementError ¶
type UnsupportedStatementError struct {
Statement string
}
func (*UnsupportedStatementError) Error ¶
func (e *UnsupportedStatementError) Error() string
type UnsupportedTableOptionError ¶
func (*UnsupportedTableOptionError) Error ¶
func (e *UnsupportedTableOptionError) Error() string
type ViewDependencyUnresolvedError ¶ added in v0.15.0
type ViewDependencyUnresolvedError struct {
View string
}
func (*ViewDependencyUnresolvedError) Error ¶ added in v0.15.0
func (e *ViewDependencyUnresolvedError) Error() string