Documentation ¶
Index ¶
- Variables
- func MustRegister(fns ...func(DB) error)
- func MustRegisterTx(fns ...func(DB) error)
- func Register(fns ...func(DB) error) error
- func RegisterTx(fns ...func(DB) error) error
- func Run(db DB, a ...string) (oldVersion, newVersion int64, err error)
- func SetTableName(name string)
- func SetVersion(db DB, version int64) error
- func Version(db DB) (int64, error)
- type Collection
- func (c *Collection) DisableSQLAutodiscover(flag bool) *Collection
- func (c *Collection) DiscoverSQLMigrations(dir string) error
- func (c *Collection) Migrations() []*Migration
- func (c *Collection) MustRegister(fns ...func(DB) error)
- func (c *Collection) MustRegisterTx(fns ...func(DB) error)
- func (c *Collection) Register(fns ...func(DB) error) error
- func (c *Collection) RegisterTx(fns ...func(DB) error) error
- func (c *Collection) Run(db DB, a ...string) (oldVersion, newVersion int64, err error)
- func (c *Collection) SetTableName(tableName string) *Collection
- func (c *Collection) SetVersion(db DB, version int64) error
- func (c *Collection) Version(db DB) (int64, error)
- type DB
- type Migration
Constants ¶
This section is empty.
Variables ¶
var DefaultCollection = NewCollection()
Functions ¶
func MustRegister ¶
func MustRegisterTx ¶
func Register ¶
Register registers new database migration. Must be called from file with name like "1_initialize_db.go", where:
- 1 - migration version;
- initialize_db - comment.
func RegisterTx ¶
RegisterTx is just like Register but marks the migration to be executed inside a transaction.
func Run ¶
Run runs command on the db. Supported commands are: - up [target] - runs all available migrations by default or up to target one if argument is provided. - down - reverts last migration. - reset - reverts all migrations. - version - prints current db version. - set_version - sets db version without running migrations.
func SetTableName ¶
func SetTableName(name string)
func SetVersion ¶
Types ¶
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
func NewCollection ¶
func NewCollection(migrations ...*Migration) *Collection
func (*Collection) DisableSQLAutodiscover ¶
func (c *Collection) DisableSQLAutodiscover(flag bool) *Collection
func (*Collection) DiscoverSQLMigrations ¶
func (c *Collection) DiscoverSQLMigrations(dir string) error
DiscoverSQLMigrations scan the dir for files with .sql extension and adds discovered SQL migrations to the collection.
func (*Collection) Migrations ¶
func (c *Collection) Migrations() []*Migration
func (*Collection) MustRegister ¶
func (c *Collection) MustRegister(fns ...func(DB) error)
func (*Collection) MustRegisterTx ¶
func (c *Collection) MustRegisterTx(fns ...func(DB) error)
func (*Collection) Register ¶
func (c *Collection) Register(fns ...func(DB) error) error
Register registers new database migration. Must be called from a file with name like "1_initialize_db.go".
func (*Collection) RegisterTx ¶
func (c *Collection) RegisterTx(fns ...func(DB) error) error
RegisterTx is like Register, but migration will be run in a transaction.
func (*Collection) Run ¶
func (c *Collection) Run(db DB, a ...string) (oldVersion, newVersion int64, err error)
func (*Collection) SetTableName ¶
func (c *Collection) SetTableName(tableName string) *Collection
func (*Collection) SetVersion ¶
func (c *Collection) SetVersion(db DB, version int64) error
type DB ¶
type DB interface { Model(model ...interface{}) *orm.Query Select(model interface{}) error Insert(model ...interface{}) error Update(model interface{}) error Delete(model interface{}) error ForceDelete(model interface{}) error Exec(query interface{}, params ...interface{}) (orm.Result, error) ExecOne(query interface{}, params ...interface{}) (orm.Result, error) Query(coll, query interface{}, params ...interface{}) (orm.Result, error) QueryOne(model, query interface{}, params ...interface{}) (orm.Result, error) Begin() (*pg.Tx, error) CopyFrom(r io.Reader, query interface{}, params ...interface{}) (orm.Result, error) CopyTo(w io.Writer, query interface{}, params ...interface{}) (orm.Result, error) Context() context.Context orm.QueryFormatter }
DB is a common interface for pg.DB and pg.Tx types.
type Migration ¶
func RegisteredMigrations ¶
func RegisteredMigrations() []*Migration
RegisteredMigrations returns currently registered Migrations.