[deploy] Add foreign keys to models related to Organization (#9933)
* Add foreign keys to models related to Organization * Fix specs * Use on_delete: :cascade for listings -> organizations FK
This commit is contained in:
parent
45fb6504dc
commit
36358293ce
6 changed files with 24 additions and 6 deletions
|
|
@ -0,0 +1,11 @@
|
|||
class AddMissingForeignKeysToModelsRelatedToOrganizations < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_foreign_key :articles, :organizations, on_delete: :nullify, validate: false
|
||||
add_foreign_key :collections, :organizations, on_delete: :nullify, validate: false
|
||||
add_foreign_key :credits, :organizations, on_delete: :restrict, validate: false
|
||||
add_foreign_key :display_ads, :organizations, on_delete: :cascade, validate: false
|
||||
add_foreign_key :classified_listings, :organizations, on_delete: :cascade, validate: false
|
||||
add_foreign_key :notifications, :organizations, on_delete: :cascade, validate: false
|
||||
add_foreign_key :organization_memberships, :organizations, on_delete: :cascade, validate: false
|
||||
end
|
||||
end
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2020_08_21_035520) do
|
||||
ActiveRecord::Schema.define(version: 2020_08_22_092853) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "citext"
|
||||
|
|
@ -1355,6 +1355,7 @@ ActiveRecord::Schema.define(version: 2020_08_21_035520) do
|
|||
add_foreign_key "ahoy_messages", "users", on_delete: :cascade
|
||||
add_foreign_key "ahoy_visits", "users", on_delete: :cascade
|
||||
add_foreign_key "api_secrets", "users", on_delete: :cascade
|
||||
add_foreign_key "articles", "organizations", on_delete: :nullify
|
||||
add_foreign_key "audit_logs", "users"
|
||||
add_foreign_key "badge_achievements", "badges"
|
||||
add_foreign_key "badge_achievements", "users"
|
||||
|
|
@ -1363,9 +1364,13 @@ ActiveRecord::Schema.define(version: 2020_08_21_035520) do
|
|||
add_foreign_key "classified_listing_endorsements", "classified_listings"
|
||||
add_foreign_key "classified_listing_endorsements", "users"
|
||||
add_foreign_key "classified_listings", "classified_listing_categories"
|
||||
add_foreign_key "classified_listings", "organizations", on_delete: :cascade
|
||||
add_foreign_key "classified_listings", "users", on_delete: :cascade
|
||||
add_foreign_key "collections", "organizations", on_delete: :nullify
|
||||
add_foreign_key "credits", "organizations", on_delete: :restrict
|
||||
add_foreign_key "display_ad_events", "display_ads", on_delete: :cascade
|
||||
add_foreign_key "display_ad_events", "users", on_delete: :cascade
|
||||
add_foreign_key "display_ads", "organizations", on_delete: :cascade
|
||||
add_foreign_key "email_authorizations", "users", on_delete: :cascade
|
||||
add_foreign_key "html_variant_successes", "articles", on_delete: :nullify
|
||||
add_foreign_key "html_variant_successes", "html_variants", on_delete: :cascade
|
||||
|
|
@ -1375,10 +1380,12 @@ ActiveRecord::Schema.define(version: 2020_08_21_035520) do
|
|||
add_foreign_key "messages", "chat_channels"
|
||||
add_foreign_key "messages", "users"
|
||||
add_foreign_key "notification_subscriptions", "users", on_delete: :cascade
|
||||
add_foreign_key "notifications", "organizations", on_delete: :cascade
|
||||
add_foreign_key "oauth_access_grants", "oauth_applications", column: "application_id"
|
||||
add_foreign_key "oauth_access_grants", "users", column: "resource_owner_id"
|
||||
add_foreign_key "oauth_access_tokens", "oauth_applications", column: "application_id"
|
||||
add_foreign_key "oauth_access_tokens", "users", column: "resource_owner_id"
|
||||
add_foreign_key "organization_memberships", "organizations", on_delete: :cascade
|
||||
add_foreign_key "page_views", "articles", on_delete: :cascade
|
||||
add_foreign_key "podcast_episodes", "podcasts", on_delete: :cascade
|
||||
add_foreign_key "podcasts", "users", column: "creator_id"
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ RSpec.describe LinkTag, type: :liquid_tag do
|
|||
let(:article) do
|
||||
create(:article, user_id: user.id, title: "test this please", tags: "html, rss, css")
|
||||
end
|
||||
let(:org) { build_stubbed(:organization) }
|
||||
let(:org) { create(:organization) }
|
||||
let(:org_user) do
|
||||
user = create(:user)
|
||||
build_stubbed(:organization_membership, user: user, organization: org)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ RSpec.describe ListingTag, type: :liquid_tag do
|
|||
updated_at: datetime,
|
||||
)
|
||||
end
|
||||
let(:org) { build_stubbed(:organization) }
|
||||
let(:org) { create(:organization) }
|
||||
let(:org_user) do
|
||||
user = create(:user)
|
||||
create(:organization_membership, user: user, organization: org)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ RSpec.describe OrganizationPolicy, type: :policy do
|
|||
subject(:organization_policy) { described_class.new(user, org) }
|
||||
|
||||
let(:user) { build_stubbed(:user) }
|
||||
let(:org) { build_stubbed(:organization) }
|
||||
let(:org) { create(:organization) }
|
||||
|
||||
before do
|
||||
create(:organization_membership, user: user, organization: org, type_of_user: "admin")
|
||||
|
|
@ -43,7 +43,7 @@ RSpec.describe OrganizationPolicy, type: :policy do
|
|||
subject(:organization_policy) { described_class.new(user, new_org) }
|
||||
|
||||
let(:user) { build_stubbed(:user) }
|
||||
let(:org) { build_stubbed(:organization) }
|
||||
let(:org) { create(:organization) }
|
||||
let(:new_org) { build_stubbed(:organization) }
|
||||
|
||||
before { create(:organization_membership, user: user, organization: org, type_of_user: "admin") }
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe "ArticlesUpdate", type: :request do
|
||||
let(:organization) { build_stubbed(:organization) }
|
||||
let(:organization) { create(:organization) }
|
||||
let(:organization2) { create(:organization) }
|
||||
let(:user) { create(:user, :org_admin) }
|
||||
let(:user2) do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue