Merge master into producer-emails.

This commit is contained in:
Paul Mackay
2015-03-04 19:09:43 +00:00
468 changed files with 11434 additions and 3239 deletions

View File

@@ -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')

View File

@@ -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')

View File

@@ -8,6 +8,7 @@ class AddOwnerToEnterprise < ActiveRecord::Migration
admin_owner = e.users.find &:admin?
any_admin = Spree::User.admin.first
any_user = Spree::User.first
any_user ||= 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

View File

@@ -1,22 +1,17 @@
class EnterpriseConfigRefactor < ActiveRecord::Migration
class Enterprise < ActiveRecord::Base
self.inheritance_column = nil
end
def up
add_column :enterprises, :sells, :string, null: false, default: 'none'
add_index :enterprises, :sells
add_index :enterprises, [:is_primary_producer, :sells]
# Combine is_distributor and type into sells.
db.select_values("SELECT id FROM enterprises").each do |enterprise_id|
distributor = db.select_values("SELECT is_distributor FROM enterprises WHERE id = #{db.quote(enterprise_id)}")
primary_producer = db.select_value("SELECT is_distributor FROM enterprises WHERE id = #{db.quote(enterprise_id)}")
type = db.select_value("SELECT type FROM enterprises WHERE id = #{db.quote(enterprise_id)}")
if type == "single" && (distributor || primary_producer)
sells = "own"
elsif !distributor || type == "profile"
sells = "none"
else
sells = "any"
end
db.update("UPDATE enterprises SET sells = #{db.quote(sells)} WHERE id = #{db.quote(enterprise_id)}")
Enterprise.reset_column_information
Enterprise.all.each do |enterprise|
enterprise.update_attributes!({:sells => sells_what?(enterprise)})
end
remove_column :enterprises, :type
@@ -28,25 +23,35 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration
add_column :enterprises, :type, :string, null: false, default: 'profile'
add_column :enterprises, :is_distributor, :boolean
# Combine is_distributor and type into sells.
db.select_values("SELECT id FROM enterprises").each do |enterprise_id|
sells = db.select_value("SELECT sells FROM enterprises WHERE id = #{db.quote(enterprise_id)}")
case sells
when "own"
type = "single"
when "any"
type = "full"
else
type = "profile"
end
distributor = sells != "none"
db.update("UPDATE enterprises SET type = #{db.quote(type)}, is_distributor = #{db.quote(distributor)} WHERE id = #{db.quote(enterprise_id)}")
Enterprise.reset_column_information
Enterprise.all.each do |enterprise|
enterprise.update_attributes!({
:type => type?(enterprise),
:is_distributor => distributes?(enterprise)
})
end
remove_column :enterprises, :sells
end
def db
ActiveRecord::Base.connection
def sells_what?(enterprise)
is_distributor = enterprise.read_attribute(:is_distributor)
is_primary_producer = enterprise.read_attribute(:is_primary_producer)
type = enterprise.read_attribute(:type)
return "own" if type == "single" && (is_distributor || is_primary_producer)
return "none" if !is_distributor || type == "profile"
return "any"
end
def distributes?(enterprise)
enterprise.read_attribute(:sells) != "none"
end
def type?(enterprise)
sells = enterprise.read_attribute(:sells)
return "profile" if sells == "none"
return "single" if sells == "own"
return "full"
end
end

View File

@@ -0,0 +1,5 @@
class AddShopTrialStartDateToEnterprises < ActiveRecord::Migration
def change
add_column :enterprises, :shop_trial_start_date, :datetime, default: nil
end
end

View File

@@ -0,0 +1,5 @@
class AddProducerProfileOnlyToEnterprises < ActiveRecord::Migration
def change
add_column :enterprises, :producer_profile_only, :boolean, default: false
end
end

View File

@@ -0,0 +1,15 @@
class CreateVariantOverrides < ActiveRecord::Migration
def change
create_table :variant_overrides do |t|
t.references :variant
t.references :hub
t.decimal :price, precision: 8, scale: 2
t.integer :count_on_hand
end
add_foreign_key :variant_overrides, :spree_variants, column: :variant_id
add_foreign_key :variant_overrides, :enterprises, column: :hub_id
add_index :variant_overrides, [:variant_id, :hub_id]
end
end

View File

@@ -0,0 +1,6 @@
class AddNotNullToVariantOverrideRelations < ActiveRecord::Migration
def change
change_column :variant_overrides, :hub_id, :integer, null: false
change_column :variant_overrides, :variant_id, :integer, null: false
end
end

View File

@@ -0,0 +1,23 @@
class AddPermalinkToEnterprises < ActiveRecord::Migration
def up
add_column :enterprises, :permalink, :string
Enterprise.all.each do |enterprise|
counter = 1
permalink = enterprise.name.parameterize
permalink = "my-enterprise-name" if permalink == ""
while Enterprise.find_by_permalink(permalink) do
permalink = enterprise.name.parameterize + counter.to_s
counter += 1
end
enterprise.update_attributes!(permalink: permalink)
end
change_column :enterprises, :permalink, :string, null: false
end
def down
remove_column :enterprises, :permalink
end
end

View File

@@ -0,0 +1,6 @@
class AddAddressesRefToEnterpriseGroups < ActiveRecord::Migration
def change
add_column :enterprise_groups, :address_id, :integer
add_foreign_key :enterprise_groups, :spree_addresses, column: "address_id"
end
end

