{"modulePath":"github.com/unity-technologies/migrate","version":"v3.5.4+incompatible","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package source\n\nPackage source provides the Source interface. All source drivers must implement this interface, register themselves, optionally provide a \\`WithInstance\\` function and pass the tests in package source/testing.\n\n## Variables\n\n```go\nvar (\n\tDefaultParse = Parse\n\tDefaultRegex = Regex\n)\n```\n\n```go\nvar (\n\tErrParse = fmt.Errorf(\"no match\")\n)\n```\n\n```go\nvar Regex = regexp.MustCompile(`^([0-9]+)_(.*)\\.(` + string(Down) + `|` + string(Up) + `)\\.(.*)$`)\n```\nRegex matches the following pattern:\n\n\t123_name.up.ext\n\t123_name.down.ext\n\n## Functions\n\n```go\nfunc List() []string\n```\nList lists the registered drivers\n\n```go\nfunc Register(name string, driver Driver)\n```\nRegister globally registers a driver.\n\n## Types\n\n```go\ntype Direction string\n```\nDirection is either up or down.\n\n```go\nconst (\n\tDown Direction = \"down\"\n\tUp   Direction = \"up\"\n)\n```\n\n```go\ntype Driver interface {\n\t// Open returns a a new driver instance configured with parameters\n\t// coming from the URL string. Migrate will call this function\n\t// only once per instance.\n\tOpen(url string) (Driver, error)\n\n\t// Close closes the underlying source instance managed by the driver.\n\t// Migrate will call this function only once per instance.\n\tClose() error\n\n\t// First returns the very first migration version available to the driver.\n\t// Migrate will call this function multiple times.\n\t// If there is no version available, it must return os.ErrNotExist.\n\tFirst() (version uint, err error)\n\n\t// Prev returns the previous version for a given version available to the driver.\n\t// Migrate will call this function multiple times.\n\t// If there is no previous version available, it must return os.ErrNotExist.\n\tPrev(version uint) (prevVersion uint, err error)\n\n\t// Next returns the next version for a given version available to the driver.\n\t// Migrate will call this function multiple times.\n\t// If there is no next version available, it must return os.ErrNotExist.\n\tNext(version uint) (nextVersion uint, err error)\n\n\t// ReadUp returns the UP migration body and an identifier that helps\n\t// finding this migration in the source for a given version.\n\t// If there is no up migration available for this version,\n\t// it must return os.ErrNotExist.\n\t// Do not start reading, just return the ReadCloser!\n\tReadUp(version uint) (r io.ReadCloser, identifier string, err error)\n\n\t// ReadDown returns the DOWN migration body and an identifier that helps\n\t// finding this migration in the source for a given version.\n\t// If there is no down migration available for this version,\n\t// it must return os.ErrNotExist.\n\t// Do not start reading, just return the ReadCloser!\n\tReadDown(version uint) (r io.ReadCloser, identifier string, err error)\n}\n```\nDriver is the interface every source driver must implement.\n\nHow to implement a source driver?\n\n 1. Implement this interface.\n 2. Optionally, add a function named \\`WithInstance\\`. This function should accept an existing source instance and a Config{} struct and return a driver instance.\n 3. Add a test that calls source/testing.go:Test()\n 4. Add own tests for Open(), WithInstance() (when provided) and Close(). All other functions are tested by tests in source/testing. Saves you some time and makes sure all source drivers behave the same way.\n 5. Call Register in init().\n\nGuidelines:\n\n  - All configuration input must come from the URL string in func Open() or the Config{} struct in WithInstance. Don't os.Getenv().\n  - Drivers are supposed to be read only.\n  - Ideally don't load any contents (into memory) in Open or WithInstance.\n\n```go\nfunc Open(url string) (Driver, error)\n```\nOpen returns a new driver instance.\n\n```go\ntype Migration struct {\n\t// Version is the version of this migration.\n\tVersion uint\n\n\t// Identifier can be any string that helps identifying\n\t// this migration in the source.\n\tIdentifier string\n\n\t// Direction is either Up or Down.\n\tDirection Direction\n\n\t// Raw holds the raw location path to this migration in source.\n\t// ReadUp and ReadDown will use this.\n\tRaw string\n}\n```\nMigration is a helper struct for source drivers that need to build the full directory tree in memory. Migration is fully independent from migrate.Migration.\n\n```go\nfunc Parse(raw string) (*Migration, error)\n```\nParse returns Migration for matching Regex pattern.\n\n```go\ntype Migrations struct {\n\t// contains filtered or unexported fields\n}\n```\nMigrations wraps Migration and has an internal index to keep track of Migration order.\n\n```go\nfunc NewMigrations() *Migrations\n```\n\n```go\nfunc (i *Migrations) Append(m *Migration) (ok bool)\n```\n\n```go\nfunc (i *Migrations) Down(version uint) (m *Migration, ok bool)\n```\n\n```go\nfunc (i *Migrations) First() (version uint, ok bool)\n```\n\n```go\nfunc (i *Migrations) Next(version uint) (nextVersion uint, ok bool)\n```\n\n```go\nfunc (i *Migrations) Prev(version uint) (prevVersion uint, ok bool)\n```\n\n```go\nfunc (i *Migrations) Up(version uint) (m *Migration, ok bool)\n```\n\n","path":"github.com/unity-technologies/migrate/source","name":"source","synopsis":"Package source provides the Source interface.","isRedistributable":true}
