forked from pressly/goose
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus.go
More file actions
58 lines (48 loc) · 1.24 KB
/
status.go
File metadata and controls
58 lines (48 loc) · 1.24 KB
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
53
54
55
56
57
58
package goose
import (
"database/sql"
"path/filepath"
"strings"
"time"
)
// Status prints the status of all migrations.
func Status(db *sql.DB, dir string) error {
// must ensure that the version table exists if we're running on a pristine DB
if _, err := EnsureDBVersion(db); err != nil {
return err
}
// collect all migrations
migrations, err := CollectMigrations(db, dir, minVersion, maxVersion, false)
if err != nil {
return err
}
log.Println(" Applied At Migration (Note)")
log.Println(" =============================================================")
for _, migration := range migrations {
printMigrationStatus(db, migration)
}
return nil
}
func printMigrationStatus(db *sql.DB, migration *Migration) {
var (
appliedAt string
note string
filename string
)
if migration.IsApplied {
appliedAt = migration.TStamp.Format(time.ANSIC)
} else {
appliedAt = "Pending"
}
if migration.Note != nil && len(*migration.Note) > 0 {
note = *migration.Note
} else {
note = "-"
}
if strings.HasPrefix(migration.Source, "[!") {
filename = migration.Source
} else {
filename = filepath.Base(migration.Source)
}
log.Printf(" %-24s -- %v (%v)\n", appliedAt, filename, note)
}