Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrations to fix up default store and store_id on orders #1230

Merged
merged 2 commits into from
Jun 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ def change
s.seo_title = preference_store.get('spree/app_configuration/default_seo_title') {}
s.default_currency = preference_store.get('spree/app_configuration/currency') {}
s.code = 'spree'
s.default = true
end.save!
end
end
13 changes: 13 additions & 0 deletions core/db/migrate/20160608162651_ensure_default_store.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class EnsureDefaultStore < ActiveRecord::Migration
class Store < ActiveRecord::Base
self.table_name = 'spree_stores'
end

def up
unless Store.where(default: true).exists?
store = Store.first
raise "Database has no stores. One should have been created in a previous migration." unless store
store.update_column(:default, true)
end
end
end
12 changes: 12 additions & 0 deletions core/db/migrate/20160608180751_ensure_store_on_orders.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class EnsureStoreOnOrders < ActiveRecord::Migration
class Store < ActiveRecord::Base
self.table_name = 'spree_stores'
end
class Order < ActiveRecord::Base
self.table_name = 'spree_orders'
end
def up
default_store = Store.find_by(default: true)
Order.where(store_id: nil).update_all(store_id: default_store.id)
end
end