Skip to content

Draft: Invoke migrations without using rake task

Rutger Wessels requested to merge fix-migrations-as-non-superuser-job into master

What does this MR do and why?

While working on a further iteration of preventing cross-database modification (main,ci), I ran into an issue with reset_as_non_superuser rake task. This rake task is used in the CI job db:migrate-non-superuser.

The job is added because we want to verify that database migrations do not need to be run with a PostgreSQL user that has SUPERUSER privilege. The job invokes a rake task [gitlab:db:reset_as_non_superuser](https://gitlab.com/gitlab-org/gitlab/-/blob/9d64e88ef966dfe4096cb3db7da3f9a6bd9973dd/lib/tasks/gitlab/db.rake#L443) that will override the ActiveRecord connection and then runs migrations by using Rake::Task['db:migrate'].invoke.

However, this rake task is reconfiguring the ActiveRecord connection based on the values from database.yml. So the override in gitlab:db:reset_as_non_superuser is actually ignored. The migrations in the CI job are run as user postgres on CI.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

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

Merge request reports