AddOwnerToSpreeVariants [migration]

Should existing variants be migrated to have an owner (copied from supplier)? No, because you can change supplier. This concept needs work.
This commit is contained in:
David Cook
2026-02-25 13:47:13 +11:00
parent b26152cf0e
commit 8955ffe126
4 changed files with 12 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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) }