Flag GitLab objects in schemas outside the search path

What does this MR do and why?

Follow-up to !245566 (merged)

This MR adds a gitlab_objects_outside_search_path warning to Gitlab::Database::DatabaseInformation. Every schema that is not a search-path candidate is cross-referenced against the GitLab schema dictionary (Gitlab::Database::GitlabSchema.table_schema), and a warning is reported when one holds recognized GitLab objects. GitLab never resolves unqualified references against such schemas, so these objects are never used — they are typically leftovers from a restore or a migration into the wrong schema.

Partition schemas (gitlab_partitions_dynamic, gitlab_partitions_static) are exempt because GitLab keeps partitions there by design, outside the search path.

The finding renders through the existing findings UI on /admin/database_diagnostics, so no frontend change is needed.

Related to #611068 (closed)

Screenshots or screen recordings

The new finding on /admin/database_diagnostics, after the setup in the next section. Expand Details on the Search path row to see it.

gitlab-objects-outside-search-path

How to set up and validate locally

All statements target the main development database (gitlabhq_development).

  1. Create a schema with a GitLab object, without touching the search_path:

    CREATE SCHEMA foobar;
    CREATE TABLE foobar.users (id int);
  2. In a Rails console:

    Gitlab::Database::DatabaseInformation.execute

    The findings array now contains a gitlab_objects_outside_search_path warning naming foobar. Before this change it was empty.

  3. Replace the table with a non-GitLab one and confirm no finding is reported:

    DROP TABLE foobar.users;
    CREATE TABLE foobar.not_a_gitlab_table (id int);
  4. Clean up:

    DROP SCHEMA foobar CASCADE;
Edited by Niko Belokolodov

Merge request reports

Loading
Loading