Skip to content

Ignore objects from Schema Validations

Leonardo da Rosa requested to merge 408080-ignore-specific-objects-2 into master

What does this MR do and why?

Ignores some Schema Objects from Schema Validations1.

It ignores:

How to set up and validate locally

Validating test_replication tables

  1. Create a new test_replication table:
CREATE TABLE test_replication (
  id bigint NOT NULL,
  created_at timestamp with time zone DEFAULT now() NOT NULL,
  status smallint DEFAULT 1 NOT NULL
);
  1. Run the task to check the schema:
bundle exec rake gitlab:db:schema_checker:run
  1. Table test_replication diff must not be present in the output

Validating gitlab_schema_write_trigger_for_ triggers

  1. Create a new trigger:
-- Don't forget to drop this trigger, as it blocks the users table
CREATE TRIGGER gitlab_schema_write_trigger_for_users BEFORE INSERT OR DELETE OR UPDATE OR TRUNCATE ON users FOR EACH STATEMENT EXECUTE FUNCTION gitlab_schema_prevent_write();
  1. Run the task to check the schema:
bundle exec rake gitlab:db:schema_checker:run
  1. Trigger gitlab_schema_write_trigger_for_users diff must not be present in the output

Validating partitioned table columns

  1. Create a new partitioned_table table:
CREATE TABLE partitioned_table (
  id bigint NOT NULL,
  partition_column bigint DEFAULT 1 NOT NULL,
  created_at timestamp with time zone DEFAULT now() NOT NULL,
  status smallint DEFAULT 1 NOT NULL
) PARTITION BY HASH (partition_column, created_at);
  1. Now, add a slightly different statement to db/structure.sql:
CREATE TABLE partitioned_table (
  id integer NOT NULL,
  partition_column integer,
  created_at timestamp with time zone,
  status integer DEFAULT 1 NOT NULL
) PARTITION BY HASH (partition_column, created_at);
  1. You should get the following diff:
The table partitioned_table has a different column statement between structure.sql and database
Diff:

-CREATE TABLE partitioned_table (id bigint NOT NULL, status smallint DEFAULT 1 NOT NULL)
+CREATE TABLE partitioned_table (id integer NOT NULL, status integer DEFAULT 1 NOT NULL)

partition_column and created_at columns must not be present in the diff.

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 #408080 (closed)

  1. Schema Validations is a framework that compares production DB and db/structure.sql to find inconsistencies between the two.

Edited by Leonardo da Rosa

Merge request reports

Loading