mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-17 04:34:24 +00:00
User may have many WebhookEndpoints [migration]
Although we won't be allowing multiple in the this PR, we certainly plan to in the future. The migration helper add_reference couldn't handle the custom column name, so I had to put it together manually.
This commit is contained in:
@@ -38,6 +38,8 @@ module Spree
|
||||
has_many :customers
|
||||
has_many :credit_cards
|
||||
has_many :report_rendering_options, class_name: "::ReportRenderingOptions", dependent: :destroy
|
||||
has_many :webhook_endpoints, dependent: :destroy
|
||||
|
||||
accepts_nested_attributes_for :enterprise_roles, allow_destroy: true
|
||||
|
||||
accepts_nested_attributes_for :bill_address
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddSpreeUserReferenceToWebhookEndpoint < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :webhook_endpoints, :user_id, :bigint, default: 0, null: false
|
||||
add_index :webhook_endpoints, :user_id
|
||||
add_foreign_key :webhook_endpoints, :spree_users, column: :user_id
|
||||
end
|
||||
end
|
||||
@@ -1193,6 +1193,8 @@ ActiveRecord::Schema.define(version: 2023_02_13_160135) do
|
||||
t.string "url", null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.bigint "user_id", default: 0, null: false
|
||||
t.index ["user_id"], name: "index_webhook_endpoints_on_user_id"
|
||||
end
|
||||
|
||||
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
||||
@@ -1299,4 +1301,5 @@ ActiveRecord::Schema.define(version: 2023_02_13_160135) do
|
||||
add_foreign_key "subscriptions", "spree_shipping_methods", column: "shipping_method_id", name: "subscriptions_shipping_method_id_fk"
|
||||
add_foreign_key "variant_overrides", "enterprises", column: "hub_id", name: "variant_overrides_hub_id_fk"
|
||||
add_foreign_key "variant_overrides", "spree_variants", column: "variant_id", name: "variant_overrides_variant_id_fk"
|
||||
add_foreign_key "webhook_endpoints", "spree_users", column: "user_id"
|
||||
end
|
||||
|
||||
@@ -7,6 +7,7 @@ describe Spree::User do
|
||||
|
||||
describe "associations" do
|
||||
it { is_expected.to have_many(:owned_enterprises) }
|
||||
it { is_expected.to have_many(:webhook_endpoints).dependent(:destroy) }
|
||||
|
||||
describe "addresses" do
|
||||
let(:user) { create(:user, bill_address: create(:address)) }
|
||||
|
||||
Reference in New Issue
Block a user