Skip to content

Display a friendlier error message when DB is not seeded

What does this MR do and why?

Goes from undefined method personal_access_tokens' for nil:NilClass` as seen in gitlab-org/quality/engineering-productivity/review-apps-broken-incidents#30 (closed) to a friendlier message:

Error: Could not find root user. Check that the database was properly seeded

The first commit is a pure refactoring (i.e. we don't change the ruby command - see the validation in the next section).

The second commit adds the friendlier error message.

Does it work?

The review-deploy job for this MR succeeded: https://gitlab.com/gitlab-org/gitlab/-/jobs/4212705710#L185

How to set up and validate locally

In the first commit, I just extracted the one-liner ruby code to a heredoc. Below is to prove that the output before/after refactoring is the same (I added an extra ; at the end of the last line for consistency):

export REVIEW_APPS_ROOT_TOKEN=abcd

read -r -d '' multiline_ruby_code <<RUBY
token = User.find_by_username('root').personal_access_tokens.create(scopes: [:api], name: 'Token to disable sign-ups');
token.set_token('${REVIEW_APPS_ROOT_TOKEN}');
begin;
token.save!;
rescue(ActiveRecord::RecordNotUnique);
end;
Gitlab::CurrentSettings.current_application_settings.update!(signup_enabled: false);
RUBY

ruby_code=$(echo $multiline_ruby_code | tr '\n' ' ')
disable_signup_rb="token = User.find_by_username('root').personal_access_tokens.create(scopes: [:api], name: 'Token to disable sign-ups'); token.set_token('${REVIEW_APPS_ROOT_TOKEN}'); begin; token.save!; rescue(ActiveRecord::RecordNotUnique); end; Gitlab::CurrentSettings.current_application_settings.update!(signup_enabled: false)"

echo $ruby_code
# token = User.find_by_username('root').personal_access_tokens.create(scopes: [:api], name: 'Token to disable sign-ups'); token.set_token('abcd'); begin; token.save!; rescue(ActiveRecord::RecordNotUnique); end; Gitlab::CurrentSettings.current_application_settings.update!(signup_enabled: false); 
echo $disable_signup_rb
# token = User.find_by_username('root').personal_access_tokens.create(scopes: [:api], name: 'Token to disable sign-ups'); token.set_token('abcd'); begin; token.save!; rescue(ActiveRecord::RecordNotUnique); end; Gitlab::CurrentSettings.current_application_settings.update!(signup_enabled: false)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by David Dieulivol

Merge request reports

Loading