migration

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2019 License: MIT Imports: 17 Imported by: 4

README

license CircleCI codecov Go Report Card

Migration

A simple migration framework for Golang.

CLI

This migration does not have a binary CLI exported, but it has a built in tool to be triggered as a CLI.

This approach was adopted because there is a implementation based on source code implementation. For that to work we need to compile the tool.

Usage

go get github.com/lab259/go-migration

Now we must implement the CLI:

package main

import (
	"fmt"
	"github.com/globalsign/mgo"
	"github.com/lab259/go-migration"
	"github.com/lab259/go-migration/examples/mongo/db"
	_ "github.com/lab259/go-migration/examples/mongo/migrations" // Import all migrations
	"os"
)

func main() {
	session, err := mgo.Dial("mongodb://localhost/test") // Starts the connection
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	defer session.Close() // Ensures closing the connection

	db.MongoSession = session

	source := migration.DefaultCodeSource()      // Default Source implementation is the CodeSource...
	reporter := migration.NewDefaultReporter()   // Default reporter implementation

	manager := migration.NewDefaultManager(migration.NewMongoDB(session), source)
	runner := migration.NewArgsRunner(reporter, manager, os.Exit) // Create a runner based on the arguments passed to the program
	runner.Run() // Run the command
}

Below is an example of a migration. The NewCodeMigration takes the file name in consideration to extract the ID and Description of the migration. In the following example the file name is "20171219012821_create_table_indexes.go". So the ID will be 20171219012821 (but in time.Time) and the description will be "create_table_indexes".

package migrations

import (
	"github.com/globalsign/mgo"
	. "github.com/lab259/go-migration"
	"github.com/lab259/go-migration/examples/mongo/db"
)

func init() {
	NewCodeMigration(
		func() error {
			// Get the connection reference
			session := db.GetSession()
			defer session.Close()
			//-------------------

			c := session.DB("").C("customers")
			err := c.EnsureIndex(mgo.Index{
				Name: "NameIndex",
				Key:  []string{"name"},
			})
			return err // Return the error of the operation
		}, func() error {
			session := db.GetSession()
			defer session.Close()

			err := session.DB("").C("customers").DropIndexName("NameIndex")
			return err
		},
	)
}

Another thing the NewCodeMigration does is to auto register in the DefaultCodeSource. If you create a migration through the NewMigration you will need to register it manually.

Motivation

At first, I was not intending to create my own migration framework until I got stuck into two main problems.

  1. I was using MongoDB and I could find a reliable framework to adopt;

  2. Since most of the frameworks were based on SQL databases, SQL files or go files were used attached with database/sql package.

So, I decided I would create a minimalist framework that only cares about retrieving and storing the current version and let the developer deal with any database configurations and connections specifics.

As simple as it can be, it can track anything that can be versioned. From NoSQLs, until text files using diffs.

Mongo is NoSQL... Why bother migrations!?

Well... in the real world sometimes things change. And keep version of the "API" in the record might not be the best approach in some cases.

However, the main reason for this implementation is to ensure indexes are created correctly.

Why it does't have a CLI command?

It could be implemented when you are using SQL files as source (check the source_directory.go implementation). However, for the source_code.go you will need to create your own CLI. Hence, all connections which must be open, and all migrations "classes" can be compiled and linked together.

You can use the CLI base implementation to extend and create your own solution.

Supported databases

  • MongoDB (via mgo)
  • MySQL (TODO)
  • PostgresSQL (via lib/pq)
  • SQLite (TODO)

Other migration frameworks

Extending

In order to add new technologies to work with this framework, you must implement a struct implementing the Target interface.

The Target is a very simple interface responsible for getting and setting the version for the database. You can check out how the MongoDBTarget was implemented at target_mongodb.go.

Bugs and features

For BUGs and new features feel free to create an issue.

Documentation

Index

Constants

View Source
const DefaultMigrationTable = "_migrations"

DefaultMigrationTable is the default name of the migrations table.

Variables

View Source
var CodeMigrationDateFormat = "20060102150405"

CodeMigrationDateFormat is the format understood by the CodeMigration

View Source
var ErrMigrationPanicked = errors.New("migration panicked")

ErrMigrationPanicked is the error returned when a migrations panics.

View Source
var ErrMigrationStarved = errors.New("migration starvation")

ErrMigrationStarved is when late migrations are detected.

