-
Notifications
You must be signed in to change notification settings - Fork 59
/
default.go
51 lines (41 loc) · 1.52 KB
/
default.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package migrations
var DefaultCollection = NewCollection()
func SetTableName(name string) {
DefaultCollection.SetTableName(name)
}
func Version(db DB) (int64, error) {
return DefaultCollection.Version(db)
}
func SetVersion(db DB, version int64) error {
return DefaultCollection.SetVersion(db, version)
}
// 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 Register(fns ...func(DB) error) error {
return DefaultCollection.Register(fns...)
}
// RegisterTx is just like Register but marks the migration to be executed inside a transaction.
func RegisterTx(fns ...func(DB) error) error {
return DefaultCollection.RegisterTx(fns...)
}
func MustRegister(fns ...func(DB) error) {
DefaultCollection.MustRegister(fns...)
}
func MustRegisterTx(fns ...func(DB) error) {
DefaultCollection.MustRegisterTx(fns...)
}
// RegisteredMigrations returns currently registered Migrations.
func RegisteredMigrations() []*Migration {
return DefaultCollection.Migrations()
}
// 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 Run(db DB, a ...string) (oldVersion, newVersion int64, err error) {
return DefaultCollection.Run(db, a...)
}