Commit de62d2c4 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'rd-fix-namespace_id-fk-for-gitlab_subscriptions' into 'master'

Add ON DELETE constraint to namespace_id FK on gitlab_subscriptions

Closes gitlab-ce#55401

See merge request gitlab-org/gitlab-ee!8871
parents 0488ad0a 8c005072
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20181212104941) do
ActiveRecord::Schema.define(version: 20181215161939) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -3260,7 +3260,7 @@ ActiveRecord::Schema.define(version: 20181212104941) do
add_foreign_key "geo_repository_renamed_events", "projects", on_delete: :cascade
add_foreign_key "geo_repository_updated_events", "projects", on_delete: :cascade
add_foreign_key "geo_reset_checksum_events", "projects", on_delete: :cascade
add_foreign_key "gitlab_subscriptions", "namespaces"
add_foreign_key "gitlab_subscriptions", "namespaces", name: "fk_e2595d00a1", on_delete: :cascade
add_foreign_key "gitlab_subscriptions", "plans", column: "hosted_plan_id", name: "fk_bd0c4019c3", on_delete: :cascade
add_foreign_key "gpg_key_subkeys", "gpg_keys", on_delete: :cascade
add_foreign_key "gpg_keys", "users", on_delete: :cascade
......
......@@ -31,7 +31,7 @@ module EE
belongs_to :plan
has_one :namespace_statistics
has_one :gitlab_subscription
has_one :gitlab_subscription, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
scope :with_plan, -> { where.not(plan_id: nil) }
......
# frozen_string_literal: true
class AddOnDeleteCascadeToNamespaceIdFkOnGitlabSubscriptions < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
remove_foreign_key(:gitlab_subscriptions, column: :namespace_id)
add_concurrent_foreign_key(:gitlab_subscriptions, :namespaces, column: :namespace_id)
end
def down
# Previously there was a foreign key without a CASCADING DELETE, so we'll
# just leave the foreign key in place.
end
end
......@@ -8,7 +8,7 @@ describe Namespace do
let!(:gold_plan) { create(:gold_plan) }
it { is_expected.to have_one(:namespace_statistics) }
it { is_expected.to have_one(:gitlab_subscription) }
it { is_expected.to have_one(:gitlab_subscription).dependent(:destroy) }
it { is_expected.to belong_to(:plan) }
it { is_expected.to delegate_method(:shared_runners_minutes).to(:namespace_statistics) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment