From 81ca3b9d38c1f5c3f9dfd82697e22d96fdc8c175 Mon Sep 17 00:00:00 2001 From: Blake Gentry Date: Tue, 24 Dec 2024 13:54:14 -0600 Subject: [PATCH] add line name to migration comment (#703) --- CHANGELOG.md | 1 + cmd/river/rivercli/river_cli.go | 8 ++++---- cmd/river/rivercli/river_cli_test.go | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 078e6a74..51a23a24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cmd/river/rivercli/river_cli.go b/cmd/river/rivercli/river_cli.go index 66728be1..36fa41d0 100644 --- a/cmd/river/rivercli/river_cli.go +++ b/cmd/river/rivercli/river_cli.go @@ -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)) } } @@ -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 { @@ -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)) } diff --git a/cmd/river/rivercli/river_cli_test.go b/cmd/river/rivercli/river_cli_test.go index 02337815..0943038c 100644 --- a/cmd/river/rivercli/river_cli_test.go +++ b/cmd/river/rivercli/river_cli_test.go @@ -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) {