dbmate

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2018 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMigrationsDir = "./db/migrations"

DefaultMigrationsDir specifies default directory to find migration files

View Source
const DefaultSchemaFile = "./db/schema.sql"

DefaultSchemaFile specifies default location for schema.sql

View Source
const DefaultWaitInterval = time.Second

DefaultWaitInterval specifies length of time between connection attempts

View Source
const DefaultWaitTimeout = 60 * time.Second

DefaultWaitTimeout specifies maximum time for connection attempts

View Source
const Version = "1.4.1"

Version of dbmate

Variables

This section is empty.

Functions

func GetDriverOpen

func GetDriverOpen(u *url.URL) (*sql.DB, error)

GetDriverOpen is a shortcut for GetDriver(u.Scheme).Open(u)

func RegisterDriver

func RegisterDriver(drv Driver, scheme string)

RegisterDriver registers a driver for a URL scheme

Types

type DB

type DB struct {
	AutoDumpSchema bool
	DatabaseURL    *url.URL
	MigrationsDir  string
	SchemaFile     string
	WaitInterval   time.Duration
	WaitTimeout    time.Duration
}

DB allows dbmate actions to be performed on a specified database

func New

func New(databaseURL *url.URL) *DB

New initializes a new dbmate database

func (*DB) Create

func (db *DB) Create() error

Create creates the current database

func (*DB) CreateAndMigrate

func (db *DB) CreateAndMigrate() error

CreateAndMigrate creates the database (if necessary) and runs migrations

func (*DB) Drop

func (db *DB) Drop() error

Drop drops the current database (if it exists)

func (*DB) DumpSchema

func (db *DB) DumpSchema() error

DumpSchema writes the current database schema to a file

func (*DB) GetDriver

func (db *DB) GetDriver() (Driver, error)

GetDriver loads the required database driver

func (*DB) Migrate

func (db *DB) Migrate() error

Migrate migrates database to the latest version

func (*DB) NewMigration

func (db *DB) NewMigration(name string) error

NewMigration creates a new migration file

func (*DB) Rollback

func (db *DB) Rollback() error

Rollback rolls back the most recent migration

func (*DB) Wait added in v1.4.0

func (db *DB) Wait() error

Wait blocks until the database server is available. It does not verify that the specified database exists, only that the host is ready to accept connections.

type Driver

type Driver interface {
	Open(*url.URL) (*sql.DB, error)
	DatabaseExists(*url.URL) (bool, error)
	CreateDatabase(*url.URL) error
	DropDatabase(*url.URL) error
	DumpSchema(*url.URL, *sql.DB) ([]byte, error)
	CreateMigrationsTable(*sql.DB) error
	SelectMigrations(*sql.DB, int) (map[string]bool, error)
	InsertMigration(Transaction, string) error
	DeleteMigration(Transaction, string) error
	Ping(*url.URL) error
}

Driver provides top level database functions

func GetDriver

func GetDriver(name string) (Driver, error)

GetDriver loads a database driver by name

type MySQLDriver

type MySQLDriver struct {
}

MySQLDriver provides top level database functions

func (MySQLDriver) CreateDatabase

func (drv MySQLDriver) CreateDatabase(u *url.URL) error

CreateDatabase creates the specified database

func (MySQLDriver) CreateMigrationsTable

func (drv MySQLDriver) CreateMigrationsTable(db *sql.DB) error

CreateMigrationsTable creates the schema_migrations table

func (MySQLDriver) DatabaseExists

func (drv MySQLDriver) DatabaseExists(u *url.URL) (bool, error)

DatabaseExists determines whether the database exists

func (MySQLDriver) DeleteMigration

func (drv MySQLDriver) DeleteMigration(db Transaction, version string) error

DeleteMigration removes a migration record

func (MySQLDriver) DropDatabase

func (drv MySQLDriver) DropDatabase(u *url.URL) error

DropDatabase drops the specified database (if it exists)

func (MySQLDriver) DumpSchema

func (drv MySQLDriver) DumpSchema(u *url.URL, db *sql.DB) ([]byte, error)

DumpSchema returns the current database schema

func (MySQLDriver) InsertMigration

func (drv MySQLDriver) InsertMigration(db Transaction, version string) error

InsertMigration adds a new migration record

func (MySQLDriver) Open

func (drv MySQLDriver) Open(u *url.URL) (*sql.DB, error)