View Source
var NoVersion = time.Date(0, 0, 0, 0, 0, 0, 0, time.UTC)

NoVersion represents a zero version

Functions

func NewMigrationID

func NewMigrationID(str string) time.Time

NewMigrationID creates a new ID from a string.

func Register

func Register(migration Migration)

Register registers the migration on the migration.DefaultCodeSource instance.

Types

type ArgsRunner

type ArgsRunner struct {
	// contains filtered or unexported fields
}

ArgsRunner is the Runner that will provide the default implementation of Runner that captures params from the arguments.

func (*ArgsRunner) Run

func (runner *ArgsRunner) Run(executionContext interface{})

Run performs the actions based on the arguments captured.

type BaseMigration

type BaseMigration struct {
	// contains filtered or unexported fields
}

BaseMigration is the default structure that all base migrations returns.

func (*BaseMigration) GetDescription

func (m *BaseMigration) GetDescription() string

GetDescription returns the ID of the migration.

func (*BaseMigration) GetID

func (m *BaseMigration) GetID() time.Time

GetID returns the ID of the migration.

type CodeSource

type CodeSource struct {
	// contains filtered or unexported fields
}

CodeSource is migration.Source implementation. It provides the development of migrations using Golang code.

TODO add examples

func DefaultCodeSource

func DefaultCodeSource() *CodeSource

DefaultCodeSource implements a singleton of the default CodeSource. It enable the developer to use the migration.Register without needing to deal with the migration.NewCodeSource.

On normal situations only one CodeSource is enough through the whole system. And many sources are needed, the developer can use multiple instances of the migration.CodeSource and use the migration.CodeSource.Register, instead of using the default implementation migration.Register.

func NewCodeSource

func NewCodeSource() *CodeSource

NewCodeSource returns a new instance of a migration.CodeSource.

func (*CodeSource) List

func (s *CodeSource) List() ([]Migration, error)

List implements the migration.Source.List by listing all the registered migrations of this instance.

func (*CodeSource) Register

func (s *CodeSource) Register(migration Migration)

Register registers the migration for further use.

type DefaultMigration

type DefaultMigration struct {
	BaseMigration
	// contains filtered or unexported fields
}

DefaultMigration is the default implementation of the migration.Migration.

It is designed to provide a coded implementaiton of a migration. It receives an up and down anonymous methods to be ran while executing the migration.

This implementation is used by the migration.CodeSource implemenation of the migration.Source.

func NewCodeMigration

func NewCodeMigration(handlers ...Handler) *DefaultMigration

NewCodeMigration uses the regex to extract data NewMigration.

It uses the `NewCodeMigrationCustom`.

func NewCodeMigrationCustom added in v1.2.2

func NewCodeMigrationCustom(skip int, handlers ...Handler) *DefaultMigration

NewCodeMigrationCustom uses the regex to extract data NewMigration.

If a handler is provided it will assigned to the Up method. If a second is provided, it will be assigned to the Down method.

func NewMigration

func NewMigration(id time.Time, description string, handlers ...Handler) *DefaultMigration

NewMigration returns a new instance of migration.Migration with all the required properties initialized.

If a handler is provided it will assigned to the Up method. If a second is provided, it will be assigned to the Down method.

func (*DefaultMigration) Do

func (m *DefaultMigration) Do(executionContext interface{}) error

Do calls the up action of the migration.

func (*DefaultMigration) GetManager

func (m *DefaultMigration) GetManager() Manager

GetManager returns the reference of the manager that is executing the migration.

func (*DefaultMigration) SetManager

func (m *DefaultMigration) SetManager(manager Manager) Migration

SetManager set the reference of the manager that is executing the migration.

It returns itself for sugar syntax.

func (*DefaultMigration) Undo

func (m *DefaultMigration) Undo(executionContext interface{}) error

Undo calls the down action of the migration.

type DefaultReporter

type DefaultReporter struct {
	// contains filtered or unexported fields
}

DefaultReporter is the default implementation of a Reporter.

func NewDefaultReporter

func NewDefaultReporter() *DefaultReporter

NewDefaultReporter returns an instance of a DefaultReporter.

func NewDefaultReporterWithParams

func NewDefaultReporterWithParams(w io.Writer, exitFnc func(code int)) *DefaultReporter

NewDefaultReporterWithParams initializes an instance of a DefaultReporter with its params.

