Documentation
¶
Index ¶
Constants ¶
const DiffTypeMigrations = 10 ^ 6 + iota
A integer denoting our custom diff type for schema migrations We add 10^6 to iota, to avoid collisions with tengo diff types.
const Version = "1.0.0"
Version is the semantic version of mydiff
Variables ¶
var AvailableFormatters map[string]Formatter = map[string]Formatter{ "sql": &SQLFormatter{}, "compact": &CompactFormatter{}, }
AvailableFormatters is a map with the available formatters indexed by their name.
Functions ¶
func StringSetDiff ¶
StringSetDiff returns the difference between two sets of strings
Types ¶
type CompactFormatter ¶
type CompactFormatter struct{}
CompactFormatter formats a diff in a compact human-readable way
func (*CompactFormatter) Format ¶
func (f *CompactFormatter) Format(diff *Diff) interface{}
Format returns a string with the formatted diff
type Diff ¶
type Diff struct {
DSN1, DSN2 *ParsedDSN
From, To *tengo.Schema
IncludeMigrations bool
MigrationsCol string
}
Diff encapsulates the data necessary to compute a diff between two schemas in servers denoted by DSN1, and DSN2
func NewDiff ¶
func NewDiff(DSN1, DSN2 string, from, to *tengo.Schema, includeMigrations bool, migrationsCol string) *Diff
NewDiff creates a new Diff
func (*Diff) Compute ¶
func (d *Diff) Compute() []tengo.ObjectDiff
Compute computes the difference between the two schemas returning an Difference object.
func (*Diff) Raw ¶
func (d *Diff) Raw() *tengo.SchemaDiff
Raw returns the tengo.SchemaDiff between the receiver's From an To fields
type Formatter ¶
type Formatter interface {
Format(diff *Diff) interface{}
}
Formatter is the interface implemented by different values that know how To format a diff
func NewFormatter ¶
NewFormatter creates a new value of a specific formatter based on the given difftype. Allowed difftypes are: - sql: which returns a SQLFormatter If the difftype is unknown, then an error is returned.
type MigrationsDiff ¶
type MigrationsDiff struct { Context *Diff Table, Column string Missing1 []string Missing2 []string }
MigrationDiff is an implementation of a tengo.ObjectDiff aimed at representing the difference in the migrations recorded in both schemas.
MigrationsDiff is tested in integration in diff_test.go and formatter_test.go
func NewMigrationsDiff ¶
func NewMigrationsDiff(d *Diff) (m *MigrationsDiff, err error)
ComputeMigrationsDiff calculates a MigrationsDiff Object, which represents the differences between two tables containing the versions of the migrations that were run in two servers.
This is useful while detecting inconsistencies in the DBs of web application development frameworks such as rails
func (*MigrationsDiff) DiffType ¶
func (m *MigrationsDiff) DiffType() tengo.DiffType
DiffType (see tengo.ObjectType)
func (*MigrationsDiff) IsEmpty ¶
func (m *MigrationsDiff) IsEmpty() bool
IsEmpty determines whether the migrations diff is empty
func (*MigrationsDiff) ObjectKey ¶
func (m *MigrationsDiff) ObjectKey() tengo.ObjectKey
ObjectKey (see tengo.ObjectType)
func (*MigrationsDiff) Statement ¶
func (m *MigrationsDiff) Statement(tengo.StatementModifiers) (string, error)
Statement (see tengo.ObjectType)
type SQLFormatter ¶
type SQLFormatter struct{}
SQLFormatter formats a Diff in SQL format (ALTER, CREATE and DROP statements)
func (*SQLFormatter) Format ¶
func (f *SQLFormatter) Format(diff *Diff) interface{}
Format formats a diff returning a slice of string commands, each of which is an SQL ALTER, CREATE or DROP statement.
type TableDiff ¶
TableDiff is an adapter of the tengo.TableDiff that exposes the alterClauses field, in order to be visitable by any formatter object.
There's no reason why tengo.TableDiff.alterClauses is not exported, and a new ticket should be opened in skeema/tengo to export this field, and eventually remove this code, which is unsafe if the dependency on skeema/tengo is upgraded.
func (*TableDiff) AlterClauses ¶
func (d *TableDiff) AlterClauses() []tengo.TableAlterClause
AlterClauses returns the unexported alterClauses field of the adapted tengo.tableDiff so a Formatter can visit them to generate instructions for amending the schemas, not only in SQL but in the different formats supported by mydiff.
TableAlterClause can be one of:
AddColumn DropColumn AddIndex DropIndex AddForeignKey DropForeignKey RenameColumn ModifyColumn ChangeAutoIncrement ChangeCharSet ChangeCreateOptions ChangeComment ChangeStorageEngine