mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
add rollback to migration
This commit is contained in:
@@ -12,13 +12,36 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration
|
||||
end
|
||||
|
||||
def down
|
||||
# This process is lossy. Producer profiles wont exist.
|
||||
add_column :enterprises, :type, :string, null: false, default: 'profile'
|
||||
add_column :enterprises, :is_distributor, :boolean
|
||||
|
||||
Enterprise.all.each do |enterprise|
|
||||
enterprise.type = type?(enterprise)
|
||||
enterprise.is_distributor = distributes?(enterprise)
|
||||
enterprise.save!
|
||||
end
|
||||
|
||||
remove_column :enterprises, :sells
|
||||
end
|
||||
|
||||
def sells_what?(enterprise)
|
||||
is_distributor = enterprise.read_attribute(:is_distributor)
|
||||
type = enterprise.read_attribute(:type)
|
||||
return "none" if !is_distributor || type == "profile"
|
||||
return "own" if type == "single" || enterprise.suppliers == [enterprise]
|
||||
return "own" if type == "single"
|
||||
return "any"
|
||||
end
|
||||
|
||||
def distributes?(enterprise)
|
||||
return true if enterprise.read_attribute(:sells) != "none"
|
||||
return false
|
||||
end
|
||||
|
||||
def type?(enterprise)
|
||||
sells = enterprise.read_attribute(:sells)
|
||||
return "profile" if !enterprise.is_primary_producer and sells == "none"
|
||||
return "single" if sells == "own"
|
||||
return "full"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user