From 8955ffe1261c0604ec44cb22e9611f36afbae3fd Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 25 Feb 2026 13:47:13 +1100 Subject: [PATCH] AddOwnerToSpreeVariants [migration] Should existing variants be migrated to have an owner (copied from supplier)? No, because you can change supplier. This concept needs work. --- app/models/spree/variant.rb | 1 + db/migrate/20260225022934_add_owner_to_spree_variants.rb | 8 ++++++++ db/schema.rb | 2 ++ spec/models/spree/variant_spec.rb | 1 + 4 files changed, 12 insertions(+) create mode 100644 db/migrate/20260225022934_add_owner_to_spree_variants.rb diff --git a/app/models/spree/variant.rb b/app/models/spree/variant.rb index 16002013c5..8276164fbc 100644 --- a/app/models/spree/variant.rb +++ b/app/models/spree/variant.rb @@ -40,6 +40,7 @@ module Spree belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', optional: false belongs_to :primary_taxon, class_name: 'Spree::Taxon', touch: true, optional: false belongs_to :supplier, class_name: 'Enterprise', optional: false, touch: true + belongs_to :owner, class_name: 'Enterprise', optional: true delegate :name, :name=, :description, :description=, :meta_keywords, to: :product diff --git a/db/migrate/20260225022934_add_owner_to_spree_variants.rb b/db/migrate/20260225022934_add_owner_to_spree_variants.rb new file mode 100644 index 0000000000..d74c902eb2 --- /dev/null +++ b/db/migrate/20260225022934_add_owner_to_spree_variants.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class AddOwnerToSpreeVariants < ActiveRecord::Migration[7.1] + def change + add_column :spree_variants, :owner_id, :integer + add_foreign_key :spree_variants, :enterprises, column: :owner_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 72a13aa378..9db50b5bf2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1009,6 +1009,7 @@ ActiveRecord::Schema[7.1].define(version: 2026_03_06_015040) do t.bigint "supplier_id" t.float "variant_unit_scale" t.string "variant_unit_name", limit: 255 + t.integer "owner_id" t.index ["primary_taxon_id"], name: "index_spree_variants_on_primary_taxon_id" t.index ["product_id"], name: "index_variants_on_product_id" t.index ["shipping_category_id"], name: "index_spree_variants_on_shipping_category_id" @@ -1270,6 +1271,7 @@ ActiveRecord::Schema[7.1].define(version: 2026_03_06_015040) do add_foreign_key "spree_tax_rates", "spree_zones", column: "zone_id", name: "spree_tax_rates_zone_id_fk" add_foreign_key "spree_users", "spree_addresses", column: "bill_address_id", name: "spree_users_bill_address_id_fk" add_foreign_key "spree_users", "spree_addresses", column: "ship_address_id", name: "spree_users_ship_address_id_fk" + add_foreign_key "spree_variants", "enterprises", column: "owner_id" add_foreign_key "spree_variants", "enterprises", column: "supplier_id" add_foreign_key "spree_variants", "spree_products", column: "product_id", name: "spree_variants_product_id_fk" add_foreign_key "spree_variants", "spree_shipping_categories", column: "shipping_category_id" diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index 92138a0ea2..38655f5f1f 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -8,6 +8,7 @@ RSpec.describe Spree::Variant do it { is_expected.to have_many :semantic_links } it { is_expected.to belong_to(:product).required } it { is_expected.to belong_to(:supplier).required } + it { is_expected.to belong_to(:owner).optional } it { is_expected.to have_many(:inventory_units) } it { is_expected.to have_many(:line_items) } it { is_expected.to have_many(:stock_items) }