Skip to content

Commit 448d27b

Browse files
committed
AddOwnerToSpreeVariants [migration]
Should existing variants be migrated to have an owner (copied from supplier)? No, because you can change supplier. This concept needs work.
1 parent fa71e39 commit 448d27b

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

app/models/spree/variant.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Variant < ApplicationRecord
4040
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', optional: false
4141
belongs_to :primary_taxon, class_name: 'Spree::Taxon', touch: true, optional: false
4242
belongs_to :supplier, class_name: 'Enterprise', optional: false, touch: true
43+
belongs_to :owner, class_name: 'Enterprise', optional: true
4344

4445
delegate :name, :name=, :description, :description=, :meta_keywords, to: :product
4546

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AddOwnerToSpreeVariants < ActiveRecord::Migration[7.1]
2+
def change
3+
add_column :spree_variants, :owner_id, :integer
4+
add_foreign_key :spree_variants, :enterprises, column: :owner_id
5+
end
6+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.1].define(version: 2026_02_11_055758) do
13+
ActiveRecord::Schema[7.1].define(version: 2026_02_25_022934) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pg_stat_statements"
1616
enable_extension "plpgsql"
@@ -994,6 +994,7 @@
994994
t.bigint "supplier_id"
995995
t.float "variant_unit_scale"
996996
t.string "variant_unit_name", limit: 255
997+
t.integer "owner_id"
997998
t.index ["primary_taxon_id"], name: "index_spree_variants_on_primary_taxon_id"
998999
t.index ["product_id"], name: "index_variants_on_product_id"
9991000
t.index ["shipping_category_id"], name: "index_spree_variants_on_shipping_category_id"
@@ -1252,6 +1253,7 @@
12521253
add_foreign_key "spree_tax_rates", "spree_zones", column: "zone_id", name: "spree_tax_rates_zone_id_fk"
12531254
add_foreign_key "spree_users", "spree_addresses", column: "bill_address_id", name: "spree_users_bill_address_id_fk"
12541255
add_foreign_key "spree_users", "spree_addresses", column: "ship_address_id", name: "spree_users_ship_address_id_fk"
1256+
add_foreign_key "spree_variants", "enterprises", column: "owner_id"
12551257
add_foreign_key "spree_variants", "enterprises", column: "supplier_id"
12561258
add_foreign_key "spree_variants", "spree_products", column: "product_id", name: "spree_variants_product_id_fk"
12571259
add_foreign_key "spree_variants", "spree_shipping_categories", column: "shipping_category_id"

spec/models/spree/variant_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
it { is_expected.to have_many :semantic_links }
99
it { is_expected.to belong_to(:product).required }
1010
it { is_expected.to belong_to(:supplier).required }
11+
it { is_expected.to belong_to(:owner) }
1112
it { is_expected.to have_many(:inventory_units) }
1213
it { is_expected.to have_many(:line_items) }
1314
it { is_expected.to have_many(:stock_items) }

0 commit comments

Comments
 (0)