Documentation ¶
Index ¶
- Constants
- Variables
- func DDLActionStr(diff EntityDiff) (string, error)
- func ExtractConstraintOriginalName(constraintName string) string
- type AlterTableEntityDiff
- func (d *AlterTableEntityDiff) AlterTable() *sqlparser.AlterTable
- func (d *AlterTableEntityDiff) CanonicalStatementString() (s string)
- func (d *AlterTableEntityDiff) Entities() (from Entity, to Entity)
- 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) CanonicalStatementString() (s string)
- func (d *AlterViewEntityDiff) Entities() (from Entity, to Entity)
- 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 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) Create() EntityDiff
- func (c *CreateTableEntity) Diff(other Entity, hints *DiffHints) (EntityDiff, error)
- func (c *CreateTableEntity) Drop() EntityDiff
- func (c *CreateTableEntity) Name() string
- func (c *CreateTableEntity) TableDiff(other *CreateTableEntity, hints *DiffHints) (*AlterTableEntityDiff, error)
- type CreateTableEntityDiff
- func (d *CreateTableEntityDiff) CanonicalStatementString() (s string)
- func (d *CreateTableEntityDiff) CreateTable() *sqlparser.CreateTable
- func (d *CreateTableEntityDiff) Entities() (from Entity, to Entity)
- 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) 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, hints *DiffHints) (*AlterViewEntityDiff, error)
- type CreateViewEntityDiff
- func (d *CreateViewEntityDiff) CanonicalStatementString() (s string)
- func (d *CreateViewEntityDiff) CreateView() *sqlparser.CreateView
- func (d *CreateViewEntityDiff) Entities() (from Entity, to Entity)
- 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 DiffHints
- type DropTableEntityDiff
- func (d *DropTableEntityDiff) CanonicalStatementString() (s string)
- func (d *DropTableEntityDiff) DropTable() *sqlparser.DropTable
- func (d *DropTableEntityDiff) Entities() (from Entity, to Entity)
- 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) CanonicalStatementString() (s string)
- func (d *DropViewEntityDiff) DropView() *sqlparser.DropView
- func (d *DropViewEntityDiff) Entities() (from Entity, to Entity)
- 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 Entity
- type EntityDiff
- func AllSubsequent(diff EntityDiff) (diffs []EntityDiff)
- func DiffCreateTablesQueries(query1 string, query2 string, hints *DiffHints) (EntityDiff, error)
- func DiffCreateViewsQueries(query1 string, query2 string, hints *DiffHints) (EntityDiff, error)
- func DiffSchemas(schema1 *Schema, schema2 *Schema, hints *DiffHints) ([]EntityDiff, error)
- func DiffSchemasSQL(sql1 string, sql2 string, hints *DiffHints) ([]EntityDiff, error)
- func DiffTables(create1 *sqlparser.CreateTable, create2 *sqlparser.CreateTable, ...) (EntityDiff, error)
- func DiffViews(create1 *sqlparser.CreateView, create2 *sqlparser.CreateView, hints *DiffHints) (EntityDiff, error)
- type InvalidColumnInCheckConstraintError
- type InvalidColumnInForeignKeyConstraintError
- type InvalidColumnInGeneratedColumnError
- type InvalidColumnInKeyError
- type InvalidColumnInPartitionError
- type MissingPartitionColumnInUniqueKeyError
- type ModifyColumnDiff
- type NotFullyParsedError
- type Schema
- func (s *Schema) Apply(diffs []EntityDiff) (*Schema, error)
- func (s *Schema) Diff(other *Schema, hints *DiffHints) (diffs []EntityDiff, err error)
- func (s *Schema) Entities() []Entity
- func (s *Schema) Entity(name string) Entity
- func (s *Schema) EntityNames() []string
- 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) View(name string) *CreateViewEntity
- func (s *Schema) ViewNames() []string
- func (s *Schema) Views() []*CreateViewEntity
- type UnsupportedApplyOperationError
- type UnsupportedEntityError
- type UnsupportedStatementError
- type UnsupportedTableOptionError
Constants ¶
const ( AutoIncrementIgnore int = iota AutoIncrementApplyHigher AutoIncrementApplyAlways )
const ( RangeRotationFullSpec = iota RangeRotationDistinctStatements RangeRotationIgnore )
const ( ConstraintNamesIgnoreVitess = iota ConstraintNamesIgnoreAll ConstraintNamesStrict )
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") ErrViewDependencyUnresolved = errors.New("views have unresolved/loop dependencies") )
Functions ¶
func DDLActionStr ¶
func DDLActionStr(diff EntityDiff) (string, error)
DDLActionStr returns the action implied by the given diff: CREATE", "DROP", "ALTER" or empty
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) CanonicalStatementString ¶
func (d *AlterTableEntityDiff) CanonicalStatementString() (s string)
CanonicalStatementString implements EntityDiff
func (*AlterTableEntityDiff) Entities ¶
func (d *AlterTableEntityDiff) Entities() (from Entity, to Entity)
Entities 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) CanonicalStatementString ¶
func (d *AlterViewEntityDiff) CanonicalStatementString() (s string)
CanonicalStatementString implements EntityDiff
func (*AlterViewEntityDiff) Entities ¶
func (d *AlterViewEntityDiff) Entities() (from Entity, to Entity)
IsEmpty 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 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(other *ColumnDefinitionEntity, hints *DiffHints) *ModifyColumnDiff
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 AlterTable statement if changes are found, or nil if not. the other table may be of different name; its name is ignored.
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
}
CreateTableEntity stands for a TABLE construct. It contains the table's CREATE statement.
func NewCreateTableEntity ¶
func NewCreateTableEntity(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) 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) 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) CanonicalStatementString ¶
func (d *CreateTableEntityDiff) CanonicalStatementString() (s string)
CanonicalStatementString 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) 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
}
CreateViewEntity stands for a VIEW construct. It contains the view's CREATE statement.
func NewCreateViewEntity ¶
func NewCreateViewEntity(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) 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, hints *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) CanonicalStatementString ¶
func (d *CreateViewEntityDiff) CanonicalStatementString() (s string)
CanonicalStatementString 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) 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 DiffHints ¶
type DiffHints struct { StrictIndexOrdering bool AutoIncrementStrategy int RangeRotationStrategy int ConstraintNamesStrategy int }
DiffHints is an assortment of rules for diffing entities
type DropTableEntityDiff ¶
type DropTableEntityDiff struct {
// contains filtered or unexported fields
}
func (*DropTableEntityDiff) CanonicalStatementString ¶
func (d *DropTableEntityDiff) CanonicalStatementString() (s string)
CanonicalStatementString 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)
IsEmpty 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) CanonicalStatementString ¶
func (d *DropViewEntityDiff) CanonicalStatementString() (s string)
CanonicalStatementString 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) 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 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 // Create returns an entity diff that describes how to drop this entity Drop() EntityDiff }
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 // 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" the this diff's Statement(). It returns an empty string if the diff is empty StatementString() string // CanonicalStatementString "stringifies" the 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) }
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 DiffCreateTablesQueries ¶
func DiffCreateTablesQueries(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(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 DiffSchemas ¶
func DiffSchemas(schema1 *Schema, schema2 *Schema, hints *DiffHints) ([]EntityDiff, error)
DiffSchemasSQL 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(sql1 string, sql2 string, hints *DiffHints) ([]EntityDiff, error)
DiffSchemasSQL compares two schemas and returns the list of diffs that turn 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 DiffTables ¶
func DiffTables(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(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
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 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 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 ¶
NewSchemaFromEntities creates a valid and normalized schema based on list of entities
func NewSchemaFromQueries ¶
NewSchemaFromQueries creates a valid and normalized schema based on list of queries
func NewSchemaFromSQL ¶
NewSchemaFromSQL creates a valid and normalized schema based on a SQL blob that contains CREATE statements for various objects (tables, views)
func NewSchemaFromStatements ¶
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) Diff ¶
func (s *Schema) Diff(other *Schema, hints *DiffHints) (diffs []EntityDiff, err error)
Diff compares this schema with another schema, and sees what it takes to make this schema look like the other. It returns a list of diffs.
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) 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) 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
Tables returns this schema's views in good order (may be applied without error)
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