Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Migration ¶
type Migration struct { // The required timestamp string for the migration. // The format is arbitrary but must be orderable using standard string comparison. Timestamp string // An optional string that will be displayed alongside the timestamp in logs. Description string // Implementation of the Migrator interface. Migrator Migrator }
Migration is a struct that represents a single migration.
type MigrationCRUD ¶
type MigrationCRUD interface { // Setup performs setup operations needed before other CRUD operations can be used. // Returns any errors. // // For example, this method can create a migrations table if it does not already exist. Setup() error // CreateMigration creates a new migration with the given timestamp and returns any errors. CreateMigration(timestamp string) error // GetLatestTimestamp returns the latest timestamp of all migrations. // If no timestamps are found then hasLatest should be false, else it should be true. // Also returns any errors encountered. GetLatestTimestamp() (timestamp string, hasLatest bool, err error) // DeleteMigrationByTimestamp deletes the migration with the given timestamp and returns any errors. DeleteMigrationByTimestamp(timestamp string) error }
MigrationCRUD is an interface for performing CRUD (Create, Read, Update, Delete) operations on a migration.
This interface should be implemented as a wrapper for your data solution.
type MigrationRepository ¶
type MigrationRepository interface { // GetMigrations returns a slice of migrations to run. // This can be a hard coded list, or perhaps loaded from some other source. GetMigrations() []Migration }
MigrationRepository is an interface for fetching the migrations to run.
type MigrationRunner ¶ added in v0.2.0
type MigrationRunner struct { // Implementation of the MigrationRepository interface that will fetch the migrations to run. MigrationRepository MigrationRepository // Implementation of the MigrationCRUD interface that will perform the CRUD operations on the data solution. MigrationCRUD MigrationCRUD }
func (MigrationRunner) MigrateDown ¶ added in v0.2.0
func (m MigrationRunner) MigrateDown() error
MigrateDown runs the Down method for the migration whose timestamp matches the latest timestamp returned by MigrationCRUD.GetLatestTimestamp.
If there is no latest timestamp, an error will be returned. Will also return any other errors that are encountered.
func (MigrationRunner) MigrateUp ¶ added in v0.2.0
func (m MigrationRunner) MigrateUp() error
MigrateUp runs the Up method for all migrations returned by the MigrationRepository that are newer than the timestamp fetched by MigrationCRUD.GetLatestTimestamp. This will trigger a call to MigrationCRUD.CreateMigration for every one that's run.
If there is no latest timestamp, all migrations will be run.
If any errors are encountered, the whole function will be aborted and any migrations yet to run will not be run. Returns any such errors encountered.
type Migrator ¶ added in v1.1.0
type Migrator interface { // Up runs the migration and returns any errors. Up() error // Down runs the inverse migration and returns any errors. Down() error }
Migrator is an interface for running a migration.
A new struct that implements this interface should be created for each migration. Any additional dependencies required to run your migrations can be added as fields to this struct.