Documentation ¶
Overview ¶
Package migration contains an implementation of a simple database migration mechanism that allows semi-automatic transitions between various database versions as well as building the latest version of the database from scratch.
Please look into README.md with further instructions how to use it.
Index ¶
- Constants
- func DowngradeTable(tx *sql.Tx, tableName, oldTableDefinition string, columns []string) error
- func InitDBSchema(db *sql.DB, schema Schema) error
- func InitInfoTable(db *sql.DB, schema Schema) error
- func SetDBVersion(db *sql.DB, dbDriver types.DBDriver, dbSchema Schema, targetVer Version, ...) error
- func UpdateTableData(tx *sql.Tx, table, query string, args ...interface{}) error
- func UpgradeTable(tx *sql.Tx, tableName, newTableDefinition string) error
- type Migration
- type Schema
- type Step
- type Version
Constants ¶
const (
// DriverUnsupportedErr error message indicating unsupported DB driver
DriverUnsupportedErr = "%v driver is not supported"
)
Variables ¶
This section is empty.
Functions ¶
func DowngradeTable ¶ added in v1.4.0
DowngradeTable downgrades table to oldTableDefinition. Set columns to the list of new columns if you're removing any columns
func InitDBSchema ¶ added in v1.4.0
InitDBSchema ensures that a given database schema exists. If it already exists, no changes will be made to the database, otherwise it will attempt to create the schema.
func InitInfoTable ¶
InitInfoTable ensures that the migration information table is created. If it already exists, no changes will be made to the database. Otherwise, a new migration information table will be created and initialized.
func SetDBVersion ¶
func SetDBVersion( db *sql.DB, dbDriver types.DBDriver, dbSchema Schema, targetVer Version, migrations []Migration, ) error
SetDBVersion attempts to get the database into the specified target version using available migration steps.
func UpdateTableData ¶ added in v1.4.0
UpdateTableData updates data and checks rows affected
Types ¶
type Migration ¶
Migration type describes a single Migration.
func NewUpdateTableMigration ¶
func NewUpdateTableMigration(tableName, previousSchema string, previousColumns []string, newSchema string) Migration
NewUpdateTableMigration generates a migration which changes tables schema and copies data (should work in most of cases like adding a field, altering it and so on) Set previousColumns to the list of previous columns if you're changing any columns