Skip to content

Commit

Permalink
add line name to migration comment
Browse files Browse the repository at this point in the history
  • Loading branch information
bgentry committed Dec 24, 2024
1 parent e7ae173 commit 387ebf4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions cmd/river/rivercli/river_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func migratePrintResult(out io.Writer, opts *migrateOpts, res *rivermigrate.Migr

if opts.ShowSQL {
fmt.Fprintf(out, "%s\n", strings.Repeat("-", 80))
fmt.Fprintf(out, "%s\n", migrationComment(migrateVersion.Version, direction))
fmt.Fprintf(out, "%s\n", migrationComment(opts.Line, migrateVersion.Version, direction))
fmt.Fprintf(out, "%s\n\n", strings.TrimSpace(migrateVersion.SQL))
}
}
Expand All @@ -451,8 +451,8 @@ func migratePrintResult(out io.Writer, opts *migrateOpts, res *rivermigrate.Migr
// An informational comment that's tagged on top of any migration's SQL to help
// attribute what it is for when it's copied elsewhere like other migration
// frameworks.
func migrationComment(version int, direction rivermigrate.Direction) string {
return fmt.Sprintf("-- River migration %03d [%s]", version, direction)
func migrationComment(line string, version int, direction rivermigrate.Direction) string {
return fmt.Sprintf("-- River %s migration %03d [%s]", line, version, direction)
}

type migrateGetOpts struct {
Expand Down Expand Up @@ -523,7 +523,7 @@ func (c *migrateGet) Run(_ context.Context, opts *migrateGetOpts) (bool, error)
}

printedOne = true
fmt.Fprintf(c.Out, "%s\n", migrationComment(migration.Version, direction))
fmt.Fprintf(c.Out, "%s\n", migrationComment(opts.Line, migration.Version, direction))
fmt.Fprintf(c.Out, "%s\n", strings.TrimSpace(sql))
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/river/rivercli/river_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ func withCommandBase[TCommand Command[TOpts], TOpts CommandOpts](t *testing.T, c
func TestMigrationComment(t *testing.T) {
t.Parallel()

require.Equal(t, "-- River migration 001 [down]", migrationComment(1, rivermigrate.DirectionDown))
require.Equal(t, "-- River migration 002 [up]", migrationComment(2, rivermigrate.DirectionUp))
require.Equal(t, "-- River main migration 001 [down]", migrationComment("main", 1, rivermigrate.DirectionDown))
require.Equal(t, "-- River main migration 002 [up]", migrationComment("main", 2, rivermigrate.DirectionUp))
}

func TestRoundDuration(t *testing.T) {
Expand Down

0 comments on commit 387ebf4

Please sign in to comment.