View File

@@ -0,0 +1,19 @@
class AddAddressInstancesToExistingEnterpriseGroups < ActiveRecord::Migration
def change
country = Spree::Country.find_by_name(ENV['DEFAULT_COUNTRY'])
state = country.states.first
EnterpriseGroup.all.each do |g|
next if g.address.present?
address = Spree::Address.new(firstname: 'unused', lastname: 'unused', address1: 'undefined', city: 'undefined', zipcode: 'undefined', state: state, country: country, phone: 'undefined')
g.address = address
# some groups are invalid, because of a missing description
g.save!(validate: false)
end
end
def self.down
# we can't know which addresses were already there and which weren't
# and we can't remove addresses as long as they are referenced and
# required by the model
end
end

View File

@@ -0,0 +1,10 @@
class AddWebContactToEnterpriseGroups < ActiveRecord::Migration
def change
add_column :enterprise_groups, :email, :string, null: false, default: ''
add_column :enterprise_groups, :website, :string, null: false, default: ''
add_column :enterprise_groups, :facebook, :string, null: false, default: ''
add_column :enterprise_groups, :instagram, :string, null: false, default: ''
add_column :enterprise_groups, :linkedin, :string, null: false, default: ''
add_column :enterprise_groups, :twitter, :string, null: false, default: ''
end
end

View File

@@ -0,0 +1,6 @@
class AddOwnerToEnterpriseGroups < ActiveRecord::Migration
def change
add_column :enterprise_groups, :owner_id, :integer
add_foreign_key :enterprise_groups, :spree_users, column: "owner_id"
end
end

View File

@@ -0,0 +1,5 @@
class AddOwnerIndexToEnterpriseGroups < ActiveRecord::Migration
def change
add_index :enterprise_groups, :owner_id
end
end

View File

@@ -0,0 +1,5 @@
class AddAddressIdIndexToEnterpriseGroups < ActiveRecord::Migration
def change
add_index :enterprise_groups, :address_id
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 => 20141229094516) do
ActiveRecord::Schema.define(:version => 20150220035501) do
create_table "adjustment_metadata", :force => true do |t|
t.integer "adjustment_id"
@@ -213,8 +213,19 @@ ActiveRecord::Schema.define(:version => 20141229094516) do
t.string "logo_content_type"
t.integer "logo_file_size"
t.datetime "logo_updated_at"
t.integer "address_id"
t.string "email", :default => "", :null => false
t.string "website", :default => "", :null => false
t.string "facebook", :default => "", :null => false
t.string "instagram", :default => "", :null => false
t.string "linkedin", :default => "", :null => false
t.string "twitter", :default => "", :null => false
t.integer "owner_id"
end
add_index "enterprise_groups", ["address_id"], :name => "index_enterprise_groups_on_address_id"
add_index "enterprise_groups", ["owner_id"], :name => "index_enterprise_groups_on_owner_id"
create_table "enterprise_groups_enterprises", :id => false, :force => true do |t|
t.integer "enterprise_group_id"
t.integer "enterprise_id"
@@ -285,6 +296,9 @@ ActiveRecord::Schema.define(:version => 20141229094516) do
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.datetime "shop_trial_start_date"
t.boolean "producer_profile_only", :default => false
t.string "permalink", :null => false
end
add_index "enterprises", ["address_id"], :name => "index_enterprises_on_address_id"
@@ -1049,6 +1063,15 @@ ActiveRecord::Schema.define(:version => 20141229094516) do
t.integer "state_id"
end
create_table "variant_overrides", :force => true do |t|
t.integer "variant_id", :null => false
t.integer "hub_id", :null => false
t.decimal "price", :precision => 8, :scale => 2
t.integer "count_on_hand"
end
add_index "variant_overrides", ["variant_id", "hub_id"], :name => "index_variant_overrides_on_variant_id_and_hub_id"
add_foreign_key "adjustment_metadata", "enterprises", name: "adjustment_metadata_enterprise_id_fk"
add_foreign_key "adjustment_metadata", "spree_adjustments", name: "adjustment_metadata_adjustment_id_fk", column: "adjustment_id"
@@ -1084,6 +1107,9 @@ ActiveRecord::Schema.define(:version => 20141229094516) do
add_foreign_key "enterprise_fees", "enterprises", name: "enterprise_fees_enterprise_id_fk"
add_foreign_key "enterprise_groups", "spree_addresses", name: "enterprise_groups_address_id_fk", column: "address_id"
add_foreign_key "enterprise_groups", "spree_users", name: "enterprise_groups_owner_id_fk", column: "owner_id"
add_foreign_key "enterprise_groups_enterprises", "enterprise_groups", name: "enterprise_groups_enterprises_enterprise_group_id_fk"
add_foreign_key "enterprise_groups_enterprises", "enterprises", name: "enterprise_groups_enterprises_enterprise_id_fk"
@@ -1206,4 +1232,7 @@ ActiveRecord::Schema.define(:version => 20141229094516) do
add_foreign_key "suburbs", "spree_states", name: "suburbs_state_id_fk", column: "state_id"
add_foreign_key "variant_overrides", "enterprises", name: "variant_overrides_hub_id_fk", column: "hub_id"
add_foreign_key "variant_overrides", "spree_variants", name: "variant_overrides_variant_id_fk", column: "variant_id"
end