-
Notifications
You must be signed in to change notification settings - Fork 521
/
provider_types.go
91 lines (81 loc) · 2.28 KB
/
provider_types.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package goose
import (
"fmt"
"path/filepath"
"time"
)
// MigrationType is the type of migration.
type MigrationType string
const (
TypeGo MigrationType = "go"
TypeSQL MigrationType = "sql"
)
// Source represents a single migration source.
//
// The Path field may be empty if the migration was registered manually. This is typically the case
// for Go migrations registered using the [WithGoMigration] option.
type Source struct {
Type MigrationType
Path string
Version int64
}
// MigrationResult is the result of a single migration operation.
type MigrationResult struct {
Source *Source
Duration time.Duration
Direction string
// Empty indicates no action was taken during the migration, but it was still versioned. For
// SQL, it means no statements; for Go, it's a nil function.
Empty bool
// Error is only set if the migration failed.
Error error
}
// String returns a string representation of the migration result.
//
// Example down:
//
// EMPTY down 00006_posts_view-copy.sql (607.83µs)
// OK down 00005_posts_view.sql (646.25µs)
//
// Example up:
//
// OK up 00005_posts_view.sql (727.5µs)
// EMPTY up 00006_posts_view-copy.sql (378.33µs)
func (m *MigrationResult) String() string {
var format string
if m.Direction == "up" {
format = "%-5s %-2s %s (%s)"
} else {
format = "%-5s %-4s %s (%s)"
}
var state string
if m.Empty {
state = "EMPTY"
} else {
state = "OK"
}
return fmt.Sprintf(format,
state,
m.Direction,
filepath.Base(m.Source.Path),
truncateDuration(m.Duration),
)
}
// State represents the state of a migration.
type State string
const (
// StatePending is a migration that exists on the filesystem, but not in the database.
StatePending State = "pending"
// StateApplied is a migration that has been applied to the database and exists on the
// filesystem.
StateApplied State = "applied"
// TODO(mf): we could also add a third state for untracked migrations. This would be useful for
// migrations that were manually applied to the database, but not versioned. Or the Source was
// deleted, but the migration still exists in the database. StateUntracked State = "untracked"
)
// MigrationStatus represents the status of a single migration.
type MigrationStatus struct {
Source *Source
State State
AppliedAt time.Time
}