diff options
Diffstat (limited to 'db/post_migrate/20210303064142_cleanup_gitlab_subscriptions_with_null_namespace_id.rb')
-rw-r--r-- | db/post_migrate/20210303064142_cleanup_gitlab_subscriptions_with_null_namespace_id.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/db/post_migrate/20210303064142_cleanup_gitlab_subscriptions_with_null_namespace_id.rb b/db/post_migrate/20210303064142_cleanup_gitlab_subscriptions_with_null_namespace_id.rb new file mode 100644 index 00000000000..1fcfb3d43c0 --- /dev/null +++ b/db/post_migrate/20210303064142_cleanup_gitlab_subscriptions_with_null_namespace_id.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class CleanupGitlabSubscriptionsWithNullNamespaceId < ActiveRecord::Migration[6.0] + disable_ddl_transaction! + + class GitlabSubscription < ActiveRecord::Base + self.table_name = 'gitlab_subscriptions' + end + + def up + # As of today, there is 0 records whose namespace_id is null on GitLab.com. + # And we expect no such records on non GitLab.com instance. + # So this post-migration cleanup script is just for extra safe. + # + # This will be fast on GitLab.com, because: + # - gitlab_subscriptions.count=5021850 + # - namespace_id is indexed, so the query is pretty fast. Try on database-lab, this uses 5.931 ms + GitlabSubscription.where('namespace_id IS NULL').delete_all + end + + def down + # no-op : can't go back to `NULL` without first dropping the `NOT NULL` constraint + end +end |