mydiff

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

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

View Source
const Version = "1.0.0"

Version is the semantic version of mydiff

Variables

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

func StringSetDiff(a []string, b []string) (diff []string)

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

func NewFormatter(diffType string) (Formatter, error)

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

Statement (see tengo.ObjectType)

type ParsedDSN

type ParsedDSN struct {
	*mysql.Config
}

func ParseDSN

func ParseDSN(DSN string) *ParsedDSN

ParseDSN parses a DSN string into an object capable of returning information about its parts

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

type TableDiff struct {
	*tengo.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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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