-
Notifications
You must be signed in to change notification settings - Fork 523
/
version.go
52 lines (45 loc) · 1.16 KB
/
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
46
47
48
49
50
51
52
package goose
import (
"context"
"database/sql"
"fmt"
)
// Version prints the current version of the database.
func Version(db *sql.DB, dir string, opts ...OptionsFunc) error {
ctx := context.Background()
return VersionContext(ctx, db, dir, opts...)
}
// VersionContext prints the current version of the database.
func VersionContext(ctx context.Context, 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 := GetDBVersionContext(ctx, 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
}