mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Migrate master variant :sku to product
(cherry picked from commit d8649fc9fb)
This commit is contained in:
@@ -75,7 +75,7 @@ module Spree
|
||||
)
|
||||
}
|
||||
|
||||
delegate_belongs_to :master, :images, :sku
|
||||
delegate_belongs_to :master, :images
|
||||
delegate :images_attributes=, to: :master
|
||||
|
||||
# Transient attributes used temporarily when creating a new product,
|
||||
|
||||
24
db/migrate/20230522090252_add_sku_to_product.rb
Normal file
24
db/migrate/20230522090252_add_sku_to_product.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
class AddSkuToProduct < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
add_column :spree_products, :sku, :string, limit: 255, default: "", null: false
|
||||
|
||||
migrate_master_sku
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :spree_products, :sku
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def migrate_master_sku
|
||||
ActiveRecord::Base.connection.execute(<<-SQL
|
||||
UPDATE spree_products
|
||||
SET sku = spree_variants.sku
|
||||
FROM spree_variants
|
||||
WHERE spree_variants.product_id = spree_products.id
|
||||
AND spree_variants.is_master = true
|
||||
SQL
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -745,6 +745,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_22_120633) do
|
||||
t.text "notes"
|
||||
t.integer "primary_taxon_id", null: false
|
||||
t.boolean "inherits_properties", default: true, null: false
|
||||
t.string "sku", limit: 255, default: "", null: false
|
||||
t.index ["available_on"], name: "index_products_on_available_on"
|
||||
t.index ["deleted_at"], name: "index_products_on_deleted_at"
|
||||
t.index ["name"], name: "index_products_on_name"
|
||||
|
||||
Reference in New Issue
Block a user