Skip to content

Refactor: in dry run, we don't execute sql

Rutger Wessels requested to merge 412716-rename-method into master

What does this MR do and why?

Related issue: #412716 (closed)

In the LockWritesManager class, we have a method execute_sql_statement. But this method does not execute a SQL statement in case the dry_run mode is used.

I added a new method process_query that will:

  • Log the SQL and return needs_#{action} if dry_run is enabled
  • Calls execute_sql_statement and returns #{action}ed if dry_run is not enabled

How to set up and validate locally

Open two terminals. In one of them, open psql console: gdk psql -d gitlabhq_development_ci

gitlabhq_development_ci=# insert into shards (name) values ('this gives an error');
ERROR:  Table: "shards" 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

# In another terminal, run bundle exec rake gitlab:db:unlock_writes
# Now, we can insert data in the shards table:

gitlabhq_development_ci=# insert into shards (name) values ('success');
INSERT 0 1

# In another terminal, run bundle exec rake gitlab:db:lock_writes
# The table is locked for writes:

gitlabhq_development_ci=# insert into shards (name) values ('this gives an error');
ERROR:  Table: "shards" 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

Related to #412716 (closed)

Edited by Rutger Wessels

Merge request reports