forked from pressly/goose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
45 lines (39 loc) · 934 Bytes
/
version.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
package goose
import (
"database/sql"
"fmt"
)
// Version prints the current version of the database.
func Version(db *sql.DB, dir string, opts ...OptionsFunc) error {
option := &options{}
for _, f := range opts {
f(option)
}
if option.noVersioning {
var current int64
migrations, err := CollectMigrations(dir, minVersion, maxVersion)
if err != nil {
return fmt.Errorf("failed to collect migrations: %w", err)
}
if len(migrations) > 0 {
current = migrations[len(migrations)-1].Version
}
log.Printf("goose: file version %v\n", current)
return nil
}
current, err := GetDBVersion(db)
if err != nil {
return err
}
log.Printf("goose: version %v\n", current)
return nil
}
var tableName = "goose_db_version"
// TableName returns goose db version table name
func TableName() string {
return tableName
}
// SetTableName set goose db version table name
func SetTableName(n string) {
tableName = n
}