Documentation ¶
Index ¶
- Constants
- func GetDriverOpen(u *url.URL) (*sql.DB, error)
- func RegisterDriver(drv Driver, scheme string)
- type DB
- func (db *DB) Create() error
- func (db *DB) CreateAndMigrate() error
- func (db *DB) Drop() error
- func (db *DB) DumpSchema() error
- func (db *DB) GetDriver() (Driver, error)
- func (db *DB) Migrate() error
- func (db *DB) NewMigration(name string) error
- func (db *DB) Rollback() error
- func (db *DB) Wait() error
- 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) DumpSchema(u *url.URL, db *sql.DB) ([]byte, error)
- func (drv MySQLDriver) InsertMigration(db Transaction, version string) error
- func (drv MySQLDriver) Open(u *url.URL) (*sql.DB, error)
- func (drv MySQLDriver) Ping(u *url.URL) error
- func (drv MySQLDriver) SelectMigrations(db *sql.DB, limit int) (map[string]bool, error)
- 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) DumpSchema(u *url.URL, db *sql.DB) ([]byte, error)
- func (drv PostgresDriver) InsertMigration(db Transaction, version string) error
- func (drv PostgresDriver) Open(u *url.URL) (*sql.DB, error)
- func (drv PostgresDriver) Ping(u *url.URL) error
- func (drv PostgresDriver) SelectMigrations(db *sql.DB, limit int) (map[string]bool, error)
- 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) DumpSchema(u *url.URL, db *sql.DB) ([]byte, error)
- func (drv SQLiteDriver) InsertMigration(db Transaction, version string) error
- func (drv SQLiteDriver) Open(u *url.URL) (*sql.DB, error)
- func (drv SQLiteDriver) Ping(u *url.URL) error
- func (drv SQLiteDriver) SelectMigrations(db *sql.DB, limit int) (map[string]bool, error)
- type Transaction
Constants ¶
const DefaultMigrationsDir = "./db/migrations"
DefaultMigrationsDir specifies default directory to find migration files
const DefaultSchemaFile = "./db/schema.sql"
DefaultSchemaFile specifies default location for schema.sql
const DefaultWaitInterval = time.Second
DefaultWaitInterval specifies length of time between connection attempts
const DefaultWaitTimeout = 60 * time.Second
DefaultWaitTimeout specifies maximum time for connection attempts
const Version = "1.4.1"
Version of dbmate
Variables ¶
This section is empty.
Functions ¶
func GetDriverOpen ¶
GetDriverOpen is a shortcut for GetDriver(u.Scheme).Open(u)
func RegisterDriver ¶
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 (*DB) CreateAndMigrate ¶
CreateAndMigrate creates the database (if necessary) and runs migrations
func (*DB) DumpSchema ¶
DumpSchema writes the current database schema to a file
func (*DB) NewMigration ¶
NewMigration creates a new migration file
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
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 ¶
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) 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 ¶
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 ¶
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) 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 ¶
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 ¶
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) 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 ¶
SelectMigrations returns a list of applied migrations with an optional limit (in descending order)