Documentation ¶
Index ¶
- Variables
- func CreateMigration(name, migrationType, dir string, t time.Time) (path string, err error)
- func EnsureDBVersion(conf *DBConf, db *sql.DB) (int64, error)
- func GetDBVersion(conf *DBConf) (version int64, err error)
- func GetMostRecentDBVersion(dirpath string) (version int64, err error)
- func GetPreviousDBVersion(dirpath string, version int64) (previous int64, err error)
- func NumericComponent(name string) (int64, error)
- func Run(arguments ...string)
- func RunMigrations(conf *DBConf, migrationsDir string, target int64) (err error)
- type Command
- type CreateDBDriver
- type CreateSqlDialect
- type DBConf
- type DBDriver
- type MSSQLDialect
- type Migration
- type MigrationRecord
- type MySqlDialect
- type PostgresDialect
- type SqlDialect
- type Sqlite3Dialect
- type StatusData
Constants ¶
This section is empty.
Variables ¶
var ( ErrTableDoesNotExist = errors.New("table does not exist") ErrNoPreviousVersion = errors.New("no previous version found") )
var Commands = []*Command{
upCmd,
downCmd,
redoCmd,
statusCmd,
createCmd,
dbVersionCmd,
cleanCmd,
resetCmd,
}
var (
DBDrivers = map[string]CreateDBDriver{}
)
var GooseFlagSet = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
global options. available to any subcommands.
var ReadDbConf func() (*DBConf, error)
var ( SqlDialects = map[string]CreateSqlDialect{"postgres": func() SqlDialect { return &PostgresDialect{} }, "mysql": func() SqlDialect { return &MySqlDialect{} }, "sqlite": func() SqlDialect { return &Sqlite3Dialect{} }} )
Functions ¶
func CreateMigration ¶
func EnsureDBVersion ¶
retrieve the current version for this DB. Create and initialize the DB version table if it doesn't exist.
func GetDBVersion ¶
wrapper for EnsureDBVersion for callers that don't already have their own DB instance
func GetMostRecentDBVersion ¶
helper to identify the most recent possible version within a folder of migration scripts
func GetPreviousDBVersion ¶
func NumericComponent ¶
look for migration scripts with names in the form:
XXX_descriptivename.ext
where XXX specifies the version number and ext specifies the type of migration
Types ¶
type Command ¶
type Command struct { Run func(cmd *Command, args ...string) Flag flag.FlagSet Name string Usage string Summary string Help string }
shamelessly snagged from the go tool each command gets its own set of args, defines its own entry point, and provides its own help
type CreateDBDriver ¶
type CreateSqlDialect ¶
type CreateSqlDialect func() SqlDialect
type DBDriver ¶
type DBDriver struct { Name string OpenStr string Import string Dialect SqlDialect }
DBDriver encapsulates the info needed to work with a specific database driver
func NewDBDriver ¶
Create a new DBDriver and populate driver specific fields for drivers that we know about. Further customization may be done in NewDBConf
type MSSQLDialect ¶
type MSSQLDialect struct{}
func (*MSSQLDialect) CreateVersionTableSql ¶
func (pg *MSSQLDialect) CreateVersionTableSql() string
func (*MSSQLDialect) DbVersionQuery ¶
func (*MSSQLDialect) InsertVersionSql ¶
func (pg *MSSQLDialect) InsertVersionSql() string
type Migration ¶
type MigrationRecord ¶
type MySqlDialect ¶
type MySqlDialect struct{}
func (*MySqlDialect) CreateVersionTableSql ¶
func (m *MySqlDialect) CreateVersionTableSql() string
func (*MySqlDialect) DbVersionQuery ¶
func (*MySqlDialect) InsertVersionSql ¶
func (m *MySqlDialect) InsertVersionSql() string
type PostgresDialect ¶
type PostgresDialect struct{}
func (*PostgresDialect) CreateVersionTableSql ¶
func (pg *PostgresDialect) CreateVersionTableSql() string
func (*PostgresDialect) DbVersionQuery ¶
func (*PostgresDialect) InsertVersionSql ¶
func (pg *PostgresDialect) InsertVersionSql() string
type SqlDialect ¶
type SqlDialect interface { CreateVersionTableSql() string // sql string to create the goose_db_version table InsertVersionSql() string // sql string to insert the initial version table row DbVersionQuery(db *sql.DB) (*sql.Rows, error) }
SqlDialect abstracts the details of specific SQL dialects for goose's few SQL specific statements
func DialectByName ¶
func DialectByName(d string) SqlDialect
drivers that we don't know about can ask for a dialect by name
type Sqlite3Dialect ¶
type Sqlite3Dialect struct{}
func (*Sqlite3Dialect) CreateVersionTableSql ¶
func (m *Sqlite3Dialect) CreateVersionTableSql() string
func (*Sqlite3Dialect) DbVersionQuery ¶
func (*Sqlite3Dialect) InsertVersionSql ¶
func (m *Sqlite3Dialect) InsertVersionSql() string