Skip to content

Use DROP SCHEMA ... CASCADE in db:drop_tables

Patrick Bair requested to merge pb-drop-schema-cascade-in-drop-tables into master

What does this MR do and why?

As reported in #347140 (closed), gitlab:db:drop_tables is failing when trying to drop all the tables, because some objects still depend on the gitlab_partitions_dynamic schema.

I think this is being caused by detached partitions, which wouldn't automatically be dropped when we drop the parent table earlier in the same rake task (we do a DROP TABLE ... CASCADE there).

If we add CASCADE on the DROP SCHEMA as well, this will drop any of those dangling partitions.

How to set up and validate locally

  1. On master, create a "detached partition" in gitlab_partitions_dynamic
    create table gitlab_partitions_dynamic.web_hook_logs_000000 (like public.web_hook_logs);
  2. Run the rake task
    rails gitlab:db:drop_tables
    And you should see an error about being unable to drop the schema due to the table depending on it.
  3. Repeat those steps on this branch and the extra table will be dropped automatically when the schema is dropped.

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 Patrick Bair

Merge request reports