mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
Uncouple migrations from models
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
class EnsureShippingMethodsHaveDistributors < ActiveRecord::Migration
|
||||
class Enterprise < ActiveRecord::Base
|
||||
scope :is_distributor, where(is_distributor: true)
|
||||
end
|
||||
|
||||
def up
|
||||
d = Enterprise.is_distributor.first
|
||||
sms = Spree::ShippingMethod.where('distributor_id IS NULL')
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
class AddForeignKeys < ActiveRecord::Migration
|
||||
class AdjustmentMetadata < ActiveRecord::Base; end
|
||||
class CoordinatorFee < ActiveRecord::Base; end
|
||||
class Enterprise < ActiveRecord::Base
|
||||
belongs_to :address, :class_name => 'Spree::Address'
|
||||
end
|
||||
class ExchangeVariant < ActiveRecord::Base; end
|
||||
class Spree::InventoryUnit < ActiveRecord::Base; end
|
||||
class Spree::LineItem < ActiveRecord::Base; end
|
||||
class Spree::Address < ActiveRecord::Base; end
|
||||
class Spree::Order < ActiveRecord::Base; end
|
||||
class Spree::Taxon < ActiveRecord::Base; end
|
||||
class CoordinatorFee < ActiveRecord::Base; end
|
||||
|
||||
def change
|
||||
setup_foreign_keys
|
||||
@@ -60,6 +63,7 @@ class AddForeignKeys < ActiveRecord::Migration
|
||||
|
||||
address = Spree::Address.create!(firstname: 'Dummy distributor', lastname: 'Dummy distributor', phone: '12345678', state: state,
|
||||
address1: 'Dummy distributor', city: 'Dummy distributor', zipcode: '1234', country: country)
|
||||
Enterprise.reset_column_information
|
||||
deleted_distributor = Enterprise.create!(name: "Deleted distributor", address: address)
|
||||
|
||||
orphaned_orders = Spree::Order.joins('LEFT OUTER JOIN enterprises ON enterprises.id=spree_orders.distributor_id').where('enterprises.id IS NULL')
|
||||
|
||||
@@ -7,7 +7,7 @@ class AddOwnerToEnterprise < ActiveRecord::Migration
|
||||
owner = e.users.find{ |u| !u.admin? }
|
||||
admin_owner = e.users.find &:admin?
|
||||
any_admin = Spree::User.admin.first
|
||||
any_user = Spree::User.first
|
||||
any_user = Spree::User.first || Spree::User.new(email: 'owner@example.com', password: 'owner123').tap { |u| u.save(validate: false) }
|
||||
e.update_column :owner_id, (owner || admin_owner || any_admin || any_user )
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user