Migrate spree_variants.on_demand to spree_stock_items.backorderable

This commit is contained in:
luisramos0
2019-05-01 15:54:17 +01:00
parent 380a9c561e
commit 42d1d3eff6
3 changed files with 18 additions and 2 deletions

View File

@@ -2,6 +2,6 @@
class RemoveOnDemandFromProductAndVariant < ActiveRecord::Migration
def change
remove_column :spree_products, :on_demand
remove_column :spree_variants, :on_demand
# we are removing spree_variants.on_demand in a later migration
end
end

View File

@@ -0,0 +1,16 @@
class MigrateVariantsOnDemandToStockItemsBackorderable < ActiveRecord::Migration
def up
# We use SQL directly here to avoid going through VariantStock.on_demand and VariantStock.on_demand=
sql = "update spree_stock_items set backorderable = (select on_demand from spree_variants where spree_variants.id = spree_stock_items.variant_id)"
ActiveRecord::Base.connection.execute(sql)
remove_column :spree_variants, :on_demand
end
def down
add_column :spree_variants, :on_demand, :boolean, :default => false
sql = "update spree_variants set on_demand = (select backorderable from spree_stock_items where spree_variants.id = spree_stock_items.variant_id)"
ActiveRecord::Base.connection.execute(sql)
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20190320111312) do
ActiveRecord::Schema.define(:version => 20190501143327) do
create_table "adjustment_metadata", :force => true do |t|
t.integer "adjustment_id"