Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add line name to migration comment #703

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading