Ignore objects from Schema Validations
What does this MR do and why?
Ignores some Schema Objects from Schema Validations1.
It ignores:
-
test_replication
tables. See: https://gitlab.com/gitlab-org/gitlab/-/issues/407893 - gitlab_schema_write_trigger_for_* triggers. These are added dynamically to the database.
- Table columns that are used in partitioned tables
-
- GitLab partition logic advances the DEFAULT value of partition key columns. See: #407965 (comment 1367535469)
How to set up and validate locally
test_replication
tables
Validating - 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
);
- Run the task to check the schema:
bundle exec rake gitlab:db:schema_checker:run
- Table
test_replication
diff must not be present in the output
gitlab_schema_write_trigger_for_
triggers
Validating - 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();
- Run the task to check the schema:
bundle exec rake gitlab:db:schema_checker:run
- Trigger
gitlab_schema_write_trigger_for_users
diff must not be present in the output
Validating partitioned table columns
- 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);
- 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);
- 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.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #408080 (closed)
-
Schema Validations is a framework that compares production DB and
db/structure.sql
to find inconsistencies between the two.↩
Edited by Leonardo da Rosa