Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoPlan = errors.New("sql/migrate: no plan for matched states")
ErrNoPlan is returned by Plan when there is no change between the two states.
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change struct { // Cmd or statement to execute. Cmd string // Args for placeholder parameters in the statement above. Args []interface{} // A Comment describes the change. Comment string // Reverse contains the "reversed statement" if // command is reversible. Reverse string // The Source that caused this change, or nil. Source schema.Change }
A Change of migration.
type Dir ¶
type Dir struct {
// contains filtered or unexported fields
}
Dir represents a versioned migration directory.
func (*Dir) Compact ¶
Compact compacts the first n migration files into one. If n < 0, all files are selected.
func (*Dir) Plan ¶
Plan calculates the migration Plan required for moving from the directory state to the next state (to). A StateReader, can be another directory, static schema elements or a Driver connection.
type DirOption ¶
DirOption allows configuring the Dir using functional options.
func DirConn ¶
DirConn provides a Driver connection to a database. It is usually connected to an ephemeral database for emulating migration changes on it and calculating the "current state" to be compared with the "desired state".
func DirGlob ¶
DirGlob configures the glob/pattern for reading migration files from the directory. For example:
migrate.NewDir( migrate.DirPath("migrations"), migrate.DirGlob("*.up.sql"), )
func DirPath ¶
DirPath configures the FS used by the migration directory to point the given OS directory.
func DirTemplates ¶
DirTemplates configures template files for writing the Plan object to the migration directory.
migrate.NewDir( migrate.DirPath("migrations"), migrate.DirTemplates("{{timestamp}}{{.Name}}.up.sql", "{{range c := .Changes}}{{println c.Cmd}}{{end}}"), ) migrate.NewDir( migrate.DirPath("migrations"), migrate.DirTemplates( "{{timestamp}}{{.Name}}.up.sql", "{{range $c := .Changes}}{{println $c.Cmd}}{{end}}", "{{timestamp}}{{.Name}}.down.sql", "{{range $c := .Changes}}{{println $c.Reverse}}{{end}}", ), )
type Driver ¶
type Driver interface { schema.Differ schema.ExecQuerier schema.Inspector PlanApplier }
The Driver interface must be implemented by the different dialects to support database migration authoring/planning and applying. ExecQuerier, Inspector and Differ, provide basic schema primitives for inspecting database schemas, calculate the difference between schema elements, and executing raw SQL statements. The PlanApplier interface wraps the methods for generating migration plan for applying the actual changes on the database.
type FileRemoveWriter ¶
type FileRemoveWriter interface { RemoveFile(name string) error WriteFile(name string, data []byte, perm fs.FileMode) error }
FileRemoveWriter wraps the WriteFile and RemoveFile methods to allow editing the migration directory on development.
type Plan ¶
type Plan struct { // Name of the plan. Provided by the user or auto-generated. Name string // Reversible describes if the changeset is reversible. Reversible bool // Transactional describes if the changeset is transactional. Transactional bool // Changes defines the list of changeset in the plan. Changes []*Change }
A Plan defines a planned changeset that its execution brings the database to the new desired state. Additional information is calculated by the different drivers to indicate if the changeset is transactional (can be rolled-back) and reversible (a down file can be generated to it).
type PlanApplier ¶
type PlanApplier interface { // PlanChanges returns a migration plan for applying the given changeset. PlanChanges(context.Context, string, []schema.Change) (*Plan, error) // ApplyChanges is responsible for applying the given changeset. // An error may return from ApplyChanges if the driver is unable // to execute a change. ApplyChanges(context.Context, []schema.Change) error }
PlanApplier wraps the methods for planning and applying changes on the database.
type StateReader ¶
StateReader wraps the method for reading a database/schema state. The types below provides a few builtin options for reading a state from a migration directory, a static object (e.g. a parsed file).
In next Go version, the State will be replaced with the following union type `interface { Realm | Schema }`.
func Realm ¶
func Realm(r *schema.Realm) StateReader
Realm returns a state reader for the static Realm object.
func Schema ¶
func Schema(s *schema.Schema) StateReader
Schema returns a state reader for the static Schema object.
type StateReaderFunc ¶
The StateReaderFunc type is an adapter to allow the use of ordinary functions as state readers.