Skip to content

Validate NOT NULL constraint on gitlab_subscriptions namespace_id

What does this MR do?

For issue #321662 (closed). This MR is the seconds step to validate the NOT NULL constraint on GitlabSubscriptions namespace_id column.

Isseu #243496 (closed) requires to add NOT NULL constraint on GitlabSubscriptions namespace_id column. Per document https://docs.gitlab.com/ee/development/database/not_null_constraints.html#add-a-not-null-constraint-to-an-existing-column, it requires two steps in two releases.

The first step is done by MR !54319 (merged), where it:

  • Ensure the constraint is enforced at the application level (i.e. add a model validation).
  • Add a post-deployment migration to add the NOT NULL constraint with validate: false.
  • Add a post-deployment migration to fix the existing records

This MR is the second step, where it:

  • Validate the NOT NULL constraint using a post-deployment migration.

Migration output

Up

$ bin/rails db:migrate
== 20210322115438 ValidateNotNullConstraintOnGitlabSubscriptionsNamespaceId: migrating 
-- current_schema()
   -> 0.0002s
-- execute("ALTER TABLE gitlab_subscriptions VALIDATE CONSTRAINT check_77fea3f0e7;")
   -> 0.0006s
== 20210322115438 ValidateNotNullConstraintOnGitlabSubscriptionsNamespaceId: migrated (0.0029s) 

Down (Note: rollback is NO-OP in this migration script)

$ bin/rails db:rollback
== 20210322115438 ValidateNotNullConstraintOnGitlabSubscriptionsNamespaceId: reverting 
== 20210322115438 ValidateNotNullConstraintOnGitlabSubscriptionsNamespaceId: reverted (0.0000s) 

Screenshots (strongly suggested)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #321662 (closed)

Edited by Max Orefice

Merge request reports