func (*DefaultReporter) AfterMigrate

func (reporter *DefaultReporter) AfterMigrate(migrations []*Summary, err error)

AfterMigrate is called right after the process of migration is completed.

func (*DefaultReporter) AfterMigration

func (reporter *DefaultReporter) AfterMigration(summary Summary, err error)

AfterMigration is called by the Manager right after a migrations is ran.

func (*DefaultReporter) AfterReset

func (reporter *DefaultReporter) AfterReset(rewindSummary []*Summary, migrateSummary []*Summary, err error)

AfterReset is called right before the process of reseting is completed.

func (*DefaultReporter) AfterRewind

func (reporter *DefaultReporter) AfterRewind(migrations []*Summary, err error)

AfterRewind is called right after the process of rewinding is completed.

func (*DefaultReporter) BeforeMigrate

func (reporter *DefaultReporter) BeforeMigrate(migrations []Migration)

BeforeMigrate is called right before the process of migration is triggered.

func (*DefaultReporter) BeforeMigration

func (reporter *DefaultReporter) BeforeMigration(summary Summary, err error)

BeforeMigration is called by the Manager right before a migration is ran.

func (*DefaultReporter) BeforeReset

func (reporter *DefaultReporter) BeforeReset()

BeforeReset is called right before the process of reseting is triggered.

func (*DefaultReporter) BeforeRewind

func (reporter *DefaultReporter) BeforeRewind(migrations []Migration)

BeforeRewind is called right before the process of rewinding is triggered.

func (*DefaultReporter) CommandNotFound

func (reporter *DefaultReporter) CommandNotFound(command string)

CommandNotFound reports the command executed by the migration tool was not found.

func (*DefaultReporter) Exit

func (reporter *DefaultReporter) Exit(code int)

Exit calls the exit function of the reporter.

func (*DefaultReporter) Failure

func (reporter *DefaultReporter) Failure(err error)

Failure reports a failure and writes it down.

func (*DefaultReporter) ListExecuted

func (reporter *DefaultReporter) ListExecuted(migrations []Migration, err error)

ListExecuted reports the list of the migrations that were executed.

func (*DefaultReporter) ListPending

func (reporter *DefaultReporter) ListPending(migrations []Migration, err error)

ListPending reports the list of the migrations peding to be executed.

func (*DefaultReporter) MigrationSummary

func (reporter *DefaultReporter) MigrationSummary(migration *Summary, err error)

MigrationSummary prints the summary of the migration.

func (*DefaultReporter) MigrationsStarved

func (reporter *DefaultReporter) MigrationsStarved(migrations []Migration)

MigrationsStarved is called whenever the manager detects a migration will never be executed.

func (*DefaultReporter) NoCommand

func (reporter *DefaultReporter) NoCommand()

NoCommand gets called when no command is provided to the migration tool.

func (*DefaultReporter) Usage

func (reporter *DefaultReporter) Usage()

Usage prints the usage of the migration command.

type Direction

type Direction uint

Direction is the enum that represents the direction of the migration.

Its possible values are `MigrationDirectionDo` and `MigrationDirectionUndo`.

const (
	// DirectionDo is the forward direction.
	DirectionDo Direction = iota
	// DirectionUndo is the backwards direction.
	DirectionUndo Direction = iota
)

type DirectorySource

type DirectorySource struct {
	// Directory represents the path that the migrations file will be searched
	// for.
	Directory string

	// Extension represents the file extension of the files.
	Extension string
}

DirectorySource is migration.Source implementation. It provides the development of migrations using SQL files inside of a directory.

The file pattern used to match the migrations is: <DATE>_<DESCRIPTION>.(up|down).(extension)

DATE: Must be in the format YYYYMMDDHHNNSS. For example, 20171005110647 for Oct 05, 2017 11:06:47)

DESCRIPTION: Any text but with no dots.

Valid naming examples:

20171025191747_Creates_user_table.down.sql       : Drop the user table
20171025191747_Creates_user_table.up.sql         : Create user table
20171025191747_Creates customers table.down.sql  : Drop the customer table
20171025191747_Creates customers table.up.sql    : Create customer table
20171025213303_Drops_the_token_column.up.sql     : Drops a column, so is irreversible (there is no .down.sql)

Invalid naming examples:

