Skip to content

Validate issues.work_item_type_id NOT NULL constraint

Mario Celi requested to merge 345830-finalize-work-item-type-backfill into master

What does this MR do and why?

  1. Ensures background migration has finished running for the 5 base types the issue table backfill was originally scheduled.
  2. Validates a NOT NULL constraint on the issues.work_item_type_id column.

We scheduled 5 backfill migrations (one for each work item type). They are all complete in .com and staging. .com finished the last backfill migration on 2022-11-02

Migration output

UP

bin/rails db:migrate
main: == 20221115173607 EnsureWorkItemTypeBackfillMigrationFinished: migrating ======
main: == 20221115173607 EnsureWorkItemTypeBackfillMigrationFinished: migrated (0.1465s)

main: == 20221121184931 ValidateNotNullContraintOnIssuesWorkItemTypeId: migrating ===
main: -- current_schema()
main:    -> 0.0026s
main: -- transaction_open?()
main:    -> 0.0000s
main: -- current_schema()
main:    -> 0.0005s
main: -- transaction_open?()
main:    -> 0.0000s
main: -- execute("ALTER TABLE issues\nADD CONSTRAINT check_2addf801cd\nCHECK ( work_item_type_id IS NOT NULL )\nNOT VALID;\n")
main:    -> 0.0030s
main: -- current_schema()
main:    -> 0.0003s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0003s
main: -- execute("ALTER TABLE issues VALIDATE CONSTRAINT check_2addf801cd;")
main:    -> 0.0045s
main: -- execute("RESET statement_timeout")
main:    -> 0.0006s
main: == 20221121184931 ValidateNotNullContraintOnIssuesWorkItemTypeId: migrated (0.0512s)

ci: == 20221115173607 EnsureWorkItemTypeBackfillMigrationFinished: migrating ======
ci: -- The migration is skipped since it modifies the schemas: [:gitlab_main].
ci: -- This database can only apply migrations in one of the following schemas: [:gitlab_ci, :gitlab_shared, :gitlab_internal].
ci: == 20221115173607 EnsureWorkItemTypeBackfillMigrationFinished: migrated (0.0001s)

ci: == 20221121184931 ValidateNotNullContraintOnIssuesWorkItemTypeId: migrating ===
ci: -- current_schema()
ci:    -> 0.0003s
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- current_schema()
ci:    -> 0.0005s
ci: -- current_schema()
ci:    -> 0.0007s
ci: -- execute("SET statement_timeout TO 0")
ci:    -> 0.0004s
ci: -- execute("ALTER TABLE issues VALIDATE CONSTRAINT check_2addf801cd;")
ci:    -> 0.0075s
ci: -- execute("RESET statement_timeout")
ci:    -> 0.0004s
ci: == 20221121184931 ValidateNotNullContraintOnIssuesWorkItemTypeId: migrated (0.0275s)

DOWN

bin/rails db:rollback:main db:rollback:ci STEP=2
main: == 20221121184931 ValidateNotNullContraintOnIssuesWorkItemTypeId: reverting ===
main: -- transaction_open?()
main:    -> 0.0000s
main: -- transaction_open?()
main:    -> 0.0000s
main: -- execute("            ALTER TABLE issues\n            DROP CONSTRAINT IF EXISTS check_2addf801cd\n")
main:    -> 0.0016s
main: == 20221121184931 ValidateNotNullContraintOnIssuesWorkItemTypeId: reverted (0.0186s)

main: == 20221115173607 EnsureWorkItemTypeBackfillMigrationFinished: reverting ======
main: == 20221115173607 EnsureWorkItemTypeBackfillMigrationFinished: reverted (0.0005s)

ci: == 20221121184931 ValidateNotNullContraintOnIssuesWorkItemTypeId: reverting ===
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- execute("            ALTER TABLE issues\n            DROP CONSTRAINT IF EXISTS check_2addf801cd\n")
ci:    -> 0.0035s
ci: == 20221121184931 ValidateNotNullContraintOnIssuesWorkItemTypeId: reverted (0.0086s)

ci: == 20221115173607 EnsureWorkItemTypeBackfillMigrationFinished: reverting ======
ci: -- The migration is skipped since it modifies the schemas: [:gitlab_main].
ci: -- This database can only apply migrations in one of the following schemas: [:gitlab_ci, :gitlab_shared, :gitlab_internal].
ci: == 20221115173607 EnsureWorkItemTypeBackfillMigrationFinished: reverted (0.0001s)

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

Edited by Mario Celi

Merge request reports

Loading