Documentation ¶
Index ¶
- func ApplyChanges(ctx context.Context, changes []schema.Change, p execPlanner) error
- func CheckDiff(from, to *schema.Table, compare ...func(c1, c2 *schema.Check) bool) []schema.Change
- func CommentChange(from, to []schema.Attr) schema.ChangeKind
- func CommentDiff(from, to []schema.Attr) schema.Change
- func DefaultValue(c *schema.Column) (string, bool)
- func DetachCycles(changes []schema.Change) ([]schema.Change, error)
- func Has(elements, target interface{}) bool
- func IsLiteralBool(s string) bool
- func IsLiteralNumber(s string) bool
- func IsQuoted(s string, q ...byte) bool
- func LinkSchemaTables(schemas []*schema.Schema)
- func ScanFKs(t *schema.Table, rows *sql.Rows) error
- func ScanOne(rows *sql.Rows, dest ...interface{}) error
- func ScanSchemaFKs(s *schema.Schema, rows *sql.Rows) error
- func ScanStrings(rows *sql.Rows) ([]string, error)
- func SingleQuote(s string) (string, error)
- func Unquote(s string) (string, error)
- func ValidString(s sql.NullString) bool
- func ValuesEqual(v1, v2 []string) bool
- func VersionPermutations(dialect, version string) []string
- type Builder
- func (b *Builder) Clone() *Builder
- func (b *Builder) Comma() *Builder
- func (b *Builder) Ident(s string) *Builder
- func (b *Builder) MapComma(x interface{}, f func(i int, b *Builder)) *Builder
- func (b *Builder) MapCommaErr(x interface{}, f func(i int, b *Builder) error) error
- func (b *Builder) P(phrases ...string) *Builder
- func (b *Builder) String() string
- func (b *Builder) Table(t *schema.Table) *Builder
- func (b *Builder) Wrap(f func(b *Builder)) *Builder
- type Diff
- type DiffDriver
- type Normalizer
- type UnsupportedTypeError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyChanges ¶ added in v0.2.0
ApplyChanges is a helper used by the different drivers to apply changes.
func CheckDiff ¶ added in v0.2.0
CheckDiff computes the change diff between the 2 tables. A compare function is provided to check if a Check object was modified.
func CommentChange ¶
func CommentChange(from, to []schema.Attr) schema.ChangeKind
CommentChange reports if the element comment was changed.
func CommentDiff ¶ added in v0.3.0
CommentDiff computes the comment diff between the 2 attribute list. Note that, the implementation relies on the fact that both PostgreSQL and MySQL treat empty comment as "no comment" and a way to clear comments.
func DefaultValue ¶ added in v0.2.0
DefaultValue returns the string represents the DEFAULT of a column.
func DetachCycles ¶
DetachCycles takes a list of schema changes, and detaches references between changes if there is at least one circular reference in the changeset. More explicitly, it postpones fks creation, or deletes fks before deletes their tables.
func Has ¶
func Has(elements, target interface{}) bool
Has finds the first element in the elements list that matches target, and if so, sets target to that attribute value and returns true.
func IsLiteralBool ¶ added in v0.2.0
IsLiteralBool reports if the given string is a valid literal bool.
func IsLiteralNumber ¶ added in v0.2.0
IsLiteralNumber reports if the given string is a literal number.
func IsQuoted ¶ added in v0.2.0
IsQuoted reports if the given string is quoted with one of the given quotes (e.g. '\”, '"', '`').
func LinkSchemaTables ¶
LinkSchemaTables links foreign-key stub tables/columns to actual elements.
func ScanFKs ¶
ScanFKs scans the rows and adds the foreign-key to the table. Reference elements are added as stubs and should be linked manually by the caller.
func ScanSchemaFKs ¶ added in v0.3.4
ScanSchemaFKs scans the rows and adds the foreign-key to the schema table. Reference elements are added as stubs and should be linked manually by the caller.
func ScanStrings ¶
ScanStrings scans sql.Rows into a slice of strings and closes it at the end.
func SingleQuote ¶ added in v0.3.0
SingleQuote quotes the given string with single quote.
func ValidString ¶
func ValidString(s sql.NullString) bool
ValidString reports if the given string is not null and valid.
func ValuesEqual ¶
ValuesEqual checks if the 2 string slices are equal (including their order).
func VersionPermutations ¶
VersionPermutations returns permutations of the dialect version sorted from coarse to fine grained. For example:
VersionPermutations("mysql", "1.2.3") => ["mysql", "mysql 1", "mysql 1.2", "mysql 1.2.3"]
VersionPermutations will split the version number by ".", " ", "-" or "_", and rejoin them with ".". The output slice can be used by drivers to generate a list of permutations for searching for relevant overrides in schema element specs.
Types ¶
type Builder ¶
A Builder provides a syntactic sugar API for writing SQL statements.
func (*Builder) Comma ¶
Comma writes a comma in case the buffer is not empty, or replaces the last char if it is a whitespace.
func (*Builder) MapComma ¶
MapComma maps the slice x using the function f and joins the result with a comma separating between the written elements.
func (*Builder) MapCommaErr ¶ added in v0.2.0
MapCommaErr is like MapComma, but returns an error if f returns an error.
func (*Builder) P ¶
P writes a list of phrases to the builder separated and suffixed with whitespace.
func (*Builder) String ¶
String overrides the Buffer.String method and ensure no spaces pad the returned statement.
type Diff ¶
type Diff struct {
DiffDriver
}
A Diff provides a generic schema.Differ for diffing schema elements.
The DiffDriver is required for supporting database/dialect specific diff capabilities, like diffing custom types or attributes.
func (*Diff) RealmDiff ¶ added in v0.2.0
RealmDiff implements the schema.Differ for Realm objects and returns a list of changes that need to be applied in order to move a database from the current state to the desired.
func (*Diff) SchemaDiff ¶
SchemaDiff implements the schema.Differ interface and returns a list of changes that need to be applied in order to move from one state to the other.
type DiffDriver ¶
type DiffDriver interface { // SchemaAttrDiff returns a changeset for migrating schema attributes // from one state to the other. For example, changing schema collation. SchemaAttrDiff(from, to *schema.Schema) []schema.Change // TableAttrDiff returns a changeset for migrating table attributes from // one state to the other. For example, dropping or adding a `CHECK` constraint. TableAttrDiff(from, to *schema.Table) ([]schema.Change, error) // ColumnChange returns the schema changes (if any) for migrating one column to the other. ColumnChange(from, to *schema.Column) (schema.ChangeKind, error) // IndexAttrChanged reports if the index attributes were changed. // For example, an index type or predicate (for partial indexes). IndexAttrChanged(from, to []schema.Attr) bool // IndexPartAttrChanged reports if the index-part attributes were // changed. For example, an index-part collation. IndexPartAttrChanged(from, to *schema.IndexPart) bool // IsGeneratedIndexName reports if the index name was generated by the database // for unnamed INDEX or UNIQUE constraints. In such cases, the differ will look // for unnamed schema.Indexes on the desired state, before tagging the index as // a candidate for deletion. IsGeneratedIndexName(*schema.Table, *schema.Index) bool // ReferenceChanged reports if the foreign key referential action was // changed. For example, action was changed from RESTRICT to CASCADE. ReferenceChanged(from, to schema.ReferenceOption) bool }
A DiffDriver wraps all required methods for diffing elements that may have database-specific diff logic. See sql/schema/mysql/diff.go for an implementation example.
type Normalizer ¶
A Normalizer wraps the Normalize method for normalizing the from and to tables before running diffing. The "from" usually represents the inspected database state (current), and the second represents the desired state.
If the DiffDriver implements the Normalizer interface, TableDiff normalizes its table inputs before starting the diff process.
type UnsupportedTypeError ¶
UnsupportedTypeError describes an unsupported type error.
func (UnsupportedTypeError) Error ¶
func (e UnsupportedTypeError) Error() string