20171525191747_Creates_user_table.down.sql    : Invalid date (month 15?)
20171025191747_Creates_user_table.NNN.sql     : Invalid sufix (should be up or down)

func (*DirectorySource) List

func (s *DirectorySource) List() ([]Migration, error)

List implements the migration.Source.List by listing all the files inside the migration.DirectorySource.Directory with the naming convention using the migration.DirectorySource.Extension.

type FileMigration

type FileMigration struct {
	// contains filtered or unexported fields
}

FileMigration is the implementation of the migration.Migration that runs SQL files.

It is designed to provide a coded implementaiton of a migration. It receives an up and down anonymous methods to be ran while executing the migration.

It is used by the migration.CodeSource implemenation of the migration.Source.

func (*FileMigration) Do

func (m *FileMigration) Do(executionContext interface{}) error

Do implements the migration.Migration.Up by running all SQLs inside of the [migration.FileMigration.baseFile].up.sql file.

If the file does not exists, it returns an error.

func (*FileMigration) GetDescription

func (m *FileMigration) GetDescription() string

GetDescription implements the migration.Migration.GetDescription by returning the id of this migration.

func (*FileMigration) GetID

func (m *FileMigration) GetID() time.Time

GetID implements the migration.Migration.GetID by returning the id of this migration.

func (*FileMigration) GetManager

func (m *FileMigration) GetManager() Manager

GetManager implements the migration.Migration.GetManager by returning the manager responsible for the execution.

func (*FileMigration) SetManager

func (m *FileMigration) SetManager(manager Manager) Migration

SetManager implements the migration.Migration.SetManager by setting the manager of this instance.

It returns the itself for sugar syntax purposes.

func (*FileMigration) Undo

func (m *FileMigration) Undo(executionContext interface{}) error

Undo implements the migration.Migration.Down by running all SQLs inside of the [migration.FileMigration.baseFile].down.sql file.

If the file does not exists, it returns an error.

type Handler

type Handler func(executionContext interface{}) error

Handler is the signature of the up and down methods that a migration will receive.

type Manager

type Manager interface {
	Source() Source
	Target() Target
	MigrationsExecuted() ([]Migration, error)
	MigrationsPending() ([]Migration, error)
	Migrate(listener Reporter, executionContext interface{}) ([]*Summary, error)
	Rewind(listener Reporter, executionContext interface{}) ([]*Summary, error)
	Reset(listener Reporter, executionContext interface{}) ([]*Summary, []*Summary, error)
	Do(listener Reporter, executionContext interface{}) (*Summary, error)
	Undo(listener Reporter, executionContext interface{}) (*Summary, error)
}

Manager is an interface that describe the common behavior of a migration manager.

Any manager is divider in two parts: the `Source` and `Target`. In short, the `Source` is the origin of the migrations (eg. SQL files or Go scripts). A `Target` is database technology that the migrations will be action on.

Integrating the `Source` and the `Target`, the `Manager` is responsible for running migrations with its methods `Migrate`, `Rewind`, `Reset`, `Up` and `Down`.

func NewDefaultManager

func NewDefaultManager(target Target, source Source) Manager

NewDefaultManager creates and returns a migration.Manager implementation (`migration.ManagerDefault`) based on a target and source.

type ManagerDefault

type ManagerDefault struct {
	// contains filtered or unexported fields
}

ManagerDefault is a default implementation of a Manager. It provides, via migration.NewManager, a way to define what is the source and target of a manager.

func (*ManagerDefault) Do

func (manager *ManagerDefault) Do(reporter Reporter, executionContext interface{}) (*Summary, error)

Do takes a step up on the migrations, bringing the database one step closer to the latest migration.

Before the execution of the migrations, it calls the reporter.Before method. After the migration is executed, if it returns no error, it calls the reporter.After method.

func (*ManagerDefault) Migrate

func (manager *ManagerDefault) Migrate(reporter Reporter, executionContext interface{}) ([]*Summary, error)

Migrate brings the database to the latest migration.

func (*ManagerDefault) MigrationsExecuted

func (manager *ManagerDefault) MigrationsExecuted() ([]Migration, error)

MigrationsExecuted returns a list of migrations that were executed. It uses the migration.Manager.MigrationsAfter passing on the current version from migration.Manager.Target.Version.

func (*ManagerDefault) MigrationsPending

func (manager *ManagerDefault) MigrationsPending() ([]Migration, error)

