Skip to content

Validate member namespace id constraints

Serena Fang requested to merge validate-members-namespace-id-constraints into master

What does this MR do and why?

Describe in detail what your merge request does and why.

#371095 (closed)

#377433 (comment 1139215782)

In !102843 (merged) we add a not null constraint and in !93240 (merged) we add a foreign key with validate: false. In this MR, validate those constraints.

  • Migration file 1: Re-add the check constraint (not valid). !102843 (merged)
  • Migration file 2: Fix the 453 (maybe we get some extra records here due to the missing CHECK constraint) records by backfilling the data or removing the member records (inline). !99080 (merged)
  • Migration file 3: Validate the check constraint and the FK (fk_2f85abf8f1). <- this MR
  • Migration file 4: Drop the FK with the SET NULL clause (fk_aa82dcc1c6). !97929 (closed)
% rails db:migrate
main: == 20220916072304 ValidateNotNullConstraintOnMembersNamespaceId: migrating ====
main: -- current_schema()
main:    -> 0.0031s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0003s
main: -- execute("ALTER TABLE members VALIDATE CONSTRAINT check_508774aac0;")
main:    -> 0.0029s
main: -- execute("RESET statement_timeout")
main:    -> 0.0005s
main: == 20220916072304 ValidateNotNullConstraintOnMembersNamespaceId: migrated (0.0155s) 

main: == 20220916073539 ValidateFkMembersNamespaceId: migrating =====================
main: -- foreign_keys(:members)
main:    -> 0.0044s
main: -- execute("ALTER TABLE members VALIDATE CONSTRAINT fk_2f85abf8f1;")
main:    -> 0.0205s
main: == 20220916073539 ValidateFkMembersNamespaceId: migrated (0.0254s) ============


% rails db:rollback:main STEP=2 
main: == 20220916073539 ValidateFkMembersNamespaceId: reverting =====================
main: == 20220916073539 ValidateFkMembersNamespaceId: reverted (0.0006s) ============

main: == 20220916072304 ValidateNotNullConstraintOnMembersNamespaceId: reverting ====
main: == 20220916072304 ValidateNotNullConstraintOnMembersNamespaceId: reverted (0.0000s) 

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

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 Serena Fang

Merge request reports