Documentation ¶
Index ¶
- Constants
- func Add(m Migration)
- func CreateMigrationsTable(db *sql.DB)
- func DBConnection(ymlFile []byte, environment string) (*sql.DB, error)
- func DBConnectionWith(databaseURL, driver string) (*sql.DB, error)
- func DatabaseVersion(db *sql.DB) string
- func MigrationIdentifier() int64
- func MigrationsTableExists(db *sql.DB) bool
- func RunAllMigrationsUp(db *sql.DB)
- func RunMigrationDown(db *sql.DB, m *Migration) error
- func RunMigrationUp(db *sql.DB, m *Migration) error
- func RunOneMigrationDown(db *sql.DB)
- func SetManager(man managers.DatabaseManager)
- type ByIdentifier
- type Migration
- type Tx
- func (tx *Tx) AddColumn(name string, columnName string, tipe string) (sql.Result, error)
- func (tx *Tx) ChangeColumnType(name string, columnName string, newType string) (sql.Result, error)
- func (tx *Tx) CreateTable(name string, columns managers.Table) (sql.Result, error)
- func (tx *Tx) DropColumn(name string, columnName string) (sql.Result, error)
- func (tx *Tx) DropTable(name string) (sql.Result, error)
- func (tx *Tx) Exec(query string) (sql.Result, error)
- func (tx *Tx) RenameColumn(name string, columnName string, newName string) (sql.Result, error)
- func (tx *Tx) RenameTable(name string, newName string) (sql.Result, error)
Constants ¶
const (
// MigrationsTable is the Db table where we will store migrations
MigrationsTable = "transporter_migrations"
)
Variables ¶
This section is empty.
Functions ¶
func Add ¶
func Add(m Migration)
Add function adds a migration to the migrations array So Transporter verifies if the migration is already completed or runs the desired migration as needed.
Register checks if migration attempted to be registered id is unique.
func CreateMigrationsTable ¶
CreateMigrationsTable creates the migrations table based on the driver specific sql.
func DBConnection ¶
DBConnection Returns a DB connection from the yml config file
func DBConnectionWith ¶
DBConnection Returns a DB connection from the yml config file
func DatabaseVersion ¶
DatabaseVersion returns the latest database version.
func MigrationIdentifier ¶
func MigrationIdentifier() int64
MigrationIdentifier returns a unixnano used to identify the order of the migration.
func MigrationsTableExists ¶
MigrationsTableExists returns true if the table for the migrations already exists.
func RunAllMigrationsUp ¶
RunAllMigrationsUp runs pending migrations and stores migration on the migrations table.
func RunMigrationDown ¶
RunMigrationDown Runs one migration down and if successful it removes the migration from the migrations table.
func RunMigrationUp ¶
RunMigrationUp runs a single migration up and if success it saves the Migration identifier on the migrations table.
func RunOneMigrationDown ¶
RunOneMigrationDown Run down last migration that have completed.
func SetManager ¶
func SetManager(man managers.DatabaseManager)
SetManager allows external entities like testing to set the driver as needed.
Types ¶
type ByIdentifier ¶
type ByIdentifier []Migration
ByIdentifier is a specific order that causes first-created migrations to run first based on the identifier.
func (ByIdentifier) Len ¶
func (a ByIdentifier) Len() int
func (ByIdentifier) Less ¶
func (a ByIdentifier) Less(i, j int) bool
func (ByIdentifier) Swap ¶
func (a ByIdentifier) Swap(i, j int)
type Migration ¶
Migration represents migrations we will run up and down.
type Tx ¶
type Tx struct { *sql.Tx Manager managers.DatabaseManager // contains filtered or unexported fields }
Tx is our implementation of the sql.Tx, we did this to make the sql errors visible to transporter user when the databse operation fails.
func (*Tx) AddColumn ¶
AddColumn allows us to add columns to tables by passing column name and type.
func (*Tx) ChangeColumnType ¶
ChangeColumnType provides an interface to change columns types.
func (*Tx) CreateTable ¶
CreateTable allows us to create tables by passing a table definition and the table name.
func (*Tx) DropColumn ¶
DropColumn allows us to drop columns by passing column name on table
func (*Tx) DropTable ¶
DropTable function drops a particular table from the database based on the driver implementation.
func (*Tx) RenameColumn ¶
RenameColumn provides an interface to change columns names.