Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterDriver(f DriverFunc, scheme string)
- type DB
- func (db *DB) CheckMigrationsStatus(drv Driver) ([]StatusResult, error)
- 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) Status(quiet bool) (int, error)
- func (db *DB) Wait() error
- type Driver
- type DriverConfig
- type DriverFunc
- type Migration
- type MigrationOptions
- type StatusResult
Constants ¶
const DefaultMigrationsDir = "./db/migrations"
DefaultMigrationsDir specifies default directory to find migration files
const DefaultMigrationsTableName = "schema_migrations"
DefaultMigrationsTableName specifies default database tables to record migraitons in
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.16.2"
Version of dbmate
Variables ¶
var ( ErrNoMigrationFiles = errors.New("no migration files found") ErrInvalidURL = errors.New("invalid url, have you set your --url flag or DATABASE_URL environment variable?") ErrNoRollback = errors.New("can't rollback: no migrations have been applied") ErrCantConnect = errors.New("unable to connect to database") ErrUnsupportedDriver = errors.New("unsupported driver") ErrNoMigrationName = errors.New("please specify a name for the new migration") ErrMigrationAlreadyExist = errors.New("file already exists") ErrMigrationDirNotFound = errors.New("could not find migrations directory") ErrMigrationNotFound = errors.New("can't find migration file") ErrCreateDirectory = errors.New("unable to create directory") )
Error codes
var ( ErrParseMissingUp = errors.New("dbmate requires each migration to define an up block with '-- migrate:up'") ErrParseUnexpectedStmt = errors.New("dbmate does not support statements defined outside of the '-- migrate:up' or '-- migrate:down' blocks") )
Error codes
Functions ¶
func RegisterDriver ¶
func RegisterDriver(f DriverFunc, scheme string)
RegisterDriver registers a driver constructor for a given URL scheme
Types ¶
type DB ¶
type DB struct { AutoDumpSchema bool DatabaseURL *url.URL MigrationsDir string MigrationsTableName string SchemaFile string Verbose bool WaitBefore bool WaitInterval time.Duration WaitTimeout time.Duration Log io.Writer }
DB allows dbmate actions to be performed on a specified database
func (*DB) CheckMigrationsStatus ¶ added in v1.11.0
func (db *DB) CheckMigrationsStatus(drv Driver) ([]StatusResult, error)
CheckMigrationsStatus returns the status of all available mgirations
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() (*sql.DB, error) DatabaseExists() (bool, error) CreateDatabase() error DropDatabase() error DumpSchema(*sql.DB) ([]byte, error) MigrationsTableExists(*sql.DB) (bool, error) CreateMigrationsTable(*sql.DB) error SelectMigrations(*sql.DB, int) (map[string]bool, error) InsertMigration(dbutil.Transaction, string) error DeleteMigration(dbutil.Transaction, string) error Ping() error }
Driver provides top level database functions
type DriverConfig ¶ added in v1.11.0
DriverConfig holds configuration passed to driver constructors
type DriverFunc ¶ added in v1.11.0
type DriverFunc func(DriverConfig) Driver
DriverFunc represents a driver constructor
type Migration ¶ added in v1.5.0
type Migration struct { Contents string Options MigrationOptions }
Migration contains the migration contents and options
func NewMigration ¶ added in v1.5.0
func NewMigration() Migration
NewMigration constructs a Migration object
type MigrationOptions ¶ added in v1.5.0
type MigrationOptions interface {
Transaction() bool
}
MigrationOptions is an interface for accessing migration options
type StatusResult ¶ added in v1.11.0
StatusResult represents an available migration status