Involved Source Files
Package 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.
migration.goparse.go
Package-Level Type Names (total 5, in which 4 are exported)
/* sort exporteds by: | */
Direction is either up or down.
const Down
const Up
Driver is the interface every source driver must implement.
How to implement a source driver?
1. Implement this interface.
2. Optionally, add a function named `WithInstance`.
This function should accept an existing source instance and a Config{} struct
and return a driver instance.
3. Add a test that calls source/testing.go:Test()
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.
5. Call Register in init().
Guidelines:
* All configuration input must come from the URL string in func Open()
or the Config{} struct in WithInstance. Don't os.Getenv().
* Drivers are supposed to be read only.
* Ideally don't load any contents (into memory) in Open or WithInstance.
Close closes the underlying source instance managed by the driver.
Migrate will call this function only once per instance.
First returns the very first migration version available to the driver.
Migrate will call this function multiple times.
If there is no version available, it must return os.ErrNotExist.
Next returns the next version for a given version available to the driver.
Migrate will call this function multiple times.
If there is no next version available, it must return os.ErrNotExist.
Open returns a a new driver instance configured with parameters
coming from the URL string. Migrate will call this function
only once per instance.
Prev returns the previous version for a given version available to the driver.
Migrate will call this function multiple times.
If there is no previous version available, it must return os.ErrNotExist.
ReadDown returns the DOWN migration body and an identifier that helps
finding this migration in the source for a given version.
If there is no down migration available for this version,
it must return os.ErrNotExist.
Do not start reading, just return the ReadCloser!
ReadUp returns the UP migration body and an identifier that helps
finding this migration in the source for a given version.
If there is no up migration available for this version,
it must return os.ErrNotExist.
Do not start reading, just return the ReadCloser!
*github.com/golang-migrate/migrate/v4/source/file.File
T : io.Closer
func Open(url string) (Driver, error)
func Driver.Open(url string) (Driver, error)
func github.com/golang-migrate/migrate/v4/source/file.(*File).Open(url string) (Driver, error)
func Register(name string, driver Driver)
func github.com/golang-migrate/migrate/v4.NewWithInstance(sourceName string, sourceInstance Driver, databaseName string, databaseInstance database.Driver) (*migrate.Migrate, error)
func github.com/golang-migrate/migrate/v4.NewWithSourceInstance(sourceName string, sourceInstance Driver, databaseURL string) (*migrate.Migrate, error)
Migration is a helper struct for source drivers that need to
build the full directory tree in memory.
Migration is fully independent from migrate.Migration.
Direction is either Up or Down.
Identifier can be any string that helps identifying
this migration in the source.
Raw holds the raw location path to this migration in source.
ReadUp and ReadDown will use this.
Version is the version of this migration.
func Parse(raw string) (*Migration, error)
func (*Migrations).Down(version uint) (m *Migration, ok bool)
func (*Migrations).Up(version uint) (m *Migration, ok bool)
func (*Migrations).Append(m *Migration) (ok bool)
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.