core

package
v0.0.0-...-3568023 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2016 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
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

func CreateMigrationsTable(db *sql.DB)

CreateMigrationsTable creates the migrations table based on the driver specific sql.

func DBConnection

func DBConnection(ymlFile []byte, environment string) (*sql.DB, error)

DBConnection Returns a DB connection from the yml config file

func DBConnectionWith

func DBConnectionWith(databaseURL, driver string) (*sql.DB, error)

DBConnection Returns a DB connection from the yml config file

func DatabaseVersion

func DatabaseVersion(db *sql.DB) string

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

func MigrationsTableExists(db *sql.DB) bool

MigrationsTableExists returns true if the table for the migrations already exists.

func RunAllMigrationsUp

func RunAllMigrationsUp(db *sql.DB)

RunAllMigrationsUp runs pending migrations and stores migration on the migrations table.

func RunMigrationDown

func RunMigrationDown(db *sql.DB, m *Migration) error

RunMigrationDown Runs one migration down and if successful it removes the migration from the migrations table.

func RunMigrationUp

func RunMigrationUp(db *sql.DB, m *Migration) error

RunMigrationUp runs a single migration up and if success it saves the Migration identifier on the migrations table.

func RunOneMigrationDown

func RunOneMigrationDown(db *sql.DB)

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

type Migration struct {
	Identifier int64
	Name       string
	Up         func(tx *Tx)
	Down       func(tx *Tx)
}

Migration represents migrations we will run up and down.

func (*Migration) GetID

func (m *Migration) GetID() string

GetID Returns a string representation of the migration identifier.

func (*Migration) Pending

func (m *Migration) Pending(db *sql.DB) bool

Pending returns if a particular migration is pending. TODO: move it to be vendor specific inside the managers.

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

func (tx *Tx) AddColumn(name string, columnName string, tipe string) (sql.Result, error)

AddColumn allows us to add columns to tables by passing column name and type.

func (*Tx) ChangeColumnType

func (tx *Tx) ChangeColumnType(name string, columnName string, newType string) (sql.Result, error)

ChangeColumnType provides an interface to change columns types.

func (*Tx) CreateTable

func (tx *Tx) CreateTable(name string, columns managers.Table) (sql.Result, error)

CreateTable allows us to create tables by passing a table definition and the table name.

func (*Tx) DropColumn

func (tx *Tx) DropColumn(name string, columnName string) (sql.Result, error)

DropColumn allows us to drop columns by passing column name on table

func (*Tx) DropTable

func (tx *Tx) DropTable(name string) (sql.Result, error)

DropTable function drops a particular table from the database based on the driver implementation.

func (*Tx) Exec

func (tx *Tx) Exec(query string) (sql.Result, error)

Exec is a wrapper to the Exec function inside sql.Tx.

func (*Tx) RenameColumn

func (tx *Tx) RenameColumn(name string, columnName string, newName string) (sql.Result, error)

RenameColumn provides an interface to change columns names.

func (*Tx) RenameTable

func (tx *Tx) RenameTable(name string, newName string) (sql.Result, error)

RenameTable provides an interface to change columns names.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL