spree install.

This commit is contained in:
Andrew Spinks
2012-03-27 11:06:49 +11:00
parent 4ca90e7a32
commit cd1938a74e
289 changed files with 76431 additions and 243 deletions

View File

@@ -39,3 +39,5 @@ group :test do
# Pretty printed test output
gem 'turn', '~> 0.8.3', :require => false
end
gem 'spree_usa_epay'
gem 'spree_skrill'

View File

@@ -15,6 +15,17 @@ GEM
rack-mount (~> 0.8.2)
rack-test (~> 0.6.1)
sprockets (~> 2.0.3)
active_utils (1.0.3)
activesupport (>= 2.3.11)
i18n
activemerchant (1.20.1)
active_utils (>= 1.0.1)
activesupport (>= 2.3.11)
braintree (>= 2.0.0)
builder (>= 2.0.0)
i18n
json (>= 1.5.1)
money (<= 3.7.1)
activemodel (3.1.4)
activesupport (= 3.1.4)
builder (~> 3.0.0)
@@ -29,9 +40,17 @@ GEM
activesupport (= 3.1.4)
activesupport (3.1.4)
multi_json (~> 1.0)
acts_as_list (0.1.4)
akami (1.0.0)
gyoku (>= 0.4.0)
ansi (1.4.2)
arel (2.2.3)
bcrypt-ruby (3.0.1)
braintree (2.14.0)
builder (>= 2.0.0)
builder (3.0.0)
cancan (1.6.7)
cocaine (0.2.1)
coffee-rails (3.1.1)
coffee-script (>= 2.2.0)
railties (~> 3.1.0)
@@ -39,21 +58,59 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.2.0)
deface (0.8.0)
nokogiri (~> 1.5.0)
rails (>= 3.0.9)
devise (1.4.8)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
warden (~> 1.0.3)
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
ffaker (1.12.1)
gyoku (0.4.4)
builder (>= 2.1.2)
highline (1.6.8)
hike (1.2.1)
httpi (0.9.6)
rack
i18n (0.6.0)
jquery-rails (1.0.19)
railties (~> 3.0)
thor (~> 0.14)
json (1.6.6)
kaminari (0.13.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
railties (>= 3.0.0)
mail (2.3.3)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
meta_search (1.1.1)
actionpack (~> 3.1.0)
activerecord (~> 3.1.0)
activesupport (~> 3.1.0)
polyamorous (~> 0.5.0)
mime-types (1.18)
money (3.7.1)
i18n (~> 0.4)
multi_json (1.1.0)
nested_set (1.6.8)
activerecord (>= 3.0.0)
railties (>= 3.0.0)
nokogiri (1.5.2)
nori (1.1.0)
orm_adapter (0.0.6)
paperclip (2.5.0)
activerecord (>= 2.3.0)
activesupport (>= 2.3.2)
cocaine (>= 0.0.2)
mime-types
pg (0.13.2)
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.3)
rack (1.3.6)
rack-cache (1.2)
@@ -88,11 +145,62 @@ GEM
railties (~> 3.1.0)
sass (>= 3.1.10)
tilt (~> 1.3.2)
savon (0.9.9)
akami (~> 1.0)
builder (>= 2.1.2)
gyoku (>= 0.4.0)
httpi (~> 0.9)
nokogiri (>= 1.4.0)
nori (~> 1.1)
wasabi (~> 2.1)
spree (1.0.2)
spree_api (= 1.0.2)
spree_auth (= 1.0.2)
spree_cmd (= 1.0.2)
spree_core (= 1.0.2)
spree_dash (= 1.0.2)
spree_promo (= 1.0.2)
spree_sample (= 1.0.2)
spree_api (1.0.2)
spree_auth (= 1.0.2)
spree_core (= 1.0.2)
spree_auth (1.0.2)
cancan (= 1.6.7)
devise (= 1.4.8)
spree_core (= 1.0.2)
spree_cmd (1.0.2)
spree_core (1.0.2)
activemerchant (= 1.20.1)
acts_as_list (= 0.1.4)
deface (>= 0.7.2)
ffaker (~> 1.12.0)
highline (= 1.6.8)
jquery-rails (>= 1.0.18, <= 1.0.19)
kaminari (>= 0.13.0)
meta_search (= 1.1.1)
nested_set (= 1.6.8)
paperclip (= 2.5.0)
rails (>= 3.1.1, <= 3.1.4)
state_machine (= 1.1.1)
stringex (~> 1.3.0)
spree_dash (1.0.2)
spree_core (= 1.0.2)
spree_promo (1.0.2)
spree_auth (= 1.0.2)
spree_core (= 1.0.2)
spree_sample (1.0.2)
spree_core (= 1.0.2)
spree_skrill (1.0.1)
spree_core (>= 1.0.0)
spree_usa_epay (1.0.1)
savon
spree_core (>= 1.0.0)
sprockets (2.0.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
state_machine (1.1.1)
stringex (1.3.2)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
@@ -104,6 +212,10 @@ GEM
uglifier (1.2.3)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
warden (1.0.6)
rack (>= 1.0)
wasabi (2.1.0)
nokogiri (>= 1.4.0)
PLATFORMS
ruby
@@ -111,8 +223,11 @@ PLATFORMS
DEPENDENCIES
coffee-rails (~> 3.1.1)
jquery-rails
pg
rails (= 3.1.4)
sass-rails (~> 3.1.5)
sqlite3
spree
spree_skrill
spree_usa_epay
turn (~> 0.8.3)
uglifier (>= 1.0.3)

View File

@@ -0,0 +1,13 @@
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require admin/spree_core
//= require admin/spree_auth
//= require admin/spree_api
//= require admin/spree_promo
//= require_tree .

View File

@@ -0,0 +1,13 @@
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require store/spree_core
//= require store/spree_auth
//= require store/spree_api
//= require store/spree_promo
//= require_tree .

View File

@@ -0,0 +1,14 @@
/*
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*
*= require admin/spree_core
*= require admin/spree_auth
*= require admin/spree_api
*= require admin/spree_promo
*= require_self
*= require_tree .
*/

View File

@@ -0,0 +1,14 @@
/*
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*
*= require store/spree_core
*= require store/spree_auth
*= require store/spree_api
*= require store/spree_promo
*= require_self
*= require_tree .
*/

View File

@@ -11,6 +11,19 @@ end
module Openfoodweb
class Application < Rails::Application
config.to_prepare do
# Load application's model / class decorators
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
# Load application's view overrides
Dir.glob(File.join(File.dirname(__FILE__), "../app/overrides/*.rb")) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.

View File

@@ -3,3 +3,5 @@ require File.expand_path('../application', __FILE__)
# Initialize the rails application
Openfoodweb::Application.initialize!
ActiveRecord::Base.include_root_in_json = true

View File

@@ -0,0 +1,12 @@
# Configure Spree Preferences
#
# Note: Initializing preferences available within the Admin will overwrite any changes that were made through the user interface when you restart.
# If you would like users to be able to update a setting with the Admin it should NOT be set here.
#
# In order to initialize a setting do:
# config.setting_name = 'new value'
Spree.config do |config|
# Example:
# Uncomment to override the default site name.
# config.site_name = "Spree Demo Site"
end

View File

@@ -1,4 +1,6 @@
Openfoodweb::Application.routes.draw do
# Mount Spree's routes
mount Spree::Core::Engine, :at => '/'
# The priority is based upon order of creation:
# first created -> highest priority.

2
config/spree.yml Normal file
View File

@@ -0,0 +1,2 @@
---
version: 1.0.2

View File

@@ -0,0 +1,389 @@
class SpreeZeroNineZero < ActiveRecord::Migration
# This is a legacy migration consolidating all of the database changes needed as of Spree 0.9.0
# (See http://railsdog.lighthouseapp.com/projects/31096-spree/tickets/772)
def change
create_table :addresses, :force => true do |t|
t.string :firstname, :lastname, :address1, :address2, :city,
:zipcode, :phone, :state_name, :alternative_phone
t.references :state
t.references :country
t.timestamps
end
create_table :adjustments, :force => true do |t|
t.integer :position, :adjustment_source_id
t.decimal :amount, :precision => 8, :scale => 2, :default => 0.0, :null => false
t.string :type, :description, :adjustment_source_type, :secondary_type
t.references :order
t.timestamps
end
create_table :assets, :force => true do |t|
t.integer :viewable_id, :attachment_width, :attachment_height,
:attachment_size, :position
t.string :viewable_type, :limit => 50
t.string :attachment_content_type, :attachment_file_name
t.string :type, :limit => 75
t.datetime :attachment_updated_at
end
create_table :calculators, :force => true do |t|
t.string :type
t.integer :calculable_id, :null => false
t.string :calculable_type, :null => false
t.timestamps
end
create_table :checkouts, :force => true do |t|
t.references :order
t.string :email, :ip_address
t.text :special_instructions
t.integer :bill_address_id
t.datetime :completed_at
t.timestamps
end
create_table :configurations, :force => true do |t|
t.string :name
t.string :type, :limit => 50
t.timestamps
end
add_index :configurations, [:name, :type], :name => 'index_configurations_on_name_and_type'
create_table :countries, :force => true do |t|
t.string :iso_name, :iso, :iso3, :name
t.integer :numcode
end
create_table :coupons, :force => true do |t|
t.string :code, :description
t.integer :usage_limit
t.boolean :combine
t.datetime :expires_at, :starts_at
t.timestamps
end
create_table :creditcard_txns, :force => true do |t|
t.integer :creditcard_payment_id, :txn_type
t.decimal :amount, :precision => 8, :scale => 2, :default => 0.0, :null => false
t.string :response_code
t.text :avs_response, :cvv_response
t.timestamps
end
create_table :creditcards, :force => true do |t|
t.text :number, :verification_value
t.string :month, :year, :cc_type, :display_number, :first_name,
:last_name, :start_month, :start_year, :issue_number
t.references :address
t.references :checkout
t.timestamps
end
create_table :gateway_configurations, :force => true do |t|
t.references :gateway
t.timestamps
end
create_table :gateway_option_values, :force => true do |t|
t.references :gateway_configuration
t.references :gateway_option
t.text :value
t.timestamps
end
create_table :gateway_options, :force => true do |t|
t.string :name
t.text :description
t.boolean :textarea, :default => false
t.references :gateway
t.timestamps
end
create_table :gateways, :force => true do |t|
t.string :clazz, :name
t.text :description
t.boolean :active
t.timestamps
end
create_table :inventory_units, :force => true do |t|
t.integer :lock_version, :default => 0
t.string :state
t.references :variant
t.references :order
t.timestamps
end
create_table :line_items, :force => true do |t|
t.references :order
t.references :variant
t.integer :quantity, :null => false
t.decimal :price, :precision => 8, :scale => 2, :null => false
t.timestamps
end
add_index :line_items, :order_id, :name => 'index_line_items_on_order_id'
add_index :line_items, :variant_id, :name => 'index_line_items_on_variant_id'
create_table :option_types, :force => true do |t|
t.string :name, :limit => 100
t.string :presentation, :limit => 100
t.timestamps
end
create_table :option_types_prototypes, :id => false, :force => true do |t|
t.references :prototype
t.references :option_type
end
create_table :option_values, :force => true do |t|
t.integer :position
t.string :name, :presentation
t.references :option_type
t.timestamps
end
create_table :option_values_variants, :id => false, :force => true do |t|
t.integer :variant_id
t.integer :option_value_id
end
add_index :option_values_variants, :variant_id, :name => 'index_option_values_variants_on_variant_id'
create_table :orders, :force => true do |t|
t.string :number, :limit => 15
t.decimal :item_total, :precision => 8, :scale => 2, :default => 0.0, :null => false
t.decimal :total, :precision => 8, :scale => 2, :default => 0.0, :null => false
t.string :state
t.string :token
t.decimal :adjustment_total, :precision => 8, :scale => 2, :default => 0.0, :null => false
t.decimal :credit_total, :precision => 8, :scale => 2, :default => 0.0, :null => false
t.references :user
t.timestamps
end
add_index :orders, :number, :name => 'index_orders_on_number'
create_table :payments, :force => true do |t|
t.decimal :amount, :precision => 8, :scale => 2, :default => 0.0, :null => false
t.string :type
t.references :order
t.references :creditcard
t.timestamps
end
create_table :preferences, :force => true do |t|
t.string :attribute, :null => false, :limit => 100
t.integer :owner_id, :null => false, :limit => 30
t.string :owner_type, :null => false, :limit => 50
t.integer :group_id
t.string :group_type, :limit => 50
t.string :value
t.timestamps
end
add_index :preferences, [:owner_id, :owner_type, :attribute, :group_id, :group_type], :name => 'index_preferences_on_owner_and_attribute_and_preference', :unique => true
create_table :product_option_types, :force => true do |t|
t.integer :position
t.references :product
t.references :option_type
t.timestamps
end
create_table :product_properties, :force => true do |t|
t.string :value
t.references :product
t.references :property
t.timestamps
end
create_table :products, :force => true do |t|
t.string :name, :default => '', :null => false
t.text :description
t.datetime :available_on, :deleted_at
t.string :permalink, :meta_description, :meta_keywords
t.references :tax_category
t.references :shipping_category
t.timestamps
end
add_index :products, :available_on, :name => 'index_products_on_available_on'
add_index :products, :deleted_at, :name => 'index_products_on_deleted_at'
add_index :products, :name, :name => 'index_products_on_name'
add_index :products, :permalink, :name => 'index_products_on_permalink'
create_table :products_taxons, :id => false, :force => true do |t|
t.references :product
t.references :taxon
end
add_index :products_taxons, :product_id, :name => 'index_products_taxons_on_product_id'
add_index :products_taxons, :taxon_id, :name => 'index_products_taxons_on_taxon_id'
create_table :properties, :force => true do |t|
t.string :name
t.string :presentation, :null => false
t.timestamps
end
create_table :properties_prototypes, :id => false, :force => true do |t|
t.references :prototype
t.references :property
end
create_table :prototypes, :force => true do |t|
t.string :name
t.timestamps
end
create_table :roles, :force => true do |t|
t.string :name
end
create_table :roles_users, :id => false, :force => true do |t|
t.references :role
t.references :user
end
add_index :roles_users, :role_id, :name => 'index_roles_users_on_role_id'
add_index :roles_users, :user_id, :name => 'index_roles_users_on_user_id'
create_table :shipments, :force => true do |t|
t.string :tracking, :number
t.decimal :cost, :precision => 8, :scale => 2
t.datetime :shipped_at
t.references :order
t.references :shipping_method
t.references :address
t.timestamps
end
create_table :shipping_categories, :force => true do |t|
t.string :name
t.timestamps
end
create_table :shipping_methods, :force => true do |t|
t.string :name
t.references :zone
t.timestamps
end
create_table :state_events, :force => true do |t|
t.string :name, :previous_state
t.references :order
t.references :user
t.timestamps
end
create_table :states, :force => true do |t|
t.string :name
t.string :abbr
t.references :country
end
create_table :tax_categories, :force => true do |t|
t.string :name, :description
t.timestamps
end
create_table :tax_rates, :force => true do |t|
t.decimal :amount, :precision => 8, :scale => 4
t.references :zone
t.references :tax_category
t.timestamps
end
create_table :taxonomies, :force => true do |t|
t.string :name, :null => false
t.timestamps
end
create_table :taxons, :force => true do |t|
t.integer :parent_id
t.integer :position, :default => 0
t.string :name, :null => false
t.string :permalink
t.references :taxonomy
t.timestamps
end
create_table :users, :force => true do |t|
t.string :crypted_password, :limit => 128, :default => '', :null => false
t.string :salt, :limit => 128, :default => '', :null => false
t.string :email, :remember_token, :remember_token_expires_at,
:persistence_token, :single_access_token, :perishable_token
t.integer :login_count, :default => 0, :null => false
t.integer :failed_login_count, :default => 0, :null => false
t.datetime :last_request_at, :current_login_at, :last_login_at
t.string :current_login_ip, :last_login_ip, :login
t.integer :ship_address_id, :bill_address_id
t.timestamps
end
create_table :variants, :force => true do |t|
t.string :sku, :default => '', :null => false
t.decimal :price, :precision => 8, :scale => 2, :null => false
t.decimal :weight, :precision => 8, :scale => 2
t.decimal :height, :precision => 8, :scale => 2
t.decimal :width, :precision => 8, :scale => 2
t.decimal :depth, :precision => 8, :scale => 2
t.datetime :deleted_at
t.boolean :is_master, :default => false
t.references :product
end
add_index :variants, :product_id, :name => 'index_variants_on_product_id'
create_table :zone_members, :force => true do |t|
t.integer :zoneable_id
t.string :zoneable_type
t.references :zone
t.timestamps
end
create_table :zones, :force => true do |t|
t.string :name, :description
t.timestamps
end
end
end

View File

@@ -0,0 +1,6 @@
class CreateIndexesForInventoryUnits < ActiveRecord::Migration
def change
add_index :inventory_units, :variant_id
add_index :inventory_units, :order_id
end
end

View File

@@ -0,0 +1,49 @@
class AddCountOnHandToVariantsAndProducts < ActiveRecord::Migration
def up
add_column :variants, :count_on_hand, :integer, :default => 0, :null => false
add_column :products, :count_on_hand, :integer, :default => 0, :null => false
# Due to our namespacing changes, this migration (from earlier Spree versions) is broken
# To fix it, temporarily set table name on each of the models involved
# And then...
Spree::Variant.table_name = 'variants'
Spree::Product.table_name = 'products'
Spree::InventoryUnit.table_name = 'inventory_units'
# In some cases needed to reflect changes in table structure
Spree::Variant.reset_column_information
Spree::Product.reset_column_information
say_with_time 'Transfering inventory units with status on_hand to variants table...' do
Spree::Variant.all.each do |v|
v.update_attribute(:count_on_hand, v.inventory_units.with_state('on_hand').size)
Spree::InventoryUnit.destroy_all(:variant_id => v.id, :state => 'on_hand')
end
end
say_with_time 'Updating products count on hand' do
Spree::Product.all.each do |p|
product_count_on_hand = p.has_variants? ?
p.variants.inject(0) { |acc, v| acc + v.count_on_hand } :
(p.master ? p.master.count_on_hand : 0)
p.update_attribute(:count_on_hand, product_count_on_hand)
end
end
# ... Switch things back at the end of the migration
Spree::Variant.table_name = 'spree_variants'
Spree::Product.table_name = 'spree_products'
Spree::InventoryUnit.table_name = 'spree_inventory_units'
end
def down
Spree::Variant.all.each do |v|
v.count_on_hand.times do
Spree::InventoryUnit.create(:variant => variant, :state => 'on_hand')
end
end
remove_column :variants, :count_on_hand
remove_column :products, :count_on_hand
end
end

View File

@@ -0,0 +1,46 @@
class ChangeTaxonsToNestedSet < ActiveRecord::Migration
def up
add_column :taxons, :lft, :integer
add_column :taxons, :rgt, :integer
Spree::Taxon.reset_column_information # So the new root ids get saved
# Temporarily set the table back to taxons
Spree::Taxon.table_name = 'taxons'
Spree::Taxon.class_eval do
# adapted from awesome nested set to use 'position' information
indices = {}
left_column_name = 'lft'
right_column_name = 'rgt'
quoted_parent_column_name = 'parent_id'
scope = lambda{|node|}
set_left_and_rights = lambda do |node|
# set left
node[left_column_name] = indices[scope.call(node)] += 1
# find
where("#{quoted_parent_column_name} = ?", node).order('position ASC').each{ |n| set_left_and_rights.call(n) }
# set right
node[right_column_name] = indices[scope.call(node)] += 1
node.save!
end
# Find root node(s)
where("#{quoted_parent_column_name}" => nil).order('position ASC').each do |root_node|
# setup index for this scope
indices[scope.call(root_node)] ||= 0
set_left_and_rights.call(root_node)
end
end
# Set it back after the migration
Spree::Taxon.table_name = 'spree_taxons'
end
def down
remove_column :taxons, :lft
remove_column :taxons, :rgt
end
end

View File

@@ -0,0 +1,54 @@
class MoveToConfigurableGateways < ActiveRecord::Migration
def up
drop_table :gateways
drop_table :gateway_options
drop_table :gateway_option_values
drop_table :gateway_configurations
create_table :gateways, :force => true do |t|
t.string :type, :name
t.text :description
t.boolean :active, :default => true
t.string :environment, :default => 'development'
t.string :server, :default => 'test'
t.boolean :test_mode, :default => true
t.timestamps
end
end
def down
drop_table :gateways
create_table :gateway_configurations, :force => true do |t|
t.references :gateway
t.timestamps
end
create_table :gateway_option_values, :force => true do |t|
t.text :value
t.references :gateway_configuration
t.references :gateway_option
t.timestamps
end
create_table :gateway_options, :force => true do |t|
t.string :name
t.text :description
t.boolean :textarea, :default => false
t.references :gateway
t.timestamps
end
create_table :gateways, :force => true do |t|
t.string :clazz, :name
t.text :description
t.boolean :active
t.timestamps
end
end
end

View File

@@ -0,0 +1,18 @@
class ProductGroupsAndScopes < ActiveRecord::Migration
def change
create_table :product_groups do |t|
t.string :name, :permalink, :order
end
create_table :product_scopes do |t|
t.string :name
t.text :arguments
t.references :product_group
end
add_index :product_groups, :name
add_index :product_groups, :permalink
add_index :product_scopes, :name
add_index :product_scopes, :product_group_id
end
end

View File

@@ -0,0 +1,15 @@
class AddOpenIdAuthenticationTables < ActiveRecord::Migration
def change
create_table :open_id_authentication_associations, :force => true do |t|
t.integer :issued, :lifetime
t.string :handle, :assoc_type
t.binary :server_url, :secret
end
create_table :open_id_authentication_nonces, :force => true do |t|
t.integer :timestamp, :null => false
t.string :server_url, :null => true
t.string :salt, :null => false
end
end
end

View File

@@ -0,0 +1,24 @@
class AddOpenidFieldToUsers < ActiveRecord::Migration
def up
add_column :users, :openid_identifier, :string
add_index :users, :openid_identifier
change_column :users, :login, :string, :default => nil, :null => true
change_column :users, :crypted_password, :string, :default => nil, :null => true
change_column :users, :salt, :string, :default => nil, :null => true
end
def down
remove_column :users, :openid_identifier
# Due to namespacing change, temporarily set the table back to users
Spree::User.table_name = 'users'
[:login, :crypted_password, :salt].each do |field|
Spree::User.where(field => nil).each { |user| user.update_attribute(field, '') if user.send(field).nil? }
change_column :users, field, :string, :default => '', :null => false
end
Spree::User.table_name = 'spree_users'
end
end

View File

@@ -0,0 +1,10 @@
class ChangePreferenceValueType < ActiveRecord::Migration
def up
remove_index :preferences, :name => 'index_preferences_on_owner_and_attribute_and_preference'
change_column :preferences, :value, :text
end
def down
change_column :preferences, :value, :string
end
end

View File

@@ -0,0 +1,12 @@
class CreateBillingIntegrations < ActiveRecord::Migration
def change
create_table :billing_integrations do |t|
t.string :type, :name
t.text :description
t.boolean :active, :default => true
t.string :environment, :default => 'development'
t.timestamps
end
end
end

View File

@@ -0,0 +1,39 @@
class Checkout < ActiveRecord::Base; end;
# Hack to prevent issues with legacy migrations
class Order < ActiveRecord::Base
has_one :checkout
end
class ChargeRefactoring < ActiveRecord::Migration
def up
# Temporarily set table name for legacy support
Spree::Adjustment.table_name = 'adjustments'
add_column :orders, :completed_at, :timestamp
Order.reset_column_information
Order.all.each { |o| o.update_attribute(:completed_at, o.checkout && o.checkout.read_attribute(:completed_at)) }
remove_column :checkouts, :completed_at
change_column :adjustments, :amount, :decimal, :null => true, :default => nil, :precision => 8, :scale => 2
Spree::Adjustment.update_all :type => 'secondary_type'
Spree::Adjustment.where(:type => 'Credit').update_all(:type => 'CouponCredit')
remove_column :adjustments, :secondary_type
# Reset table name
Spree::Adjustment.table_name = 'spree_adjustments'
end
def down
add_column :checkouts, :completed_at, :timestamp
Spree::Checkout.reset_column_information
Spree::Checkout.all.each { |c| c.update_attribute(:completed_at, c.order && c.order.completed_at) }
remove_column :orders, :completed_at
add_column :adjustments, :secondary_type, :string
Spree::Adjustment.update_all :secondary_type => 'type'
Spree::Adjustment.where('type LIKE ?', '%Charge').update_all(:type => 'Charge')
Spree::Adjustment.where('type LIKE ?', '%Credit').update_all(:type => 'Credit')
change_column :adjustments, :amount, :decimal, :null => false, :default => 0, :precision => 8, :scale => 2
end
end

View File

@@ -0,0 +1,11 @@
class AddSomeIndexes < ActiveRecord::Migration
def change
add_index :taxons, :permalink
add_index :taxons, :parent_id
add_index :taxons, :taxonomy_id
add_index :assets, :viewable_id
add_index :assets, [:viewable_type, :type]
add_index :product_properties, :product_id
add_index :option_values_variants, [:variant_id, :option_value_id]
end
end

View File

@@ -0,0 +1,5 @@
class CheckoutStateMachine < ActiveRecord::Migration
def change
add_column :checkouts, :state, :string
end
end

View File

@@ -0,0 +1,5 @@
class StateForShipments < ActiveRecord::Migration
def change
add_column :shipments, :state, :string
end
end

View File

@@ -0,0 +1,12 @@
class MakeStateEventsPolymorphic < ActiveRecord::Migration
def up
rename_column :state_events, :order_id, :stateful_id
add_column :state_events, :stateful_type, :string
execute "UPDATE state_events SET stateful_type = 'Order'"
end
def down
rename_column :state_events, :stateful_id, :order_id
remove_column :state_events, :stateful_type
end
end

View File

@@ -0,0 +1,5 @@
class ShipAddressIdForCheckouts < ActiveRecord::Migration
def change
add_column :checkouts, :ship_address_id, :integer
end
end

View File

@@ -0,0 +1,5 @@
class ShippingMethodIdForCheckouts < ActiveRecord::Migration
def change
add_column :checkouts, :shipping_method_id, :integer
end
end

View File

@@ -0,0 +1,14 @@
class CreditcardLastFourDigits < ActiveRecord::Migration
def up
rename_column :creditcards, :display_number, :last_digits
creditcards = select_all "SELECT * FROM creditcards"
creditcards.each do |card|
execute "UPDATE creditcards SET last_digits = '#{card['last_digits'].gsub('XXXX-XXXX-XXXX-', '')}' WHERE id = #{card['id']}" if card['last_digits'].present?
end
end
def down
rename_column :creditcards, :last_digits, :display_number
end
end

View File

@@ -0,0 +1,15 @@
class PopulateLegacyShipmentState < ActiveRecord::Migration
def up
shipments = select_all "SELECT * FROM shipments"
shipments.each do |shipment|
if shipment['shipped_at']
execute "UPDATE shipments SET state = 'shipped'"
else
execute "UPDATE shipments SET state = 'pending'"
end
end
end
def down
end
end

View File

@@ -0,0 +1,5 @@
class AddCostPrice < ActiveRecord::Migration
def change
add_column :variants, :cost_price, :decimal, :null => true, :default => nil, :precision => 8, :scale => 2
end
end

View File

@@ -0,0 +1,25 @@
class ShipmentIdForInventoryUnits < ActiveRecord::Migration
def up
add_column :inventory_units, :shipment_id, :integer
add_index :inventory_units, :shipment_id
# migrate legacy shipments
Spree::Shipment.table_name = 'shipments'
Spree::Shipment.all.each do |shipment|
unless shipment.order
puts "Warning: shipment has invalid order - #{shipment.id}"
next
end
shipment.order.inventory_units.each do |unit|
unit.update_attribute('shipment_id', shipment.id)
end
end
Spree::Shipment.table_name = 'spree_shipments'
end
def down
remove_column :inventory_units, :shipment_id
end
end

View File

@@ -0,0 +1,6 @@
class CimFieldsForCreditcards < ActiveRecord::Migration
def change
add_column :creditcards, :gateway_customer_profile_id, :string
add_column :creditcards, :gateway_payment_profile_id, :string
end
end

View File

@@ -0,0 +1,12 @@
class CreateReturnAuthorizations < ActiveRecord::Migration
def change
create_table :return_authorizations do |t|
t.string :number, :state
t.decimal :amount, :precision => 8, :scale => 2, :default => 0.0, :null => false
t.references :order
t.text :reason
t.timestamps
end
end
end

View File

@@ -0,0 +1,5 @@
class AddReturnAuthorizationToInventoryUnits < ActiveRecord::Migration
def change
add_column :inventory_units, :return_authorization_id, :integer
end
end

View File

@@ -0,0 +1,10 @@
class CreateTrackers < ActiveRecord::Migration
def change
create_table :trackers do |t|
t.string :environment, :analytics_id
t.boolean :active, :default => true
t.timestamps
end
end
end

View File

@@ -0,0 +1,5 @@
class CreditcardIdForCreditcardTxns < ActiveRecord::Migration
def change
add_column :creditcard_txns, :creditcard_id, :integer
end
end

View File

@@ -0,0 +1,5 @@
class OriginalCreditcardTxnIdForCreditcardTxns < ActiveRecord::Migration
def change
add_column :creditcard_txns, :original_creditcard_txn_id, :integer
end
end

View File

@@ -0,0 +1,6 @@
class AddTestModeToBillingIntegration < ActiveRecord::Migration
def change
add_column :billing_integrations, :test_mode, :boolean, :default => true
add_column :billing_integrations, :server, :string, :default => 'test'
end
end

View File

@@ -0,0 +1,8 @@
class CreateProductsProductGroups < ActiveRecord::Migration
def change
create_table :product_groups_products, :id => false do |t|
t.references :product
t.references :product_group
end
end
end

View File

@@ -0,0 +1,16 @@
class CreatePaymentMethods < ActiveRecord::Migration
def change
create_table :payment_methods do |t|
t.string :type, :name
t.text :description
t.boolean :active, :default => true
t.string :environment, :default => 'development'
t.timestamps
end
# TODO - also migrate any legacy configurations for gateways and billing integrations before dropping the old tables
# we probably also need to do this inside the payment_gateway extension b/c table won't exist yet in fresh bootstrap
#drop_table :billing_integrations
#drop_table :gateways
end
end

View File

@@ -0,0 +1,42 @@
# Legacy table support
class Checkout < ActiveRecord::Base; end;
class PolymorphicPayments < ActiveRecord::Migration
def up
remove_column :payments, :type
remove_column :payments, :creditcard_id
rename_column :payments, :order_id, :payable_id
change_table :payments do |t|
t.string :payable_type, :payment_method
t.references :source, :polymorphic => true
end
execute "UPDATE payments SET payable_type = 'Order'"
Spree::Creditcard.table_name = 'creditcards'
Spree::Creditcard.all.each do |creditcard|
if checkout = Checkout.find_by_id(creditcard.checkout_id) and checkout.order
if payment = checkout.order.payments.first
execute "UPDATE payments SET source_type = 'Creditcard', source_id = #{creditcard.id} WHERE id = #{payment.id}"
end
end
end
Spree::Creditcard.table_name = 'spree_creditcards'
remove_column :creditcards, :checkout_id
end
def down
add_column :creditcards, :checkout_id, :integer
change_table :payments do |t|
t.remove :payable_type
t.remove :payment_method
t.remove :source_id
t.remove :source_type
end
rename_column :payments, :payable_id, :order_id
add_column :payments, :creditcard_id, :integer
add_column :payments, :type, :string
end
end

View File

@@ -0,0 +1,11 @@
class ChangePaymentsPaymentMethodToBelongsTo < ActiveRecord::Migration
def up
remove_column :payments, :payment_method
add_column :payments, :payment_method_id, :integer
end
def down
add_column :payments, :payment_method, :string
remove_column :payments, :payment_method_id
end
end

View File

@@ -0,0 +1,23 @@
class AssignCreditcardTxnsToPayment < ActiveRecord::Migration
def up
add_column :creditcard_txns, :payment_id, :integer
# Temporarily set back to creditcards
Spree::Creditcard.table_name = 'creditcards'
ActiveRecord::Base.connection.select_all('SELECT * FROM creditcard_txns').each do |txn_attrs|
if creditcard = Spree::Creditcard.find_by_id(txn_attrs['creditcard_id']) and creditcard.payments.first
execute "UPDATE creditcard_txns SET payment_id = #{creditcard.payments.first.id} WHERE id = #{txn_attrs['id']}"
end
end
Spree::Creditcard.table_name = 'spree_creditcards'
remove_column :creditcard_txns, :creditcard_payment_id
end
def down
remove_column :creditcard_txns, :payment_id
add_column :creditcard_txns, :creditcard_payment_id, :integer
end
end

View File

@@ -0,0 +1,15 @@
class StiForTransactions < ActiveRecord::Migration
def up
rename_table :creditcard_txns, :transactions
add_column :transactions, :type, :string
remove_column :transactions, :creditcard_id
execute "UPDATE transactions SET type = 'CreditcardTxn'"
end
def down
rename_table :transactions, :creditcard_txns
remove_column :transactions, :type
add_column :transactions, :creditcard_id, :integer
end
end

View File

@@ -0,0 +1,16 @@
class DropBillingIntegrations < ActiveRecord::Migration
def up
drop_table :billing_integrations
end
def down
create_table :billing_integrations do |t|
t.string :type, :name
t.text :description
t.boolean :active, :default => true
t.string :environment, :default => 'development'
t.timestamps
end
end
end

View File

@@ -0,0 +1,14 @@
class DeletedAtForPaymentMethods < ActiveRecord::Migration
def up
change_table :payment_methods do |t|
t.timestamp :deleted_at, :default => nil
end
end
def down
remove_column :payments_methods, :column_name
change_table :payment_methods do |t|
t.remove :deleted_at
end
end
end

View File

@@ -0,0 +1,6 @@
class AddAdjustmentsIndex < ActiveRecord::Migration
def change
add_index :adjustments, :order_id
end
end

View File

@@ -0,0 +1,9 @@
class FixByPopularity < ActiveRecord::Migration
def up
execute("UPDATE product_scopes SET name='descend_by_popularity' WHERE name='by_popularity'")
end
def down
execute("UPDATE product_scopes SET name='by_popularity' WHERE name='descend_by_popularity'")
end
end

View File

@@ -0,0 +1,5 @@
class AddAltTextToImages < ActiveRecord::Migration
def change
add_column :assets, :alt, :text
end
end

View File

@@ -0,0 +1,13 @@
class Adjustment < ActiveRecord::Base; end;
class FixExistingCouponCredits < ActiveRecord::Migration
def up
execute("UPDATE adjustments SET type='PromotionCredit' WHERE type='CouponCredit'")
execute("UPDATE adjustments SET adjustment_source_type='Promotion' WHERE adjustment_source_type='Coupon'")
end
def down
execute("UPDATE adjustments SET adjustment_source_type='Coupon' WHERE adjustment_source_type='Promotion'")
execute("UPDATE adjustments SET type='CouponCredit' WHERE type='PromotionCredit'")
end
end

View File

@@ -0,0 +1,5 @@
class AddDisplayToPaymentMethods < ActiveRecord::Migration
def change
add_column :payment_methods, :display, :string, :default => nil
end
end

View File

@@ -0,0 +1,8 @@
class AddAddressesCheckoutsIndexes < ActiveRecord::Migration
def change
add_index :addresses, :firstname
add_index :addresses, :lastname
add_index :checkouts, :order_id
add_index :checkouts, :bill_address_id
end
end

View File

@@ -0,0 +1,17 @@
class AddIconToTaxons < ActiveRecord::Migration
def up
# skip this migration if the attribute already exists because of advanced taxon extension
return if column_exists?(:taxons, :icon_file_name)
add_column :taxons, :icon_file_name, :string
add_column :taxons, :icon_content_type, :string
add_column :taxons, :icon_file_size, :integer
add_column :taxons, :icon_updated_at, :datetime
end
def down
remove_column :taxons, :icon_file_name
remove_column :taxons, :icon_content_type
remove_column :taxons, :icon_file_size
remove_column :taxons, :icon_updated_at
end
end

View File

@@ -0,0 +1,11 @@
class AddDescriptionToTaxons < ActiveRecord::Migration
def up
# skip this migration if the attribute already exists because of advanced taxon extension
return if column_exists?(:taxons, :description)
add_column :taxons, :description, :text
end
def down
remove_column :taxons, :description
end
end

View File

@@ -0,0 +1,5 @@
class IndexForShipmentsNumber < ActiveRecord::Migration
def change
add_index :shipments, :number
end
end

View File

@@ -0,0 +1,5 @@
class AddIndexOnUsersPersistenceToken < ActiveRecord::Migration
def change
add_index :users, :persistence_token
end
end

View File

@@ -0,0 +1,5 @@
class AddDefaultToTaxCategories < ActiveRecord::Migration
def change
add_column :tax_categories, :is_default, :boolean, :default => false
end
end

View File

@@ -0,0 +1,5 @@
class AddDisplayToShippingMethods < ActiveRecord::Migration
def change
add_column :shipping_methods, :display_on, :string, :default => nil
end
end

View File

@@ -0,0 +1,5 @@
class RenamePaymentMethodDisplay < ActiveRecord::Migration
def change
rename_column :payment_methods, :display, :display_on
end
end

View File

@@ -0,0 +1,5 @@
class RenamePreferencesField < ActiveRecord::Migration
def change
rename_column :preferences, :attribute, :name
end
end

View File

@@ -0,0 +1,5 @@
class AddGuestFlag < ActiveRecord::Migration
def change
add_column :users, :guest, :boolean
end
end

View File

@@ -0,0 +1,9 @@
class DropOrderToken < ActiveRecord::Migration
def up
remove_column :orders, :token
end
def down
add_column :orders, :token, :string
end
end

View File

@@ -0,0 +1,14 @@
class PaymentsStateAndAssignedToOrderOnly < ActiveRecord::Migration
def up
# TODO: migrate existing payments
rename_column :payments, :payable_id, :order_id
remove_column :payments, :payable_type
add_column :payments, :state, :string
end
def down
remove_column :payments, :state
add_column :payments, :payable_type, :string
rename_column :payments, :order_id, :payable_id
end
end

View File

@@ -0,0 +1,6 @@
class CreateAddressKeysForOrder < ActiveRecord::Migration
def change
add_column :orders, :bill_address_id, :integer
add_column :orders, :ship_address_id, :integer
end
end

View File

@@ -0,0 +1,5 @@
class PaymentTotalForOrders < ActiveRecord::Migration
def change
add_column :orders, :payment_total, :decimal, :precision => 8, :scale => 2, :default => 0.0
end
end

View File

@@ -0,0 +1,5 @@
class ShippingMethodIdForOrders < ActiveRecord::Migration
def change
add_column :orders, :shipping_method_id, :integer
end
end

View File

@@ -0,0 +1,6 @@
class AddShipmentAndPaymentState < ActiveRecord::Migration
def change
add_column :orders, :shipment_state, :string
add_column :orders, :payment_state, :string
end
end

View File

@@ -0,0 +1,29 @@
class RefactorAdjustments < ActiveRecord::Migration
def up
change_table :adjustments do |t|
t.boolean :mandatory
t.boolean :frozen
t.rename :adjustment_source_id, :source_id
t.rename :adjustment_source_type, :source_type
t.references :originator
t.string :originator_type
t.remove :type
t.rename :description, :label
t.remove :position
end
end
def down
change_table :adjustments do |t|
t.integer :position
t.rename :label, :description
t.string :type
t.remove :originator_type
t.remove :originator_id
t.rename :source_type, :adjustment_source_type
t.rename :source_id, :adjustment_source_id
t.remove :frozen
t.remove :mandatory
end
end
end

View File

@@ -0,0 +1,6 @@
class ResponseCodeAndAvsResponseForPayments < ActiveRecord::Migration
def change
add_column :payments, :response_code, :string
add_column :payments, :avs_response, :string
end
end

View File

@@ -0,0 +1,5 @@
class ChangeGuestFlagToAnonymous < ActiveRecord::Migration
def change
rename_column :users, :guest, :anonymous
end
end

View File

@@ -0,0 +1,5 @@
class EmailForOrders < ActiveRecord::Migration
def change
add_column :orders, :email, :string
end
end

View File

@@ -0,0 +1,10 @@
class CreateMailMethods < ActiveRecord::Migration
def change
create_table :mail_methods do |t|
t.string :environment
t.boolean :active, :default => true
t.timestamps
end
end
end

View File

@@ -0,0 +1,5 @@
class RenameFrozenToLocked < ActiveRecord::Migration
def change
rename_column :adjustments, :frozen, :locked
end
end

View File

@@ -0,0 +1,10 @@
class MoveSpecialInstructionsToOrders < ActiveRecord::Migration
def up
add_column :orders, :special_instructions, :text
execute "UPDATE orders SET special_instructions = (SELECT special_instructions FROM checkouts WHERE order_id = orders.id)"
end
def down
remove_column :orders, :special_instructions, :text
end
end

View File

@@ -0,0 +1,11 @@
class CreateLogEntries < ActiveRecord::Migration
def change
create_table :log_entries do |t|
t.integer :source_id
t.string :source_type
t.text :details
t.timestamps
end
end
end

View File

@@ -0,0 +1,98 @@
class Transaction < ActiveRecord::Base; end
class CreditcardTxn < Transaction; end
class MigrateTransactionsToPaymentState < ActiveRecord::Migration
AUTHORIZED=1
COMPLETED=2
PURCHASED=3
VOIDED = 4
CREDITED =5
PAYMENT_COMPLETE = 'completed'
PAYMENT_VOID = 'void'
PAYMENT_PENDING = 'pending'
# Temporarily set the table back to payments
Spree::Payment.table_name = 'payments'
def up
migrate_authorized_only_transactions
migrate_voided_transactions
migrate_completed_transactions
migrate_purchased_transactions
migrate_credited_transactions
Spree::Payment.table_name = 'spree_payments'
end
def migrate_credited_transactions
credited = Transaction.find_by_sql("SELECT * FROM transactions WHERE txn_type = #{CREDITED}")
credited.each do |tx|
payment = Spree::Payment.find(tx)
order = payment.order
order.create_payment(
:amount => tx.amount,
:source_id => payment.source_id, :source_type => 'Creditcard',
:payment_method_id => payment.payment_method_id, :state => PAYMENT_COMPLETE,
:avs_response => tx.avs_response, :response_code => tx.response_code
)
end
credited.each { |rec| rec.destroy }
end
def migrate_voided_transactions
voided = Transaction.find_by_sql("SELECT * FROM transactions WHERE txn_type = #{VOIDED}")
voided.each do |tx|
update_payment(tx, PAYMENT_VOID)
end
unless voided.empty?
all_but_credited = [AUTHORIZED, COMPLETED, PURCHASED, VOIDED]
voided_and_subsequent_transactions = Transaction.find_by_sql("SELECT * FROM transactions WHERE payment_id IN (#{voided.map(&:payment_id).join(',')}) AND txn_type IN (#{all_but_credited.join(',')})")
voided_and_subsequent_transactions.each { |rec| rec.destroy }
end
end
def migrate_purchased_transactions
migrate_transactions(PURCHASED)
end
def migrate_completed_transactions
migrate_transactions(COMPLETED)
end
def migrate_transactions(type)
txs = Transaction.find_by_sql("SELECT * FROM transactions WHERE txn_type = #{type}")
txs.each do |tx|
update_payment(tx, PAYMENT_COMPLETE)
end
txs.each { |rec| rec.destroy }
end
def migrate_authorized_only_transactions
if (ActiveRecord::Base.connection.adapter_name == 'PostgreSQL')
group_by_clause = 'GROUP BY transactions.' + Transaction.column_names.join(', transactions.')
else
group_by_clause = 'GROUP BY payment_id'
end
authorized_only = Transaction.find_by_sql("SELECT * FROM transactions #{group_by_clause} HAVING COUNT(payment_id) = 1 AND txn_type = #{AUTHORIZED}")
authorized_only.each do |tx|
update_payment(tx, PAYMENT_PENDING)
end
authorized_only.each { |rec| rec.destroy }
end
def update_payment(tx, state)
payment = Spree::Payment.find(tx.payment_id)
payment.update_attributes_without_callbacks({
:state => state,
:source_type => 'Creditcard',
:amount => tx.amount,
:response_code => tx.response_code,
:avs_response => tx.avs_response
})
end
def down
end
end

View File

@@ -0,0 +1,19 @@
class DeleteInProgressOrders < ActiveRecord::Migration
def up
execute("DELETE FROM orders WHERE orders.state = 'in_progress'")
delete_orphans('adjustments')
delete_orphans('checkouts')
delete_orphans('shipments')
delete_orphans('payments')
delete_orphans('line_items')
delete_orphans('inventory_units')
end
def down
end
private
def delete_orphans(table_name)
execute "DELETE FROM #{table_name} WHERE order_id NOT IN (SELECT id FROM orders)"
end
end

View File

@@ -0,0 +1,23 @@
class MigrateCheckoutToOrders < ActiveRecord::Migration
def up
orders = select_all "SELECT * FROM orders"
orders.each do |order|
checkout = update_order(order)
execute "DELETE FROM checkouts WHERE id = #{checkout['id']}" if checkout
end
end
def down
end
private
def update_order(order)
checkout = select_one "SELECT * FROM checkouts WHERE order_id = #{order['id']}"
if checkout
execute "UPDATE orders SET email='#{checkout['email']}', bill_address_id = #{checkout['bill_address_id']}, ship_address_id = #{checkout['ship_address_id']} WHERE id = #{checkout['id']}"
end
checkout
end
end

View File

@@ -0,0 +1,12 @@
class RemoveShippedState < ActiveRecord::Migration
def up
execute "UPDATE orders SET state = 'complete' WHERE state = 'shipped'"
shipments = select_all "SELECT shipments.id FROM shipments WHERE order_id IN (SELECT orders.id FROM orders WHERE orders.state = 'shipped')"
shipments.each do |shipment|
execute "UPDATE shipments SET state='shipped' WHERE id = #{shipment[:id]}"
end
end
def down
end
end

View File

@@ -0,0 +1,8 @@
class PreventNilPaymentTotal < ActiveRecord::Migration
def up
execute "UPDATE orders SET payment_total = 0.0 WHERE payment_total IS NULL"
end
def down
end
end

View File

@@ -0,0 +1,9 @@
class PreventNilEmail < ActiveRecord::Migration
def up
execute "UPDATE orders SET email = 'guest@example.com' WHERE email IS NULL"
execute "UPDATE orders SET email = 'guest@example.com' WHERE email = ''"
end
def down
end
end

View File

@@ -0,0 +1,20 @@
class GenerateAnonymousUsers < ActiveRecord::Migration
def up
Spree::User.table_name = 'users'
Spree::Order.table_name = 'orders'
Spree::User.reset_column_information
Spree::Order.where(:user_id => nil).each do |order|
user = Spree::User.anonymous!
user.email ||= order.email
order.user = user
order.save!
end
Spree::User.table_name = 'spree_users'
Spree::Order.table_name = 'spree_orders'
end
def down
end
end

View File

@@ -0,0 +1,12 @@
class UpdateOrderState < ActiveRecord::Migration
def up
Spree::Order.table_name = 'orders'
Spree::Order.all.map(&:update!)
Spree::Order.table_name = 'spree_orders'
end
def down
end
end

View File

@@ -0,0 +1,11 @@
class CleanupLegacyTables < ActiveRecord::Migration
def up
drop_table :checkouts
drop_table :transactions
drop_table :open_id_authentication_associations
drop_table :open_id_authentication_nonces
end
def down
end
end

View File

@@ -0,0 +1,11 @@
class RemoveNumberAndCvvFromCredicard < ActiveRecord::Migration
def up
remove_column :creditcards, :number
remove_column :creditcards, :verification_value
end
def down
add_column :creditcards, :verification_value, :text
add_column :creditcards, :number, :text
end
end

View File

@@ -0,0 +1,9 @@
class DropAnonymousFieldForUser < ActiveRecord::Migration
def up
remove_column :users, :anonymous
end
def down
add_column :users, :anonymous, :boolean
end
end

View File

@@ -0,0 +1,9 @@
class RenamedRmaCancelledState < ActiveRecord::Migration
def up
execute "UPDATE return_authorizations SET state = 'canceled' WHERE state = 'cancelled'"
end
def down
execute "UPDATE return_authorizations SET state = 'cancelled' WHERE state = 'canceled'"
end
end

View File

@@ -0,0 +1,13 @@
class FixProblematicIndexNames < ActiveRecord::Migration
def up
begin
remove_index :preferences, :name => 'index_preferences_on_owner_and_attribute_and_preference'
rescue ArgumentError
# ignore - already remove then
end
add_index :preferences, [:owner_id, :owner_type, :name, :group_id, :group_type], :name => 'ix_prefs_on_owner_attr_pref', :unique => true
end
def down
end
end

View File

@@ -0,0 +1,5 @@
class AddPositionToVariants < ActiveRecord::Migration
def change
add_column :variants, :position, :integer
end
end

View File

@@ -0,0 +1,5 @@
class AddNextStateToStateEvents < ActiveRecord::Migration
def change
add_column :state_events, :next_state, :string
end
end

View File

@@ -0,0 +1,5 @@
class AddPositionToOptionTypes < ActiveRecord::Migration
def change
add_column :option_types, :position, :integer, :null => false, :default => 0
end
end

View File

@@ -0,0 +1,19 @@
class RemoveTrailingSlashesInTaxonPermalinks < ActiveRecord::Migration
def up
taxons = select_all "SELECT * FROM taxons"
taxons.each do |taxon|
if taxon['permalink'] && taxon['permalink'][-1..-1] == '/'
execute "UPDATE taxons SET permalink = '#{taxon['permalink'][0...-1]}' WHERE id = #{taxon['id']}"
end
end
end
def down
taxons = select_all "SELECT * FROM taxons"
taxons.each do |taxon|
if taxon['permalink'] && taxon['permalink'][-1..-1] != '/'
execute "UPDATE taxons SET permalink = '#{taxon['permalink'] + '/'}' WHERE id = #{taxon['id']}"
end
end
end
end

View File

@@ -0,0 +1,14 @@
class CreateActivators < ActiveRecord::Migration
def change
create_table :activators, :force => true do |t|
t.string :description
t.datetime :expires_at
t.datetime :created_at
t.datetime :updated_at
t.datetime :starts_at
t.string :name
t.string :event_name
t.string :type
end
end
end

View File

@@ -0,0 +1,5 @@
class EligibleForAdjustments < ActiveRecord::Migration
def change
add_column :adjustments, :eligible, :boolean, :default => true
end
end

View File

@@ -0,0 +1,52 @@
class NamespaceTopLevelModels < ActiveRecord::Migration
def change
rename_table :activators, :spree_activators
rename_table :addresses, :spree_addresses
rename_table :adjustments, :spree_adjustments
rename_table :configurations, :spree_configurations
rename_table :assets, :spree_assets
rename_table :calculators, :spree_calculators
rename_table :countries, :spree_countries
rename_table :creditcards, :spree_creditcards
rename_table :gateways, :spree_gateways
rename_table :inventory_units, :spree_inventory_units
rename_table :line_items, :spree_line_items
rename_table :log_entries, :spree_log_entries
rename_table :mail_methods, :spree_mail_methods
rename_table :option_types, :spree_option_types
rename_table :option_values, :spree_option_values
rename_table :option_types_prototypes, :spree_option_types_prototypes
rename_table :option_values_variants, :spree_option_values_variants
rename_table :orders, :spree_orders
rename_table :payments, :spree_payments
rename_table :payment_methods, :spree_payment_methods
rename_table :preferences, :spree_preferences
rename_table :products, :spree_products
rename_table :product_groups, :spree_product_groups
rename_table :product_groups_products, :spree_product_groups_products
rename_table :product_option_types, :spree_product_option_types
rename_table :product_properties, :spree_product_properties
rename_table :product_scopes, :spree_product_scopes
rename_table :products_taxons, :spree_products_taxons
rename_table :properties, :spree_properties
rename_table :prototypes, :spree_prototypes
rename_table :properties_prototypes, :spree_properties_prototypes
rename_table :return_authorizations, :spree_return_authorizations
rename_table :roles, :spree_roles
rename_table :roles_users, :spree_roles_users
rename_table :shipments, :spree_shipments
rename_table :shipping_categories, :spree_shipping_categories
rename_table :shipping_methods, :spree_shipping_methods
rename_table :states, :spree_states
rename_table :state_events, :spree_state_events
rename_table :tax_categories, :spree_tax_categories
rename_table :tax_rates, :spree_tax_rates
rename_table :taxons, :spree_taxons
rename_table :taxonomies, :spree_taxonomies
rename_table :trackers, :spree_trackers
rename_table :users, :spree_users
rename_table :variants, :spree_variants
rename_table :zones, :spree_zones
rename_table :zone_members, :spree_zone_members
end
end

View File

@@ -0,0 +1,52 @@
class MigrateNamespacedPolymorphicModels < ActiveRecord::Migration
def concat(str1, str2)
dbtype = Rails.configuration.database_configuration[Rails.env]['adapter'].to_sym
case dbtype
when :mysql, :mysql2
"CONCAT(#{str1}, #{str2})"
when :sqlserver
"(#{str1} + #{str2})"
else
"(#{str1} || #{str2})"
end
end
def update_column_data(table_names, column_name)
tables = Array.wrap(table_names)
tables.each do |table|
execute "UPDATE #{table} SET #{column_name} = #{concat("'Spree::'", column_name)}" +
" where #{column_name} NOT LIKE 'Spree::%' AND #{column_name} IS NOT NULL"
end
end
def replace_column_data(table_names, column_name)
tables = Array.wrap(table_names)
tables.each do |table|
execute "UPDATE #{table} SET #{column_name} = REPLACE(#{column_name}, 'Spree::', '') " +
" where #{column_name} LIKE 'Spree::%'"
end
end
def up
update_column_data(['spree_payments', 'spree_adjustments', 'spree_log_entries'], 'source_type')
update_column_data('spree_adjustments', 'originator_type')
update_column_data('spree_calculators', 'calculable_type')
update_column_data('spree_preferences', 'owner_type')
update_column_data('spree_state_events', 'stateful_type')
update_column_data(['spree_activators', 'spree_assets', 'spree_calculators', 'spree_configurations', 'spree_gateways', 'spree_payment_methods'], 'type')
update_column_data('spree_assets', 'viewable_type')
update_column_data('spree_zone_members', 'zoneable_type')
end
def down
replace_column_data(['spree_payments', 'spree_adjustments', 'spree_log_entries'], 'source_type')
replace_column_data('spree_adjustments', 'originator_type')
replace_column_data('spree_calculators', 'calculable_type')
replace_column_data('spree_preferences', 'owner_type')
replace_column_data('spree_state_events', 'stateful_type')
replace_column_data(['spree_activators', 'spree_assets', 'spree_calculators', 'spree_configurations', 'spree_gateways', 'spree_payment_methods'], 'type')
replace_column_data('spree_assets', 'viewable_type')
replace_column_data('spree_zone_members', 'zoneable_type')
end
end

View File

@@ -0,0 +1,9 @@
class MakeAdjustmentsPolymorphic < ActiveRecord::Migration
def change
add_column :spree_adjustments, :adjustable_type, :string
rename_column :spree_adjustments, :order_id, :adjustable_id
execute "UPDATE spree_adjustments SET adjustable_type = 'Spree::Order'"
end
end

View File

@@ -0,0 +1,5 @@
class AddCompanyToAddresses < ActiveRecord::Migration
def change
add_column :spree_addresses, :company, :string
end
end

View File

@@ -0,0 +1,5 @@
class AddIncTaxToTaxRates < ActiveRecord::Migration
def change
add_column :spree_tax_rates, :inc_tax, :boolean, :default => false
end
end

Some files were not shown because too many files have changed in this diff Show More