Documentation ¶
Index ¶
- Constants
- Variables
- func AlterTableCapableOfInstantDDL(alterTable *sqlparser.AlterTable, createTable *sqlparser.CreateTable, ...) (bool, error)
- func AlterTableRotatesRangePartition(createTable *sqlparser.CreateTable, alterTable *sqlparser.AlterTable) (bool, error)
- func DDLActionStr(diff EntityDiff) (string, error)
- func ExtractConstraintOriginalName(tableName string, constraintName string) string
- func IsIntegralType(columnType string) bool
- 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
- type CreateTableEntity
- func (c *CreateTableEntity) Apply(diff EntityDiff) (Entity, error)
- func (c *CreateTableEntity) Clone() Entity
- 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) 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 IndexNeededByForeignKeyError
- type InstantDDLCapability
- type InvalidColumnInCheckConstraintError
- type InvalidColumnInForeignKeyConstraintError
- type InvalidColumnInGeneratedColumnError
- type InvalidColumnInKeyError
- type InvalidColumnInPartitionError
- type InvalidColumnReferencedInViewError
- type InvalidReferencedColumnInForeignKeyConstraintError
- type InvalidStarExprInViewError
- type MissingForeignKeyReferencedIndexError
- type MissingPartitionColumnInUniqueKeyError
- type ModifyColumnDiff
- 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 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") )
Functions ¶
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 DDLActionStr ¶
func DDLActionStr(diff EntityDiff) (string, error)
DDLActionStr returns the action implied by the given diff: CREATE", "DROP", "ALTER" or empty
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 IsIntegralType ¶ added in v0.16.0
Types ¶
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 {
// contains filtered or unexported fields
}
func NewColumnDefinitionEntity ¶
func NewColumnDefinitionEntity(c *sqlparser.ColumnDefinition) *ColumnDefinitionEntity
func (*ColumnDefinitionEntity) ColumnDiff ¶
func (c *ColumnDefinitionEntity) ColumnDiff( env *Environment, tableName string, other *ColumnDefinitionEntity, t1cc *charsetCollate, t2cc *charsetCollate, 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) 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
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 (*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) Clone ¶ added in v0.15.0
func (c *CreateTableEntity) Clone() Entity
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) 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 (*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 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 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 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