MigrationsPending returns a list of migrations that were not executed yet. It uses the migration.Manager.MigrationsBefore passing on the current version from migration.Manager.Target.Version.

func (*ManagerDefault) Reset

func (manager *ManagerDefault) Reset(reporter Reporter, executionContext interface{}) ([]*Summary, []*Summary, error)

Reset rewind all the migrations, then migrates to the latest.

func (*ManagerDefault) Rewind

func (manager *ManagerDefault) Rewind(reporter Reporter, executionContext interface{}) ([]*Summary, error)

Rewind removes all migrations previously migrated.

It lists all the executed migrations and executes their migration.Migrate.Down in a inverted order, virtually bringing the database to its original form.

func (*ManagerDefault) Source

func (manager *ManagerDefault) Source() Source

Source returns the migration source used for this manager.

func (*ManagerDefault) Target

func (manager *ManagerDefault) Target() Target

Target returns the migration target used for this manager.

func (*ManagerDefault) Undo

func (manager *ManagerDefault) Undo(reporter Reporter, executionContext interface{}) (*Summary, error)

Undo takes a step up on the migrations, bringing the database one step closer to the latest migration.

Before the execution of the migrations, it calls the reporter.Before method. After the migration is executed, if it returns no error, it calls the reporter.After method.

type Migration

type Migration interface {
	GetID() time.Time
	GetDescription() string
	Do(executionContext interface{}) error
	Undo(executionContext interface{}) error
	GetManager() Manager
	SetManager(manager Manager) Migration
}

Migration is the interface that describes the common behavior that a migration should have to be manageable by the migration.Manager.

type MongoDBTarget

type MongoDBTarget struct {
	// contains filtered or unexported fields
}

MongoDBTarget implements the migration.Target of the MongoDB.

