Documentation
¶
Index ¶
- Constants
- Variables
- func AddMigration(up func(*sql.Tx) error, down func(*sql.Tx) error)
- func AddNamedMigration(filename string, up func(*sql.Tx) error, down func(*sql.Tx) error)
- func Create(db *sql.DB, fs vfs.FileSystem, name, migrationType string) error
- func CreateWithTemplate(db *sql.DB, fs vfs.FileSystem, tmpl *template.Template, ...) error
- func Down(db *sql.DB, fs vfs.FileSystem) error
- func DownTo(db *sql.DB, fs vfs.FileSystem, version int64) error
- func EnsureDBVersion(db *sql.DB, schema string) (int64, error)
- func Fix(fs vfs.FileSystem) error
- func GetDBVersion(db *sql.DB, schema string) (int64, error)
- func NumericComponent(name string) (int64, error)
- func OpenDBWithDriver(driver string, dbstring string) (*sql.DB, error)
- func OpenDBWithDriverDialect(driver string, dbstring string, dconf DialectConfig) (*sql.DB, error)
- func Redo(db *sql.DB, fs vfs.FileSystem) error
- func Reset(db *sql.DB, fs vfs.FileSystem) error
- func Run(command string, db *sql.DB, fs vfs.FileSystem, args ...string) error
- func SetDialect(d string, opts ...DialectConfig) error
- func SetLogger(l Logger)
- func SetTableName(n string)
- func SetVerbose(v bool)
- func Status(db *sql.DB, fs vfs.FileSystem) error
- func TableName() string
- func Up(db *sql.DB, fs vfs.FileSystem) error
- func UpByOne(db *sql.DB, fs vfs.FileSystem) error
- func UpTo(db *sql.DB, fs vfs.FileSystem, version int64) error
- func Version(db *sql.DB, fs vfs.FileSystem) error
- type DialectConfig
- type Logger
- type Migration
- type MigrationRecord
- type Migrations
- func (ms *Migrations) Append(m *Migration)
- func (ms *Migrations) Current(current int64) (*Migration, error)
- func (ms *Migrations) Last() (*Migration, error)
- func (ms *Migrations) Len() int
- func (ms *Migrations) Less(i, j int) bool
- func (ms *Migrations) Next(current int64) (*Migration, error)
- func (ms *Migrations) Previous(current int64) (*Migration, error)
- func (ms *Migrations) String() string
- func (ms *Migrations) Swap(i, j int)
- type MySQLDialect
- type PostgresDialect
- type RedshiftDialect
- type SQLDialect
- type SQLSchemaDialect
- type SqlServerDialect
- type Sqlite3Dialect
- type TiDBDialect
Constants ¶
const VERSION = "v2.7.0-rc3"
Variables ¶
var ( // ErrNoCurrentVersion when a current migration version is not found. ErrNoCurrentVersion = errors.New("no current version found") // ErrNoNextVersion when the next migration version is not found. ErrNoNextVersion = errors.New("no next version found") // MaxVersion is the maximum allowed version. MaxVersion int64 = 9223372036854775807 // max(int64) )
Functions ¶
func AddMigration ¶
AddMigration adds a migration.
func AddNamedMigration ¶
AddNamedMigration : Add a named migration.
func CreateWithTemplate ¶
func CreateWithTemplate(db *sql.DB, fs vfs.FileSystem, tmpl *template.Template, name, migrationType string) error
Create writes a new blank migration file.
func Down ¶
func Down(db *sql.DB, fs vfs.FileSystem) error
Down rolls back a single migration from the current version.
func EnsureDBVersion ¶
EnsureDBVersion retrieves the current version for this DB. Create and initialize the DB version table if it doesn't exist.
func Fix ¶
func Fix(fs vfs.FileSystem) error
FIXME: Fix() may need to be reconsidered or dropped as there's no easy way to make this portable across all VFSes (especially for embedded migrations).
func GetDBVersion ¶
GetDBVersion is an alias for EnsureDBVersion, but returns -1 in error.
func NumericComponent ¶
NumericComponent looks for migration scripts with names in the form: XXX_descriptivename.ext where XXX specifies the version number and ext specifies the type of migration
func OpenDBWithDriver ¶
OpenDBWithDriver creates a connection a database, and modifies goose internals to be compatible with the supplied driver by calling SetDialect.
func OpenDBWithDriverDialect ¶
func Redo ¶
func Redo(db *sql.DB, fs vfs.FileSystem) error
Redo rolls back the most recently applied migration, then runs it again.
func SetDialect ¶
func SetDialect(d string, opts ...DialectConfig) error
SetDialect sets the SQLDialect
func Status ¶
func Status(db *sql.DB, fs vfs.FileSystem) error
Status prints the status of all migrations.
func UpByOne ¶
func UpByOne(db *sql.DB, fs vfs.FileSystem) error
UpByOne migrates up by a single version.
Types ¶
type DialectConfig ¶
type DialectConfig struct { // UseSchemas toggles schemas for backends that support them. UseSchemas bool // SchemaDir indicates whether the schema name should be derived from the // directory containing the migrations list. SchemaDir bool // SchemaEnvVar extracts the schema name from the environment variable // specified here if it exists and is set. If this value isn't configured, // the envvar SCHEMA_NAME will be used if present. SchemaEnvVar string // Schema name to use for this connection. Schema string }
type Logger ¶
type Logger interface { Fatal(v ...interface{}) Fatalf(format string, v ...interface{}) Print(v ...interface{}) Println(v ...interface{}) Printf(format string, v ...interface{}) }
Logger is standard logger interface
type Migration ¶
type Migration struct { Version int64 Next int64 // next version, or -1 if none Previous int64 // previous version, -1 if none Source string // path to .sql script Schema string Registered bool UpFn func(*sql.Tx) error // Up go migration function DownFn func(*sql.Tx) error // Down go migration function }
Migration struct.
type MigrationRecord ¶
type MigrationRecord struct { VersionID int64 IsApplied bool // was this a result of up() or down() UsingSchema string TStamp time.Time }
MigrationRecord struct.
type Migrations ¶
type Migrations struct {
// contains filtered or unexported fields
}
func CollectMigrations ¶
func CollectMigrations(fs vfs.FileSystem, current, target int64) (*Migrations, error)
CollectMigrations returns all the valid looking migration scripts in the migrations folder and go func registry, and key them by version.
func (*Migrations) Append ¶
func (ms *Migrations) Append(m *Migration)
func (*Migrations) Current ¶
func (ms *Migrations) Current(current int64) (*Migration, error)
Current gets the current migration.
func (*Migrations) Last ¶
func (ms *Migrations) Last() (*Migration, error)
Last gets the last migration.
func (*Migrations) Less ¶
func (ms *Migrations) Less(i, j int) bool
func (*Migrations) Next ¶
func (ms *Migrations) Next(current int64) (*Migration, error)
Next gets the next migration.
func (*Migrations) Previous ¶
func (ms *Migrations) Previous(current int64) (*Migration, error)
Previous : Get the previous migration.
func (*Migrations) String ¶
func (ms *Migrations) String() string
func (*Migrations) Swap ¶
func (ms *Migrations) Swap(i, j int)
type SQLDialect ¶
type SQLDialect interface {
// contains filtered or unexported methods
}
SQLDialect abstracts the details of specific SQL dialects for goose's few SQL specific statements
type SQLSchemaDialect ¶
type SQLSchemaDialect interface { SQLDialect // contains filtered or unexported methods }