From b05ed0bf6599ba3f17ec6222d725b457ae30ba94 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 25 Mar 2021 17:53:11 -0400 Subject: [PATCH] If the database is already initialized, use 0 as the return value (#1033) This matches the migrations code, which treats the operation as idempotent. --- CHANGELOG.md | 19 +++++++++++-------- internal/cmd/commands/database/funcs.go | 4 ++-- internal/cmd/commands/database/funcs_test.go | 4 ++-- internal/cmd/commands/database/init.go | 6 +++++- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59830b623..79cf7aabd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,6 @@ Canonical reference for changes, improvements, and bugfixes for Boundary. ## Next -### New and Improved - -* server: When performing recursive listing, `list` action is not longer - required to be granted to the calling user. Instead, the given scope acts as - the root point (so only results under that scope will be shown), and `list` - grant is evaluated per-scope. - [PR](https://github.com/hashicorp/boundary/pull/1016) - ### Deprecations/Changes * authentication: The `auth-methods/:authenticate:login` action is @@ -27,6 +19,17 @@ Canonical reference for changes, improvements, and bugfixes for Boundary. now but will be removed in a few releases. Finally, in the Go SDK, the `Authenticate` function now requires a `command` value to be passed in. +### New and Improved + +* server: When performing recursive listing, `list` action is not longer + required to be granted to the calling user. Instead, the given scope acts as + the root point (so only results under that scope will be shown), and `list` + grant is evaluated per-scope. + [PR](https://github.com/hashicorp/boundary/pull/1016) +* database init: If the database is already initialized, return 0 as the exit + code. This matches how the `database migrate` command works. + [PR](https://github.com/hashicorp/boundary/pull/1033) + ### Bug Fixes * server: Roles for auto generated scopes are now generated at database init. diff --git a/internal/cmd/commands/database/funcs.go b/internal/cmd/commands/database/funcs.go index 0ad4fba97..b2a8c0975 100644 --- a/internal/cmd/commands/database/funcs.go +++ b/internal/cmd/commands/database/funcs.go @@ -53,8 +53,8 @@ func migrateDatabase(ctx context.Context, ui cli.Ui, dialect, u string, requireF return unlock, 2 } if requireFresh && st.InitializationStarted { - ui.Error(base.WrapAtLength("Database has already been initialized. Please use 'boundary database migrate'.")) - return unlock, 2 + ui.Output(base.WrapAtLength("Database has already been initialized. Please use 'boundary database migrate' for any upgrade needs.")) + return unlock, -1 } if st.Dirty { ui.Error(base.WrapAtLength("Database is in a bad state. Please revert back to the last known good state.")) diff --git a/internal/cmd/commands/database/funcs_test.go b/internal/cmd/commands/database/funcs_test.go index 5911666a7..5779e86fd 100644 --- a/internal/cmd/commands/database/funcs_test.go +++ b/internal/cmd/commands/database/funcs_test.go @@ -116,8 +116,8 @@ func TestMigrateDatabase(t *testing.T) { require.NoError(t, err) return u }, - expectedCode: 2, - expectedError: "Database has already been initialized. Please use 'boundary database\nmigrate'.\n", + expectedCode: -1, + expectedOutput: "Database has already been initialized. Please use 'boundary database migrate'\nfor any upgrade needs.\n", }, { name: "bad_url_require_fresh", diff --git a/internal/cmd/commands/database/init.go b/internal/cmd/commands/database/init.go index 213b30ed6..3b9527be2 100644 --- a/internal/cmd/commands/database/init.go +++ b/internal/cmd/commands/database/init.go @@ -241,7 +241,11 @@ func (c *InitCommand) Run(args []string) (retCode int) { clean, errCode := migrateDatabase(c.Context, c.UI, dialect, migrationUrl, true) defer clean() - if errCode != 0 { + switch errCode { + case 0: + case -1: + return 0 + default: return errCode }