migration

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AddAll is the option that tells some generator methods to not check if things exist and just add them all
	AddAll uint8 = 0x000
	// AddMissing is the option that tells some generator methods to check if things exist and skip over them if they do
	AddMissing uint8 = 0x001
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	// CreateTable returns a string query which creates a full table with columns columns and primary key
	CreateTable(table string, t schema.Table) string

	// AddColumn returns a string query which adds the specified column to a table
	AddColumn(table, column string, c schema.Column) string

	// AddIndex returns a string query which adds the specified index to a table
	AddIndex(table, index string, i schema.Index) string

	// AddReference returns a string query which adds the specified index to a table
	AddReference(table string, dt schema.Table, i schema.Reference) string
}

Adapter describes an internal dialect to be used by Yoyo for generating Migration code for a given DBMS.

func LoadAdapter

func LoadAdapter(name string) (a Adapter, err error)

LoadAdapter loads and returns an implementation of Adapter corresponding to the given name string

type AdapterLoader

type AdapterLoader func(name string) (d Adapter, err error)

type Generator

type Generator func(db schema.Database, w io.StringWriter) error

Generator functions take a schema.Database and io.StringWriter, generating stuff for the Database to the io.StringWriter

func NewGenerator

func NewGenerator(
	createTable TableGenerator,
	addMissingColumns TableGenerator,
	addMissingIndices TableGenerator,
	addAllIndices TableGenerator,
	hasTable StringSearcher,
	addMissingRefs RefGenerator,
	addAllRefs RefGenerator,
) Generator

NewGenerator returns a function that generates a schema and writes it to the given io.StringWriter.

type GeneratorLoader

type GeneratorLoader func(config yoyo.Config) (Generator, error)

func InitGeneratorLoader

func InitGeneratorLoader(
	initReverseAdapter func(dia string) (adapter reverse.Adapter, err error),
	initMigrationAdapter func(dia string) (a Adapter, err error),
	newGenerator func(TableGenerator, TableGenerator, TableGenerator, TableGenerator, StringSearcher, RefGenerator, RefGenerator) Generator,
) GeneratorLoader

type RefGenerator

type RefGenerator func(localTable string, refs []schema.Reference, sw io.StringWriter) error

RefGenerator functions take a string, map[string]schema.Reference, and io.StringWriter. Implementations will use them to generate SQL for working with references

func NewRefAdder

func NewRefAdder(
	a Adapter,
	db schema.Database,
	options uint8,
	hasReference reverse.TableSearcher,
) RefGenerator

NewRefAdder returns a RefGenerator that adds references to a given table.

type StringSearcher

type StringSearcher func(string) (bool, error)

StringSearcher functions take a string and return true if the matching entity (table, column, etc) exists.

type TableGenerator

type TableGenerator func(table schema.Table, sw io.StringWriter) error

TableGenerator functions take a string, schema.Table, and io.StringWriter. Implementations will use them to generate SQL for creating or modifying tables

func NewColumnAdder

func NewColumnAdder(
	a Adapter,
	options uint8,
	hasColumn reverse.TableSearcher,
) TableGenerator

NewColumnAdder returns a TableGenerator that adds columns from a schema.Table.

func NewIndexAdder

func NewIndexAdder(
	a Adapter,
	options uint8,
	hasIndex reverse.TableSearcher,
) TableGenerator

NewIndexAdder returns a TableGenerator that adds indices from a schema.Table.

func NewTableAdder

func NewTableAdder(
	a Adapter,
) TableGenerator

NewTableAdder returns a TableGenerator that adds a table

Jump to

Keyboard shortcuts

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