Documentation
¶
Overview ¶
Package dbmigrator is yet another library to migrate database schemas.
It saves the current migration version directly in the database. There is also support for the go-bindata program.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrCorruptDatabase = errors.New("failed to retrieve migration version from setting table (database not empty)")
ErrCorruptDatabase is returned when the setting table does not have the migration_version key or another database error occured while retrieving the migration version.
var ErrNoMigrationFiles = errors.New("migration directory does not contain any valid migration files")
ErrNoMigrationFiles is returned when there are no files in the directory that match the required filename pattern.
Functions ¶
This section is empty.
Types ¶
type MigrationConfig ¶
type MigrationConfig struct {
Asset func(name string) ([]byte, error)
AssetDir func(name string) ([]string, error)
AssetInfo func(name string) (os.FileInfo, error)
DataSourceName string
DriverName string
MigrationsPath string
Quiet bool
SettingTableCreateStatement string
}
MigrationConfig contains the configuration for the migrator. The use of Asset, AssetDir and AssetInfo functions is optional, but if you set a value for either of them, you have to set values for all of them. If you leave SettingTableCreateStatement empty, the default create statement will be used.
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator contains the migrations to apply to the database.
func NewMigrator ¶
func NewMigrator(config MigrationConfig) (Migrator, error)
NewMigrator returns a new migrator. It reads all migrations (files) in the migration path that match the "YYYY-MM-DD hhmmss *.sql" filename format and sorts them.
func (*Migrator) Migrate ¶
Migrate applies all new migrations to the database. After each successful migration it will update the "migration_version" key in the setting table to the corresponding migration version. If there is an error while applying a migration, the operation is canceled (but not rolled back).