Documentation
¶
Overview ¶
Package hawk provides a lightweight migration library.
Index ¶
- type Dialect
- type Engine
- func (e *Engine) AddMigration(num int64, name string, migration Migration)
- func (e *Engine) Down(version int64) (Result, error)
- func (e *Engine) GetVersion() (int64, error)
- func (e *Engine) ReadMigrationsFromDirectory(path string) error
- func (e *Engine) Rollback() (Result, error)
- func (e *Engine) Up() (Result, error)
- type Migration
- type MigrationReference
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dialect ¶
type Dialect interface { // CreateMigrationsTable sets up the database for use by Hawk. // // Dialects are free to determine how the migration state is // represented in the database, so long as the Dialect interface // can be satisfied. CreateMigrationsTable(db *sql.DB) error // GetVersion gets the number of the currently applied migration // from the database. // // If there are no currently applied migrations, this should return // -1 as the migration number and a nil error. GetVersion(db *sql.DB) (int64, error) // SetVersion sets the number of the currently applied migration in // the database. SetVersion(tx *sql.Tx, version int64) error }
A Dialect extracts SQL-specific implementation details, so that Hawk can support multiple SQL implementations.
type Engine ¶
func (*Engine) AddMigration ¶
AddMigration adds a migration to the engine.
Migrations are run in their numerical order (smallest to largest), with the name purely being used in the MigrationReference.
func (*Engine) Down ¶
Down un-applies the migration of the given migration and any applied migrations since then.
func (*Engine) GetVersion ¶
GetVersion gets the number of the currently applied migration from the database.
If there are no currently applied migrations, this will return -1 as the migration number and a nil error.
func (*Engine) ReadMigrationsFromDirectory ¶
ReadMigrationsFromDirectory reads migrations from a directory that uses golang-migrate's format.
type Migration ¶
type Migration interface { // Up applies to the database. Up(tx *sql.Tx) error // Down un-applies to the database. Down(tx *sql.Tx) error }
A Migration is an SQL transaction that can be both applied (up) and un-applied (down) to a database.
type MigrationReference ¶
MigrationReference refers to a registered migration.
type Result ¶
type Result struct { Version MigrationReference Skipped []MigrationReference Applied []MigrationReference }
Result keeps a record of what migrations have been applied or skipped when running migrations.