Skip to content

Commit

Permalink
add line name to migration comment (#703)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgentry authored Dec 24, 2024
1 parent e7ae173 commit 81ca3b9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Sleep durations are now logged as Go-like duration strings (e.g. "10s") in either text or JSON instead of duration strings in text and nanoseconds in JSON. [PR #699](https://github.com/riverqueue/river/pull/699).
- Altered the migration comments from `river migrate-get` to include the "line" of the migration being run (`main`, or for River Pro `workflow` and `sequence`) to make them more distinguishable. [PR #703](https://github.com/riverqueue/river/pull/703).

### Fixed

Expand Down
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 81ca3b9

Please sign in to comment.