Open creates a new database connection

func (MySQLDriver) Ping added in v1.4.0

func (drv MySQLDriver) Ping(u *url.URL) error

Ping verifies a connection to the database server. It does not verify whether the specified database exists.

func (MySQLDriver) SelectMigrations

func (drv MySQLDriver) SelectMigrations(db *sql.DB, limit int) (map[string]bool, error)

SelectMigrations returns a list of applied migrations with an optional limit (in descending order)

type PostgresDriver

type PostgresDriver struct {
}

PostgresDriver provides top level database functions

func (PostgresDriver) CreateDatabase

func (drv PostgresDriver) CreateDatabase(u *url.URL) error

CreateDatabase creates the specified database

func (PostgresDriver) CreateMigrationsTable

func (drv PostgresDriver) CreateMigrationsTable(db *sql.DB) error

CreateMigrationsTable creates the schema_migrations table

func (PostgresDriver) DatabaseExists

func (drv PostgresDriver) DatabaseExists(u *url.URL) (bool, error)

DatabaseExists determines whether the database exists

func (PostgresDriver) DeleteMigration

func (drv PostgresDriver) DeleteMigration(db Transaction, version string) error

DeleteMigration removes a migration record

func (PostgresDriver) DropDatabase

func (drv PostgresDriver) DropDatabase(u *url.URL) error

DropDatabase drops the specified database (if it exists)

func (PostgresDriver) DumpSchema

func (drv PostgresDriver) DumpSchema(u *url.URL, db *sql.DB) ([]byte, error)

DumpSchema returns the current database schema

func (PostgresDriver) InsertMigration

func (drv PostgresDriver) InsertMigration(db Transaction, version string) error

InsertMigration adds a new migration record

func (PostgresDriver) Open

func (drv PostgresDriver) Open(u *url.URL) (*sql.DB, error)

Open creates a new database connection

func (PostgresDriver) Ping added in v1.4.0

func (drv PostgresDriver) Ping(u *url.URL) error

Ping verifies a connection to the database server. It does not verify whether the specified database exists.

func (PostgresDriver) SelectMigrations

func (drv PostgresDriver) SelectMigrations(db *sql.DB, limit int) (map[string]bool, error)

SelectMigrations returns a list of applied migrations with an optional limit (in descending order)

type SQLiteDriver

type SQLiteDriver struct {
}

SQLiteDriver provides top level database functions

func (SQLiteDriver) CreateDatabase

func (drv SQLiteDriver) CreateDatabase(u *url.URL) error

CreateDatabase creates the specified database

func (SQLiteDriver) CreateMigrationsTable

func (drv SQLiteDriver) CreateMigrationsTable(db *sql.DB) error

CreateMigrationsTable creates the schema_migrations table

func (SQLiteDriver) DatabaseExists

func (drv SQLiteDriver) DatabaseExists(u *url.URL) (bool, error)

DatabaseExists determines whether the database exists

func (SQLiteDriver) DeleteMigration

func (drv SQLiteDriver) DeleteMigration(db Transaction, version string) error

DeleteMigration removes a migration record

func (SQLiteDriver) DropDatabase

func (drv SQLiteDriver) DropDatabase(u *url.URL) error

DropDatabase drops the specified database (if it exists)

func (SQLiteDriver) DumpSchema

func (drv SQLiteDriver) DumpSchema(u *url.URL, db *sql.DB) ([]byte, error)

DumpSchema returns the current database schema

func (SQLiteDriver) InsertMigration

func (drv SQLiteDriver) InsertMigration(db Transaction, version string) error

InsertMigration adds a new migration record

func (SQLiteDriver) Open

func (drv SQLiteDriver) Open(u *url.URL) (*sql.DB, error)

Open creates a new database connection

func (SQLiteDriver) Ping added in v1.4.0

func (drv SQLiteDriver) Ping(u *url.URL) error

Ping verifies a connection to the database. Due to the way SQLite works, by testing whether the database is valid, it will automatically create the database if it does not already exist.

func (SQLiteDriver) SelectMigrations

func (drv SQLiteDriver) SelectMigrations(db *sql.DB, limit int) (map[string]bool, error)

SelectMigrations returns a list of applied migrations with an optional limit (in descending order)

type Transaction

type Transaction interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
}

Transaction can represent a database or open transaction

Jump to

Keyboard shortcuts

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