Documentation ¶
Index ¶
- Constants
- Variables
- func RegisterDriver(f DriverFunc, scheme string)
- type DB
- func (db *DB) Create() error
- func (db *DB) CreateAndMigrate() error
- func (db *DB) Driver() (Driver, error)
- func (db *DB) Drop() error
- func (db *DB) DumpSchema() error
- func (db *DB) FindMigrations() ([]Migration, error)
- func (db *DB) LoadSchema() 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 ParsedMigration
- type ParsedMigrationOptions
- type QueryError
- type StatusResult
Constants ¶
const Version = "2.15.0"
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'") ErrParseMissingDown = errors.New("dbmate requires each migration to define a down block with '-- migrate:down'") ErrParseWrongOrder = errors.New("dbmate requires '-- migrate:up' to appear before '-- migrate:down'") ErrParseUnexpectedStmt = errors.New("dbmate does not support statements preceding the '-- migrate:up' block") )
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 generates schema.sql after each action AutoDumpSchema bool // DatabaseURL is the database connection string DatabaseURL *url.URL // FS specifies the filesystem, or nil for OS filesystem FS fs.FS // Log is the interface to write stdout Log io.Writer // MigrationsDir specifies the directory or directories to find migration files MigrationsDir []string // MigrationsTableName specifies the database table to record migrations in MigrationsTableName string // SchemaFile specifies the location for schema.sql file SchemaFile string // Fail if migrations would be applied out of order Strict bool // Verbose prints the result of each statement execution Verbose bool // WaitBefore will wait for database to become available before running any actions WaitBefore bool // WaitInterval specifies length of time between connection attempts WaitInterval time.Duration // WaitTimeout specifies maximum time for connection attempts 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) FindMigrations ¶
FindMigrations lists all available migrations
func (*DB) LoadSchema ¶ added in v2.9.0
LoadSchema loads schema file to the current database
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 QueryError(string, error) error }
Driver provides top level database functions
type DriverConfig ¶
DriverConfig holds configuration passed to driver constructors
type DriverFunc ¶
type DriverFunc func(DriverConfig) Driver
DriverFunc represents a driver constructor
type ParsedMigration ¶
type ParsedMigration struct { Up string UpOptions ParsedMigrationOptions Down string DownOptions ParsedMigrationOptions }
ParsedMigration contains the migration contents and options
type ParsedMigrationOptions ¶
type ParsedMigrationOptions interface {
Transaction() bool
}
ParsedMigrationOptions is an interface for accessing migration options
type QueryError ¶ added in v2.8.0
func (*QueryError) Error ¶ added in v2.8.0
func (e *QueryError) Error() string
type StatusResult ¶
StatusResult represents an available migration status