schemadiff

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (
	AutoIncrementIgnore int = iota
	AutoIncrementApplyHigher
	AutoIncrementApplyAlways
)
View Source
const (
	RangeRotationFullSpec = iota
	RangeRotationDistinctStatements
	RangeRotationIgnore
)
View Source
const (
	ConstraintNamesIgnoreVitess = iota
	ConstraintNamesIgnoreAll
	ConstraintNamesStrict
)
View Source
const (
	ColumnRenameAssumeDifferent = iota
	ColumnRenameHeuristicStatement
)
View Source
const (
	TableRenameAssumeDifferent = iota
	TableRenameHeuristicStatement
)
View Source
const (
	FullTextKeyDistinctStatements = iota
	FullTextKeyUnifyStatements
)

Variables

View Source
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 DDLActionStr

func DDLActionStr(diff EntityDiff) (string, error)

DDLActionStr returns the action implied by the given diff: CREATE", "DROP", "ALTER" or empty

func ExtractConstraintOriginalName

func ExtractConstraintOriginalName(constraintName string) string

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)

Entities 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

type ApplyColumnAfterNotFoundError struct {
	Table       string
	Column      string
	AfterColumn string
}

func (*ApplyColumnAfterNotFoundError) Error

type ApplyColumnNotFoundError

type ApplyColumnNotFoundError struct {
	Table  string
	Column string
}

func (*ApplyColumnNotFoundError) Error

func (e *ApplyColumnNotFoundError) Error() string

type ApplyConstraintNotFoundError

type ApplyConstraintNotFoundError struct {
	Table      string
	Constraint string
}

func (*ApplyConstraintNotFoundError) Error

type ApplyDuplicateColumnError

type ApplyDuplicateColumnError struct {
	Table  string
	Column string
}

func (*ApplyDuplicateColumnError) Error

func (e *ApplyDuplicateColumnError) Error() string

type ApplyDuplicateConstraintError

type ApplyDuplicateConstraintError struct {
	Table      string
	Constraint string
}

func (*ApplyDuplicateConstraintError) Error

type ApplyDuplicateEntityError

type ApplyDuplicateEntityError struct {
	Entity string
}

func (*ApplyDuplicateEntityError) Error

func (e *ApplyDuplicateEntityError) Error() string

type ApplyDuplicateKeyError

type ApplyDuplicateKeyError struct {
	Table string
	Key   string
}

func (*ApplyDuplicateKeyError) Error

func (e *ApplyDuplicateKeyError) Error() string

type ApplyDuplicatePartitionError

type ApplyDuplicatePartitionError struct {
	Table     string
	Partition string
}

func (*ApplyDuplicatePartitionError) Error

type ApplyKeyNotFoundError

type ApplyKeyNotFoundError struct {
	Table string
	Key   string
}

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

type ApplyPartitionNotFoundError struct {
	Table     string
	Partition string
}

func (*ApplyPartitionNotFoundError) Error

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 (*ColumnDefinitionEntity) ColumnDiff

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

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
	ColumnRenameStrategy    int
	TableRenameStrategy     int
	FullTextKeyStrategy     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)

Entities 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
	// 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
	// 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)
}

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

type InvalidColumnInCheckConstraintError struct {
	Table      string
	Constraint string
	Column     string
}

func (*InvalidColumnInCheckConstraintError) Error

type InvalidColumnInForeignKeyConstraintError

type InvalidColumnInForeignKeyConstraintError struct {
	Table      string
	Constraint string
	Column     string
}

func (*InvalidColumnInForeignKeyConstraintError) Error

type InvalidColumnInGeneratedColumnError

type InvalidColumnInGeneratedColumnError struct {
	Table           string
	Column          string
	GeneratedColumn string
}

func (*InvalidColumnInGeneratedColumnError) Error

type InvalidColumnInKeyError

type InvalidColumnInKeyError struct {
	Table  string
	Column string
	Key    string
}

func (*InvalidColumnInKeyError) Error

func (e *InvalidColumnInKeyError) Error() string

type InvalidColumnInPartitionError

type InvalidColumnInPartitionError struct {
	Table  string
	Column string
}

func (*InvalidColumnInPartitionError) Error

type MissingPartitionColumnInUniqueKeyError

type MissingPartitionColumnInUniqueKeyError struct {
	Table     string
	Column    string
	UniqueKey string
}

func (*MissingPartitionColumnInUniqueKeyError) Error

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

type NotFullyParsedError struct {
	Entity    string
	Statement string
}

func (*NotFullyParsedError) Error

func (e *NotFullyParsedError) Error() string

type RenameTableEntityDiff added in v0.15.0

type RenameTableEntityDiff struct {
	// contains filtered or unexported fields
}

func (*RenameTableEntityDiff) CanonicalStatementString added in v0.15.0

func (d *RenameTableEntityDiff) CanonicalStatementString() (s string)

CanonicalStatementString implements EntityDiff

func (*RenameTableEntityDiff) Entities added in v0.15.0

func (d *RenameTableEntityDiff) Entities() (from Entity, to Entity)

Entities 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(entities []Entity) (*Schema, error)

NewSchemaFromEntities creates a valid and normalized schema based on list of entities

func NewSchemaFromQueries

func NewSchemaFromQueries(queries []string) (*Schema, error)

NewSchemaFromQueries creates a valid and normalized schema based on list of queries

func NewSchemaFromSQL

func NewSchemaFromSQL(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(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) 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

func (s *Schema) Entities() []Entity

Entities returns this schema's entities in good order (may be applied without error)

func (*Schema) Entity

func (s *Schema) Entity(name string) Entity

Entity returns an entity by name, or nil if nonexistent

func (*Schema) EntityNames

func (s *Schema) EntityNames() []string

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

func (s *Schema) TableNames() []string

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

func (s *Schema) ToQueries() []string

ToQueries returns an ordered list of queries which can be applied to create the schema

func (*Schema) ToSQL

func (s *Schema) ToSQL() string

ToSQL returns a SQL blob with ordered sequence of queries which can be applied to create the schema

func (*Schema) ToStatements

func (s *Schema) ToStatements() []sqlparser.Statement

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

func (s *Schema) ViewNames() []string

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 UnsupportedApplyOperationError

type UnsupportedApplyOperationError struct {
	Statement string
}

func (*UnsupportedApplyOperationError) Error

type UnsupportedEntityError

type UnsupportedEntityError struct {
	Entity    string
	Statement string
}

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

type UnsupportedTableOptionError struct {
	Table  string
	Option string
}

func (*UnsupportedTableOptionError) Error

type ViewDependencyUnresolvedError added in v0.15.0

type ViewDependencyUnresolvedError struct {
	View string
}

func (*ViewDependencyUnresolvedError) Error added in v0.15.0

Jump to

Keyboard shortcuts

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