Documentation
¶
Overview ¶
Package godfish is a database migration library built to support the command line tool.
Index ¶
- Variables
- func ApplyMigration(driver Driver, directoryPath string, forward bool, version string) (err error)
- func CreateMigrationFiles(migrationName string, reversible bool, dirpath, fwdlabel, revlabel string) (err error)
- func Info(driver Driver, directoryPath string, forward bool, finishAtVersion string, ...) (err error)
- func Init(pathToFile string) (err error)
- func Migrate(driver Driver, directoryPath string, forward bool, finishAtVersion string) (err error)
- type AppliedVersions
- type Driver
Constants ¶
This section is empty.
Variables ¶
var ErrSchemaMigrationsDoesNotExist = errors.New("schema migrations table does not exist")
ErrSchemaMigrationsDoesNotExist means there is no database table to record migration status.
Functions ¶
func ApplyMigration ¶
ApplyMigration runs a migration at directoryPath with the specified version and direction.
func CreateMigrationFiles ¶ added in v0.8.0
func CreateMigrationFiles(migrationName string, reversible bool, dirpath, fwdlabel, revlabel string) (err error)
CreateMigrationFiles takes care of setting up a new DB migration by generating empty migration files in a directory at dirpath. Passing in true for reversible means that a complementary file will be made for rollbacks. Names for directions in the filename could be overridden from their default values (forward and reverse) with the input vars fwdlabel, revlabel when non-empty.
func Info ¶
func Info(driver Driver, directoryPath string, forward bool, finishAtVersion string, w io.Writer, format string) (err error)
Info writes status of migrations to w in formats json or tsv.
Types ¶
type AppliedVersions ¶
AppliedVersions represents an iterative list of migrations that have been run against the database and have been recorded in the schema migrations table. It's enough to convert a *sql.Rows struct when implementing the Driver interface since a *sql.Rows already satisfies this interface. See existing Driver implementations in this package for examples.
type Driver ¶
type Driver interface { // Name should return the name of the driver: ie: postgres, mysql, etc Name() string // Connect should open a connection to the database. Connect(dsn string) error // Close should close the database connection. Close() error // AppliedVersions queries the schema migrations table for migration // versions that have been executed against the database. If the schema // migrations table does not exist, the returned error should be // ErrSchemaMigrationsDoesNotExist. AppliedVersions() (AppliedVersions, error) // CreateSchemaMigrationsTable should create a table to record migration // versions once they've been applied. The version should be a timestamp as // a string, formatted as the TimeFormat variable in this package. CreateSchemaMigrationsTable() error // Execute runs the schema change and commits it to the database. The query // parameter is a SQL string and may contain placeholders for the values in // args. Input should be passed to conn so it could be sanitized, escaped. Execute(query string, args ...interface{}) error // UpdateSchemaMigrations records a timestamped version of a migration that // has been successfully applied by adding a new row to the schema // migrations table. UpdateSchemaMigrations(forward bool, version string) error }
Driver adapts a database implementation to use godfish.
Directories
¶
Path | Synopsis |
---|---|
drivers
|
|
Package internal defines common functionality available within the library.
|
Package internal defines common functionality available within the library. |
cmd
Package cmd contains all the CLI stuff.
|
Package cmd contains all the CLI stuff. |
stub
Package stub implements godfish interfaces for testing purposes.
|
Package stub implements godfish interfaces for testing purposes. |