Documentation ¶
Index ¶
- Constants
- Variables
- func GetDriverOpen(u *url.URL) (*sql.DB, error)
- func RunInLock(driver Driver, sqlDB *sql.DB, timeoutSecs int, ...) error
- type DB
- type Driver
- type MySQLDriver
- func (drv MySQLDriver) CreateDatabase(u *url.URL) error
- func (drv MySQLDriver) CreateMigrationsTable(db *sql.DB) error
- func (drv MySQLDriver) DatabaseExists(u *url.URL) (bool, error)
- func (drv MySQLDriver) DeleteMigration(db Transaction, version string) error
- func (drv MySQLDriver) DropDatabase(u *url.URL) error
- func (drv MySQLDriver) InsertMigration(db Transaction, version string, project string) error
- func (drv MySQLDriver) Lock(db *sql.DB) error
- func (drv MySQLDriver) Open(u *url.URL) (*sql.DB, error)
- func (drv MySQLDriver) SelectMigrations(db *sql.DB, limit int, project string) (map[string]bool, error)
- func (drv MySQLDriver) Unlock(db *sql.DB)
- type PostgresDriver
- func (drv PostgresDriver) CreateDatabase(u *url.URL) error
- func (drv PostgresDriver) CreateMigrationsTable(db *sql.DB) error
- func (drv PostgresDriver) DatabaseExists(u *url.URL) (bool, error)
- func (drv PostgresDriver) DeleteMigration(db Transaction, version string) error
- func (drv PostgresDriver) DropDatabase(u *url.URL) error
- func (drv PostgresDriver) InsertMigration(db Transaction, version string, project string) error
- func (drv PostgresDriver) Lock(db *sql.DB) error
- func (drv PostgresDriver) Open(u *url.URL) (*sql.DB, error)
- func (drv PostgresDriver) SelectMigrations(db *sql.DB, limit int, project string) (map[string]bool, error)
- func (drv PostgresDriver) Unlock(db *sql.DB)
- type SQLiteDriver
- func (drv SQLiteDriver) CreateDatabase(u *url.URL) error
- func (drv SQLiteDriver) CreateMigrationsTable(db *sql.DB) error
- func (drv SQLiteDriver) DatabaseExists(u *url.URL) (bool, error)
- func (drv SQLiteDriver) DeleteMigration(db Transaction, version string) error
- func (drv SQLiteDriver) DropDatabase(u *url.URL) error
- func (drv SQLiteDriver) InsertMigration(db Transaction, version string, project string) error
- func (drv SQLiteDriver) Lock(db *sql.DB) error
- func (drv SQLiteDriver) Open(u *url.URL) (*sql.DB, error)
- func (drv SQLiteDriver) SelectMigrations(db *sql.DB, limit int, project string) (map[string]bool, error)
- func (drv SQLiteDriver) Unlock(db *sql.DB)
- type Transaction
Constants ¶
const Version = "1.6.0"
Version of dbmate
Variables ¶
var DefaultMigrationsDir = "./db/migrations"
DefaultMigrationsDir specifies default directory to find migration files
var DefaultProject = "default"
DefaultProject specifies the default name to associate with the migrations
var LockTimeout = "30s"
LockTimeout is the Postgres time specification for how long we should wait for a lock before dying
Functions ¶
func GetDriverOpen ¶
GetDriverOpen is a shortcut for GetDriver(u.Scheme).Open(u)
Types ¶
type DB ¶
DB allows dbmate actions to be performed on a specified database
func (*DB) RecordOnly ¶
RecordOnly will record without applying all unapplied filesystem migrations
type Driver ¶
type Driver interface { Open(*url.URL) (*sql.DB, error) DatabaseExists(*url.URL) (bool, error) CreateDatabase(*url.URL) error DropDatabase(*url.URL) error CreateMigrationsTable(*sql.DB) error SelectMigrations(*sql.DB, int, string) (map[string]bool, error) InsertMigration(Transaction, string, string) error DeleteMigration(Transaction, string) error Lock(*sql.DB) error Unlock(*sql.DB) }
Driver provides top level database functions
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) InsertMigration ¶
func (drv MySQLDriver) InsertMigration(db Transaction, version string, project string) error
InsertMigration adds a new migration record
func (MySQLDriver) Lock ¶
func (drv MySQLDriver) Lock(db *sql.DB) error
Lock locks the database so no other migrations can be run, no-op in MySQL
func (MySQLDriver) SelectMigrations ¶
func (drv MySQLDriver) SelectMigrations(db *sql.DB, limit int, project string) (map[string]bool, error)
SelectMigrations returns a list of applied migrations with an optional limit (in descending order)
func (MySQLDriver) Unlock ¶
func (drv MySQLDriver) Unlock(db *sql.DB)
Unlock removes a database lock so other migrations can be run, no-op in MySQL
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) InsertMigration ¶
func (drv PostgresDriver) InsertMigration(db Transaction, version string, project string) error
InsertMigration adds a new migration record
func (PostgresDriver) Lock ¶
func (drv PostgresDriver) Lock(db *sql.DB) error
Lock tries to acquire an advisory lock and waits for the configured LockTimeout seconds before giving up
func (PostgresDriver) Open ¶
Open creates a new database connection, also setting a lock timeout to 30 seconds for the whole session.
func (PostgresDriver) SelectMigrations ¶
func (drv PostgresDriver) SelectMigrations(db *sql.DB, limit int, project string) (map[string]bool, error)
SelectMigrations returns a list of applied migrations with an optional limit (in descending order)
func (PostgresDriver) Unlock ¶
func (drv PostgresDriver) Unlock(db *sql.DB)
Unlock releases an advisory lock
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) InsertMigration ¶
func (drv SQLiteDriver) InsertMigration(db Transaction, version string, project string) error
InsertMigration adds a new migration record
func (SQLiteDriver) Lock ¶
func (drv SQLiteDriver) Lock(db *sql.DB) error
Lock locks the database so no other migrations can be run, no-op in SQLite
func (SQLiteDriver) SelectMigrations ¶
func (drv SQLiteDriver) SelectMigrations(db *sql.DB, limit int, project string) (map[string]bool, error)
SelectMigrations returns a list of applied migrations with an optional limit (in descending order)
func (SQLiteDriver) Unlock ¶
func (drv SQLiteDriver) Unlock(db *sql.DB)
Unlock removes a database lock so other migrations can be run, no-op in SQLite