Documentation
¶
Index ¶
- Constants
- Variables
- type ErrInvalidMigration
- type Logger
- type Mariadb
- type Migratable
- type Migration
- type Migrator
- func NewMigrator(db *sql.DB, adapter Migratable, migrationsPath string) (*Migrator, error)
- func NewMigratorWithLogger(db *sql.DB, adapter Migratable, migrationsPath string, logger Logger) (*Migrator, error)
- func NewMigratorWithMigrations(db *sql.DB, adapter Migratable, migrations []*Migration) (*Migrator, error)
- func (m *Migrator) ApplyMigration(migration *Migration, mType migrationType) error
- func (m *Migrator) CreateMigrationsTable() error
- func (m *Migrator) Migrate() error
- func (m *Migrator) MigrationTableExists() (bool, error)
- func (m *Migrator) Migrations(status int) []*Migration
- func (m *Migrator) Rollback() error
- func (m *Migrator) RollbackAll() error
- func (m *Migrator) RollbackN(n int) error
- type Mysql
- type Postgres
- func (p Postgres) CreateMigrationTableSql() string
- func (p Postgres) GetMigrationCommands(sql string) []string
- func (p Postgres) GetMigrationSql() string
- func (p Postgres) MigrationLogDeleteSql() string
- func (p Postgres) MigrationLogInsertSql() string
- func (p Postgres) SelectMigrationTableSql() string
- type Sqlite3
Constants ¶
const ( Inactive = iota Active )
Migration statuses.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type ErrInvalidMigration ¶
ErrInvalidMigration encapsulates the reasons why a migration is invalid.
func (*ErrInvalidMigration) Error ¶
func (e *ErrInvalidMigration) Error() string
type Logger ¶
type Logger interface { Print(v ...interface{}) Printf(format string, v ...interface{}) Println(v ...interface{}) Fatalf(format string, v ...interface{}) }
Logger represents the standard logging interface allows different logging implementations to be used.
type Migratable ¶
type Migration ¶
Migration holds configuration information for a given migration.
func MigrationsFromPath ¶
MigrationsFromPath loads migrations from the given path. Migration file naming and format requires two files per migration of the form: NUMBER_NAME_[UP|DOWN].sql
Example:
1_add_users_table_up.sql 1_add_users_table_down.sql
The name must match for each numbered pair.
type Migrator ¶
type Migrator struct { DB *sql.DB MigrationsPath string Logger Logger // contains filtered or unexported fields }
Migrator contains the information needed to migrate a database schema.
func NewMigrator ¶
NewMigrator is the previous api for gomigrate. It loads migrations from disk and return a new migrator.
func NewMigratorWithLogger ¶
func NewMigratorWithLogger(db *sql.DB, adapter Migratable, migrationsPath string, logger Logger) (*Migrator, error)
NewMigratorWithLogger is the previous api for gomigrate. It loads migrations from disk and you can provide a Logger object.
func NewMigratorWithMigrations ¶
func NewMigratorWithMigrations(db *sql.DB, adapter Migratable, migrations []*Migration) (*Migrator, error)
NewMigratorWithMigrations returns a new Migrator setup with the given migrations. It validates the migrations (i.e. no duplicates) but doesn't connect to the database. All changes happen in the Migrate() function.
func (*Migrator) ApplyMigration ¶
ApplyMigration applies a single migration in the given direction.
func (*Migrator) CreateMigrationsTable ¶
CreateMigrationsTable creates the migrations table if it doesn't exist.
func (*Migrator) Migrate ¶
Migrate runs the given migrations against the database. It will also create the migration meta table if needed and will only run migrations that haven't already been run.
func (*Migrator) MigrationTableExists ¶
MigrationTableExists returns true if the migration table already exists.
func (*Migrator) Migrations ¶
Migrations returns a sorted list of migration ids for a given status. -1 returns all migrations.
func (*Migrator) RollbackAll ¶
RollbackAll rolls back all migrations.
type Mysql ¶
type Mysql struct{}
func (Mysql) CreateMigrationTableSql ¶
func (Mysql) GetMigrationCommands ¶
func (Mysql) GetMigrationSql ¶
func (Mysql) MigrationLogDeleteSql ¶
func (Mysql) MigrationLogInsertSql ¶
func (Mysql) SelectMigrationTableSql ¶
type Postgres ¶
type Postgres struct{}
func (Postgres) CreateMigrationTableSql ¶
func (Postgres) GetMigrationCommands ¶
func (Postgres) GetMigrationSql ¶
func (Postgres) MigrationLogDeleteSql ¶
func (Postgres) MigrationLogInsertSql ¶
func (Postgres) SelectMigrationTableSql ¶
type Sqlite3 ¶
type Sqlite3 struct{}