summaryrefslogtreecommitdiff
path: root/db/post_migrate/20210303064142_cleanup_gitlab_subscriptions_with_null_namespace_id.rb
blob: 2250d4c0c8a3dde04613d8a1e4035b351176ad97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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: nil).delete_all
  end

  def down
    # no-op : can't go back to `NULL` without first dropping the `NOT NULL` constraint
  end
end