Skip to content

Run gitlab:db:lock_writes when creating new database

What does this MR do and why?

Omnibus install calls db:configure rake task during installation. This task will:

  • create tables (db:schema:load) if database is empty
  • run migrations exist if database is not empty

This MR will make sure we set a write lock on:

  • main tables in ci database (example: users table)
  • ci tables in main database (example: ci_pipelines table)

This is implemented using the rake task gitlab:db:lock_writes

The task is idempotent.

How to set up and validate locally

WARNING This will reset the data in the database!

  • run bundle exec rake db:drop db:create gitlab:db:configure
  • (database seeding can be aborted using CTRL-C)
  • run gdk psql -c "DELETE FROM ci_pipelines WHERE id = 1"

On master branch, this will result in:

$ gdk psql -c "DELETE FROM ci_pipelines WHERE id = 1"
DELETE 0

On this branch, this will result in:

$ gdk psql -c "DELETE FROM ci_pipelines WHERE id = 1"
ERROR:  Table: "ci_pipelines" is write protected within this Gitlab database.
HINT:  Make sure you are using the right database connection
CONTEXT:  PL/pgSQL function gitlab_schema_prevent_write() line 4 at RAISE

MR acceptance checklist

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

Related to #404974 (closed)

Edited by Rutger Wessels

Merge request reports