In order to get access to the MongoDB, migration.MongoDBTarget uses the MGo library (http://github.com/globalsign/mgo).

func NewMongoDB

func NewMongoDB(db *mgo.Database) *MongoDBTarget

NewMongoDB returns a new instance of the migration.MongoDBTarget

func (*MongoDBTarget) AddMigration

func (t *MongoDBTarget) AddMigration(summary *Summary) error

SetVersion implements the migration.Target.SetVersion by storing the passed version on the database.

It returns eny error returned by the MGo.

func (*MongoDBTarget) Database added in v1.2.0

func (t *MongoDBTarget) Database() *mgo.Database

Database returns the `*mgo.Database` reference of this target.

func (*MongoDBTarget) MigrationsExecuted

func (t *MongoDBTarget) MigrationsExecuted() ([]time.Time, error)

func (*MongoDBTarget) RemoveMigration

func (t *MongoDBTarget) RemoveMigration(summary *Summary) error

RemoveMigration find and removes a migrations from the collection.

func (*MongoDBTarget) SetCollectionName

func (t *MongoDBTarget) SetCollectionName(collection string) *MongoDBTarget

SetCollectionName sets the name of the collection used to store the current version of the database.

func (*MongoDBTarget) Version

func (t *MongoDBTarget) Version() (migrationID time.Time, err error)

Version implements the migration.Target.Version by fetching the current version of the database from the collection defined by migration.MongoDBTarget.SetCollectionName.

It returns the current version of the database.

Any error returned by the MGo, will be passed up to the caller.

type MySQLTarget

type MySQLTarget struct {
	// contains filtered or unexported fields
}

MySQLTarget implements the migration.Target of the SQL based databases, using the Golang SQL package.

func NewMySQL

func NewMySQL(conn *sql.DB) *MySQLTarget

NewMySQL returns a new instance of the migration.MySQLTarget

func (*MySQLTarget) Connection

func (target *MySQLTarget) Connection() *sql.DB

Connection returns the mgo.Session reference of this target.

func (*MySQLTarget) SetTableName

func (target *MySQLTarget) SetTableName(collection string) *MySQLTarget

SetTableName sets the name of the table used to store the current migrations version that were executed.

func (*MySQLTarget) SetVersion

func (target *MySQLTarget) SetVersion(id time.Time) error

SetVersion implements the migration.Target.SetVersion by storing the passed version on the database.

It returns any error returned from the database driver.

func (*MySQLTarget) Version

func (target *MySQLTarget) Version() (time.Time, error)

Version implements the migration.Target.Version by fetching the current version of the database from the table defined by migration.MongoDBTarget.SetCollectionName.

It returns the current version of the database.

Any error returned by the driver, will be passed to the caller.

type PostgreSQLTarget added in v1.3.0

type PostgreSQLTarget struct {
	// contains filtered or unexported fields
}

func NewPostgreSQLTarget added in v1.3.0

func NewPostgreSQLTarget(db *sql.DB) *PostgreSQLTarget

func (*PostgreSQLTarget) AddMigration added in v1.3.0

func (target *PostgreSQLTarget) AddMigration(summary *Summary) error

func (*PostgreSQLTarget) MigrationsExecuted added in v1.3.0

func (target *PostgreSQLTarget) MigrationsExecuted() ([]time.Time, error)

func (*PostgreSQLTarget) RemoveMigration added in v1.3.0

func (target *PostgreSQLTarget) RemoveMigration(summary *Summary) error

func (*PostgreSQLTarget) Version added in v1.3.0

func (target *PostgreSQLTarget) Version() (time.Time, error)

type Reporter

type Reporter interface {
	BeforeMigration(migration Summary, err error)
	MigrationSummary(migration *Summary, err error)
	AfterMigration(migration Summary, err error)

	BeforeMigrate(migrations []Migration)
	AfterMigrate(migrations []*Summary, err error)

	BeforeRewind(migrations []Migration)
	AfterRewind(migrations []*Summary, err error)

	BeforeReset()
	AfterReset(rewindSummary []*Summary, migrateSummary []*Summary, err error)

	ListPending(migrations []Migration, err error)
	ListExecuted(migrations []Migration, err error)

	Failure(err error)
	Exit(code int)

	MigrationsStarved(migrations []Migration)

	Usage()
	CommandNotFound(command string)
	NoCommand()
}

Reporter is a helper method used, mainly, for logging on the `Manager` methods. Before executing any migration (in any direction) the `Manager` calls the listener `Before`. Afterward, if it does not return any error, the listener's `After` is called.

type Runner

type Runner interface {
	Run(executionContext interface{})
}

Runner defines the basic contract for a something that might run a migration.

func NewArgsRunner

func NewArgsRunner(reporter Reporter, manager Manager, exitFnc func(code int)) Runner

NewArgsRunner returns a new instance of a ArgsRunner.

func NewArgsRunnerCustom

func NewArgsRunnerCustom(reporter Reporter, manager Manager, exitFnc func(code int), args ...string) Runner

NewArgsRunnerCustom create a new instance of the Runer with custom arguments.

type Source

type Source interface {
	// List lists all migrations available for this migrations.Source.
	List() ([]Migration, error)
}

Source describes the common interface for source of migrations.

Different technologies support various ways of interaction with them. For SQL based databases, SQL files may solve the problem. However, when dealing with NoSQL databases, as MongoDB, it will not work.

So, migration.Source is a interface let the developer "store" migrations in many ways.

type Summary

type Summary struct {
	Migration Migration
	// contains filtered or unexported fields
}

Summary is the record that keeps all the data collected while the migration was ran.

func NewSummary

func NewSummary(migration Migration) *Summary

NewSummary creates a new summary based on a migration instance.

func (*Summary) Direction

func (summary *Summary) Direction() Direction

Direction is the direction the migrations ran.

func (*Summary) Duration added in v1.2.2

func (summary *Summary) Duration() time.Duration

Duration is how long the migration took to run.

func (*Summary) Failed

func (summary *Summary) Failed() bool

Failed returns if the migration failed.

func (*Summary) Failure

func (summary *Summary) Failure() error

Failure returns the reason because the migration failed.

func (*Summary) PanicData

func (summary *Summary) PanicData() interface{}

PanicData is the stores the data from the panic recovery function.

func (*Summary) Panicked

func (summary *Summary) Panicked() bool

Panicked is a flag that is returned when the tests panicks.

type Target

type Target interface {
	// Version returns the current version of the database.
	Version() (time.Time, error)

	// AddMigration persists the version on the database (or any other mean
	// necessary).
	AddMigration(summary *Summary) error

	// RemoveMigration removes a migration record from the database.
	RemoveMigration(summary *Summary) error

	// MigrationsExecuted returns all the migrations executed.
	MigrationsExecuted() ([]time.Time, error)
}

Target describes the common interface for target of migrations. Each target is a implementation of a specific database (or anything versionable).

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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