Skip to content

Commit bdd1367

Browse files
committed
Add -order-applied flag.
1 parent cf480ec commit bdd1367

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

cmd/goose/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var (
4141
noColor = flags.Bool("no-color", false, "disable color output (NO_COLOR env variable supported)")
4242
timeout = flags.Duration("timeout", 0, "maximum allowed duration for queries to run; e.g., 1h13m")
4343
envFile = flags.String("env", "", "load environment variables from file (default .env)")
44+
orderApplied = flags.Bool("order-applied", false, "list migrations by order applied (pending always last) instead of migration version")
4445
)
4546

4647
var version string
@@ -175,6 +176,9 @@ func main() {
175176
if *noVersioning {
176177
options = append(options, goose.WithNoVersioning())
177178
}
179+
if *orderApplied {
180+
options = append(options, goose.WithOrderApplied())
181+
}
178182
if timeout != nil && *timeout != 0 {
179183
var cancel context.CancelFunc
180184
ctx, cancel = context.WithTimeout(ctx, *timeout)

status.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ func StatusContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsF
9191
lines = append(lines, &line)
9292
}
9393

94-
sort.Sort(statusLines{contents: lines, order: lessByVersionOrSource})
94+
var order func(si, sj *statusLine) bool
95+
if option.orderApplied {
96+
order = lessByAppliedAt
97+
} else {
98+
order = lessByVersionOrSource
99+
}
100+
sort.Sort(statusLines{contents: lines, order: order})
95101

96102
log.Printf(" Applied At Migration")
97103
log.Printf(" =======================================")

up.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type options struct {
1212
allowMissing bool
1313
applyUpByOne bool
1414
noVersioning bool
15+
orderApplied bool
1516
}
1617

1718
type OptionsFunc func(o *options)
@@ -28,6 +29,10 @@ func WithNoColor(b bool) OptionsFunc {
2829
return func(o *options) { noColor = b }
2930
}
3031

32+
func WithOrderApplied() OptionsFunc {
33+
return func(o *options) { o.orderApplied = true }
34+
}
35+
3136
func withApplyUpByOne() OptionsFunc {
3237
return func(o *options) { o.applyUpByOne = true }
3338
}

0 commit comments

Comments
 (0)