Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Install Spree

  • Loading branch information...
commit f6dc943dc726bc9acf3faf2bf93c220422c4c379 1 parent aa24c32
@adrianmacneil authored
Showing with 2,979 additions and 1 deletion.
  1. +1 −0  .gitignore
  2. +2 −0  Gemfile
  3. +102 −0 Gemfile.lock
  4. +13 −0 README.md
  5. +13 −0 app/assets/javascripts/admin/all.js
  6. +13 −0 app/assets/javascripts/store/all.js
  7. +12 −0 app/assets/stylesheets/admin/all.css
  8. +12 −0 app/assets/stylesheets/store/all.css
  9. +13 −0 config/application.rb
  10. +2 −0  config/environment.rb
  11. +14 −0 config/initializers/spree.rb
  12. +7 −0 config/routes.rb
  13. +2 −0  config/spree.yml
  14. +392 −0 db/migrate/20120830042814_spree_zero_nine_zero.spree.rb
  15. +7 −0 db/migrate/20120830042815_create_indexes_for_inventory_units.spree.rb
  16. +50 −0 db/migrate/20120830042816_add_count_on_hand_to_variants_and_products.spree.rb
  17. +47 −0 db/migrate/20120830042817_change_taxons_to_nested_set.spree.rb
  18. +55 −0 db/migrate/20120830042818_move_to_configurable_gateways.spree.rb
  19. +16 −0 db/migrate/20120830042819_add_open_id_authentication_tables.spree.rb
  20. +27 −0 db/migrate/20120830042820_add_openid_field_to_users.spree.rb
  21. +11 −0 db/migrate/20120830042821_change_preference_value_type.spree.rb
  22. +13 −0 db/migrate/20120830042822_create_billing_integrations.spree.rb
  23. +40 −0 db/migrate/20120830042823_charge_refactoring.spree.rb
  24. +12 −0 db/migrate/20120830042824_add_some_indexes.spree.rb
  25. +6 −0 db/migrate/20120830042825_checkout_state_machine.spree.rb
  26. +6 −0 db/migrate/20120830042826_state_for_shipments.spree.rb
  27. +13 −0 db/migrate/20120830042827_make_state_events_polymorphic.spree.rb
  28. +6 −0 db/migrate/20120830042828_ship_address_id_for_checkouts.spree.rb
  29. +6 −0 db/migrate/20120830042829_shipping_method_id_for_checkouts.spree.rb
  30. +15 −0 db/migrate/20120830042830_creditcard_last_four_digits.spree.rb
  31. +16 −0 db/migrate/20120830042831_populate_legacy_shipment_state.spree.rb
  32. +6 −0 db/migrate/20120830042832_add_cost_price.spree.rb
  33. +26 −0 db/migrate/20120830042833_shipment_id_for_inventory_units.spree.rb
  34. +7 −0 db/migrate/20120830042834_cim_fields_for_creditcards.spree.rb
  35. +13 −0 db/migrate/20120830042835_create_return_authorizations.spree.rb
  36. +6 −0 db/migrate/20120830042836_add_return_authorization_to_inventory_units.spree.rb
  37. +11 −0 db/migrate/20120830042837_create_trackers.spree.rb
  38. +6 −0 db/migrate/20120830042838_creditcard_id_for_creditcard_txns.spree.rb
  39. +6 −0 db/migrate/20120830042839_original_creditcard_txn_id_for_creditcard_txns.spree.rb
  40. +7 −0 db/migrate/20120830042840_add_test_mode_to_billing_integration.spree.rb
  41. +17 −0 db/migrate/20120830042841_create_payment_methods.spree.rb
  42. +43 −0 db/migrate/20120830042842_polymorphic_payments.spree.rb
  43. +12 −0 db/migrate/20120830042843_change_payments_payment_method_to_belongs_to.spree.rb
  44. +24 −0 db/migrate/20120830042844_assign_creditcard_txns_to_payment.spree.rb
  45. +16 −0 db/migrate/20120830042845_sti_for_transactions.spree.rb
  46. +17 −0 db/migrate/20120830042846_drop_billing_integrations.spree.rb
  47. +15 −0 db/migrate/20120830042847_deleted_at_for_payment_methods.spree.rb
  48. +7 −0 db/migrate/20120830042848_add_adjustments_index.spree.rb
  49. +6 −0 db/migrate/20120830042849_add_alt_text_to_images.spree.rb
  50. +14 −0 db/migrate/20120830042850_fix_existing_coupon_credits.spree.rb
  51. +6 −0 db/migrate/20120830042851_add_display_to_payment_methods.spree.rb
  52. +9 −0 db/migrate/20120830042852_add_addresses_checkouts_indexes.spree.rb
  53. +18 −0 db/migrate/20120830042853_add_icon_to_taxons.spree.rb
  54. +12 −0 db/migrate/20120830042854_add_description_to_taxons.spree.rb
  55. +6 −0 db/migrate/20120830042855_index_for_shipments_number.spree.rb
  56. +8 −0 db/migrate/20120830042856_add_index_on_users_persistence_token.spree.rb
  57. +6 −0 db/migrate/20120830042857_add_default_to_tax_categories.spree.rb
  58. +6 −0 db/migrate/20120830042858_add_display_to_shipping_methods.spree.rb
  59. +6 −0 db/migrate/20120830042859_rename_payment_method_display.spree.rb
  60. +6 −0 db/migrate/20120830042860_rename_preferences_field.spree.rb
  61. +8 −0 db/migrate/20120830042861_add_guest_flag.spree.rb
  62. +10 −0 db/migrate/20120830042862_drop_order_token.spree.rb
  63. +15 −0 db/migrate/20120830042863_payments_state_and_assigned_to_order_only.spree.rb
  64. +7 −0 db/migrate/20120830042864_create_address_keys_for_order.spree.rb
  65. +6 −0 db/migrate/20120830042865_payment_total_for_orders.spree.rb
  66. +6 −0 db/migrate/20120830042866_shipping_method_id_for_orders.spree.rb
  67. +7 −0 db/migrate/20120830042867_add_shipment_and_payment_state.spree.rb
  68. +30 −0 db/migrate/20120830042868_refactor_adjustments.spree.rb
  69. +7 −0 db/migrate/20120830042869_response_code_and_avs_response_for_payments.spree.rb
  70. +8 −0 db/migrate/20120830042870_change_guest_flag_to_anonymous.spree.rb
  71. +6 −0 db/migrate/20120830042871_email_for_orders.spree.rb
  72. +11 −0 db/migrate/20120830042872_create_mail_methods.spree.rb
  73. +6 −0 db/migrate/20120830042873_rename_frozen_to_locked.spree.rb
  74. +11 −0 db/migrate/20120830042874_move_special_instructions_to_orders.spree.rb
  75. +12 −0 db/migrate/20120830042875_create_log_entries.spree.rb
  76. +99 −0 db/migrate/20120830042876_migrate_transactions_to_payment_state.spree.rb
  77. +20 −0 db/migrate/20120830042877_delete_in_progress_orders.spree.rb
  78. +24 −0 db/migrate/20120830042878_migrate_checkout_to_orders.spree.rb
  79. +13 −0 db/migrate/20120830042879_remove_shipped_state.spree.rb
  80. +9 −0 db/migrate/20120830042880_prevent_nil_payment_total.spree.rb
  81. +10 −0 db/migrate/20120830042881_prevent_nil_email.spree.rb
  82. +21 −0 db/migrate/20120830042882_generate_anonymous_users.spree.rb
  83. +13 −0 db/migrate/20120830042883_update_order_state.spree.rb
  84. +12 −0 db/migrate/20120830042884_cleanup_legacy_tables.spree.rb
  85. +12 −0 db/migrate/20120830042885_remove_number_and_cvv_from_credicard.spree.rb
  86. +12 −0 db/migrate/20120830042886_drop_anonymous_field_for_user.spree.rb
  87. +10 −0 db/migrate/20120830042887_renamed_rma_cancelled_state.spree.rb
  88. +14 −0 db/migrate/20120830042888_fix_problematic_index_names.spree.rb
  89. +6 −0 db/migrate/20120830042889_add_position_to_variants.spree.rb
  90. +6 −0 db/migrate/20120830042890_add_next_state_to_state_events.spree.rb
  91. +6 −0 db/migrate/20120830042891_add_position_to_option_types.spree.rb
  92. +20 −0 db/migrate/20120830042892_remove_trailing_slashes_in_taxon_permalinks.spree.rb
  93. +15 −0 db/migrate/20120830042893_create_activators.spree.rb
  94. +6 −0 db/migrate/20120830042894_eligible_for_adjustments.spree.rb
  95. +67 −0 db/migrate/20120830042895_namespace_top_level_models.spree.rb
  96. +53 −0 db/migrate/20120830042896_migrate_namespaced_polymorphic_models.spree.rb
  97. +10 −0 db/migrate/20120830042897_make_adjustments_polymorphic.spree.rb
  98. +6 −0 db/migrate/20120830042898_add_company_to_addresses.spree.rb
  99. +6 −0 db/migrate/20120830042899_add_inc_tax_to_tax_rates.spree.rb
  100. +6 −0 db/migrate/20120830042900_rename_inc_price_attribute.spree.rb
  101. +6 −0 db/migrate/20120830042901_add_default_tax_zone.spree.rb
  102. +8 −0 db/migrate/20120830042902_associate_shipping_methods_and_shipping_categories.spree.rb
  103. +8 −0 db/migrate/20120830042903_add_match_rules_to_shipping_methods.spree.rb
  104. +49 −0 db/migrate/20120830042904_new_preferences.spree.rb
  105. +10 −0 db/migrate/20120830042905_rename_state_events_to_state_changes.spree.rb
  106. +6 −0 db/migrate/20120830042906_add_deleted_at_to_tax_category.spree.rb
  107. +38 −0 db/migrate/20120830042907_migrate_images_from_products_to_variants.spree.rb
  108. +6 −0 db/migrate/20120830042908_rename_attachment_size_to_attachment_file_size.spree.rb
  109. +10 −0 db/migrate/20120830042909_increase_scale_of_tax_rate_amount.spree.rb
  110. +17 −0 db/migrate/20120830042910_create_tokenized_permissions_table.spree.rb
  111. +10 −0 db/migrate/20120830042911_convert_sales_tax_to_default_tax.spree.rb
  112. +12 −0 db/migrate/20120830042912_rename_creditcards_to_credit_cards.spree.rb
  113. +6 −0 db/migrate/20120830042913_add_deleted_at_to_spree_shipping_methods.spree.rb
  114. +6 −0 db/migrate/20120830042914_remove_credit_total_from_orders.spree.rb
  115. +15 −0 db/migrate/20120830042915_add_counter_cache_to_zone_members.spree.rb
  116. +8 −0 db/migrate/20120830042916_add_api_key_to_spree_users.spree_api.rb
  117. +8 −0 db/migrate/20120830042917_resize_api_key_field.spree_api.rb
  118. +8 −0 db/migrate/20120830042918_rename_api_key_to_spree_api_key.spree_api.rb
  119. +11 −0 db/migrate/20120830042919_rename_coupons_to_promotions.spree_promo.rb
  120. +25 −0 db/migrate/20120830042920_create_promotion_rules.spree_promo.rb
  121. +6 −0 db/migrate/20120830042921_match_policy_for_promotions.spree_promo.rb
  122. +15 −0 db/migrate/20120830042922_create_promotion_rules_users.spree_promo.rb
  123. +6 −0 db/migrate/20120830042923_name_for_promotions.spree_promo.rb
  124. +10 −0 db/migrate/20120830042924_update_calculable_type_for_promotions.spree_promo.rb
  125. +10 −0 db/migrate/20120830042925_migrate_adjustments.spree_promo.rb
  126. +23 −0 db/migrate/20120830042926_promotion_changes_to_subclass_of_activator.spree_promo.rb
  127. +10 −0 db/migrate/20120830042927_create_promotion_actions.spree_promo.rb
  128. +11 −0 db/migrate/20120830042928_create_promotion_action_line_items.spree_promo.rb
  129. +86 −0 db/migrate/20120830042929_namespace_promo_tables.spree_promo.rb
  130. +12 −0 db/migrate/20120830042930_create_spree_pending_promotions.spree_promo.rb
  131. +30 −0 db/migrate/20120830042931_content_visited_event.spree_promo.rb
  132. +568 −1 db/schema.rb
  133. +4 −0 db/seeds.rb
  134. +9 −0 public/robots.txt
View
1  .gitignore
@@ -1,5 +1,6 @@
/.bundle
/db/*.sqlite3
+/public/spree
/tmp
.DS_Store
*.log
View
2  Gemfile
@@ -48,3 +48,5 @@ gem 'refinerycms-i18n', '~> 2.0.0'
# gem 'refinerycms-inquiries', '~> 2.0.0'
# gem 'refinerycms-search', '~> 2.0.0'
# gem 'refinerycms-page-images', '~> 2.0.0'
+
+gem 'spree', git: 'git://github.com/spree/spree.git', branch: '1-2-stable'
View
102 Gemfile.lock
@@ -1,3 +1,46 @@
+GIT
+ remote: git://github.com/spree/spree.git
+ revision: 14bb58e33dfe4629d91893fddbd53b9aa081f24f
+ branch: 1-2-stable
+ specs:
+ spree (1.2.0)
+ spree_api (= 1.2.0)
+ spree_cmd (= 1.2.0)
+ spree_core (= 1.2.0)
+ spree_dash (= 1.2.0)
+ spree_promo (= 1.2.0)
+ spree_sample (= 1.2.0)
+ spree_api (1.2.0)
+ rabl (= 0.6.5)
+ spree_core (= 1.2.0)
+ spree_cmd (1.2.0)
+ thor (>= 0.14.6)
+ spree_core (1.2.0)
+ activemerchant (= 1.28.0)
+ acts_as_list (= 0.1.4)
+ aws-sdk (~> 1.3.4)
+ cancan (= 1.6.7)
+ deface (>= 0.9.0)
+ ffaker (~> 1.12.0)
+ highline (= 1.6.11)
+ jquery-rails (~> 2.0)
+ kaminari (>= 0.13.0)
+ money (= 5.0.0)
+ nested_set (= 1.7.0)
+ paperclip (~> 2.7)
+ rails (~> 3.2.8)
+ ransack (~> 0.7.0)
+ select2-rails (= 0.0.9)
+ state_machine (= 1.1.2)
+ stringex (~> 1.3.2)
+ spree_dash (1.2.0)
+ httparty (~> 0.8.1)
+ spree_core (= 1.2.0)
+ spree_promo (1.2.0)
+ spree_core (= 1.2.0)
+ spree_sample (1.2.0)
+ spree_core (= 1.2.0)
+
GEM
remote: https://rubygems.org/
specs:
@@ -14,6 +57,17 @@ GEM
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.3)
+ active_utils (1.0.4)
+ activesupport (>= 2.3.11)
+ i18n
+ activemerchant (1.28.0)
+ active_utils (>= 1.0.2)
+ activesupport (>= 2.3.11)
+ builder (>= 2.0.0)
+ i18n
+ json (>= 1.5.1)
+ money
+ nokogiri
activemodel (3.2.8)
activesupport (= 3.2.8)
builder (~> 3.0.0)
@@ -29,12 +83,20 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
acts_as_indexed (0.7.8)
+ acts_as_list (0.1.4)
arel (3.0.2)
awesome_nested_set (2.1.4)
activerecord (>= 3.0.0)
+ aws-sdk (1.3.9)
+ httparty (~> 0.7)
+ json (~> 1.4)
+ nokogiri (>= 1.4.4)
+ uuidtools (~> 2.1)
babosa (0.3.8)
bcrypt-ruby (3.0.1)
builder (3.0.0)
+ cancan (1.6.7)
+ cocaine (0.3.0)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
@@ -42,6 +104,9 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.3.3)
+ deface (0.9.1)
+ nokogiri (~> 1.5.0)
+ rails (~> 3.1)
devise (2.0.4)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
@@ -52,29 +117,56 @@ GEM
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
+ ffaker (1.12.1)
friendly_id (4.0.8)
globalize3 (0.2.0)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
paper_trail (~> 2)
+ highline (1.6.11)
hike (1.2.1)
+ httparty (0.8.3)
+ multi_json (~> 1.0)
+ multi_xml
i18n (0.6.0)
journey (1.0.4)
jquery-rails (2.0.3)
railties (>= 3.1.0, < 5.0)
thor (~> 0.14)
json (1.7.5)
+ kaminari (0.13.0)
+ actionpack (>= 3.0.0)
+ activesupport (>= 3.0.0)
+ railties (>= 3.0.0)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.19)
+ money (5.0.0)
+ i18n (~> 0.4)
+ json
multi_json (1.3.6)
+ multi_xml (0.5.1)
+ nested_set (1.7.0)
+ activerecord (>= 3.0.0)
+ railties (>= 3.0.0)
+ nokogiri (1.5.5)
orm_adapter (0.0.7)
paper_trail (2.6.3)
activerecord (~> 3.0)
railties (~> 3.0)
+ paperclip (2.7.0)
+ activerecord (>= 2.3.0)
+ activesupport (>= 2.3.2)
+ cocaine (>= 0.0.2)
+ mime-types
+ polyamorous (0.5.0)
+ activerecord (~> 3.0)
polyglot (0.3.3)
+ rabl (0.6.5)
+ activesupport (>= 2.3.14)
+ multi_json (~> 1.0)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
@@ -98,6 +190,10 @@ GEM
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (0.9.2.2)
+ ransack (0.7.0)
+ actionpack (~> 3.0)
+ activerecord (~> 3.0)
+ polyamorous (~> 0.5.0)
rdoc (3.12)
json (~> 1.4)
refinerycms (2.0.8)
@@ -149,6 +245,8 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
+ select2-rails (0.0.9)
+ thor (~> 0.14)
seo_meta (1.3.0)
railties (>= 3.0.0)
sprockets (2.1.3)
@@ -156,6 +254,8 @@ GEM
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.6)
+ state_machine (1.1.2)
+ stringex (1.3.3)
thor (0.16.0)
tilt (1.3.3)
treetop (1.4.10)
@@ -166,6 +266,7 @@ GEM
uglifier (1.2.7)
execjs (>= 0.3.0)
multi_json (~> 1.3)
+ uuidtools (2.1.3)
warden (1.1.1)
rack (>= 1.0)
will_paginate (3.0.3)
@@ -180,5 +281,6 @@ DEPENDENCIES
refinerycms (~> 2.0.0)
refinerycms-i18n (~> 2.0.0)
sass-rails (~> 3.2.3)
+ spree!
sqlite3
uglifier (>= 1.0.3)
View
13 README.md
@@ -1,4 +1,17 @@
# Refinery & Spree - together at last
+Install Refinery:
+
gem install refinerycms
refinerycms refinery_spree
+
+Add Spree gem:
+
+ gem 'spree', git: 'git://github.com/spree/spree.git', branch: '1-2-stable'
+
+Install Spree
+
+ rails g spree:install
+
+Update routes.rb
+
View
13 app/assets/javascripts/admin/all.js
@@ -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 jquery
+//= require jquery_ujs
+
+//= require admin/spree_core
+//= require admin/spree_promo
+
+//= require_tree .
View
13 app/assets/javascripts/store/all.js
@@ -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 jquery
+//= require jquery_ujs
+
+//= require store/spree_core
+//= require store/spree_promo
+
+//= require_tree .
View
12 app/assets/stylesheets/admin/all.css
@@ -0,0 +1,12 @@
+/*
+ * 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_promo
+
+ *= require_self
+ *= require_tree .
+*/
View
12 app/assets/stylesheets/store/all.css
@@ -0,0 +1,12 @@
+/*
+ * 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_promo
+
+ *= require_self
+ *= require_tree .
+*/
View
13 config/application.rb
@@ -17,6 +17,19 @@
module RefinerySpree
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
2  config/environment.rb
@@ -3,3 +3,5 @@
# Initialize the rails application
RefinerySpree::Application.initialize!
+
+ActiveRecord::Base.include_root_in_json = true
View
14 config/initializers/spree.rb
@@ -0,0 +1,14 @@
+# 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
+
+Spree.user_class = "Spree::LegacyUser"
View
7 config/routes.rb
@@ -1,5 +1,12 @@
RefinerySpree::Application.routes.draw do
+ # This line mounts Spree's routes at the root of your application.
+ # This means, any requests to URLs such as /products, will go to Spree::ProductsController.
+ # If you would like to change where this engine is mounted, simply change the :at option to something different.
+ #
+ # We ask that you don't use the :as option here, as Spree relies on it being the default of "spree"
+ mount Spree::Core::Engine, :at => '/'
+
# This line mounts Refinery's routes at the root of your application.
# This means, any requests to the root URL of your application will go to Refinery::PagesController#home.
# If you would like to change where this extension is mounted, simply change the :at option to something different.
View
2  config/spree.yml
@@ -0,0 +1,2 @@
+---
+version: 1.2.0
View
392 db/migrate/20120830042814_spree_zero_nine_zero.spree.rb
@@ -0,0 +1,392 @@
+# This migration comes from spree (originally 20090823005402)
+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
+
+ unless defined?(User)
+ 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
+ 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
7 db/migrate/20120830042815_create_indexes_for_inventory_units.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20090904192342)
+class CreateIndexesForInventoryUnits < ActiveRecord::Migration
+ def change
+ add_index :inventory_units, :variant_id
+ add_index :inventory_units, :order_id
+ end
+end
View
50 db/migrate/20120830042816_add_count_on_hand_to_variants_and_products.spree.rb
@@ -0,0 +1,50 @@
+# This migration comes from spree (originally 20090923100315)
+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_column(: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_column(: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
47 db/migrate/20120830042817_change_taxons_to_nested_set.spree.rb
@@ -0,0 +1,47 @@
+# This migration comes from spree (originally 20091007134354)
+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
55 db/migrate/20120830042818_move_to_configurable_gateways.spree.rb
@@ -0,0 +1,55 @@
+# This migration comes from spree (originally 20091008091614)
+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
16 db/migrate/20120830042819_add_open_id_authentication_tables.spree.rb
@@ -0,0 +1,16 @@
+# This migration comes from spree (originally 20091015110842)
+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
27 db/migrate/20120830042820_add_openid_field_to_users.spree.rb
@@ -0,0 +1,27 @@
+# This migration comes from spree (originally 20091015153048)
+class AddOpenidFieldToUsers < ActiveRecord::Migration
+ def up
+ unless defined?(User)
+ 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
+ end
+
+ def down
+ remove_column :users, :openid_identifier
+
+ # Due to namespacing change, temporarily set the table back to users
+ Spree::LegacyUser.table_name = 'users'
+
+ [:login, :crypted_password, :salt].each do |field|
+ Spree::User.where(field => nil).each { |user| user.update_column(field, '') if user.send(field).nil? }
+ change_column :users, field, :string, :default => '', :null => false
+ end
+
+ Spree::LegacyUser.table_name = 'spree_users'
+ end
+end
View
11 db/migrate/20120830042821_change_preference_value_type.spree.rb
@@ -0,0 +1,11 @@
+# This migration comes from spree (originally 20091016174634)
+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
13 db/migrate/20120830042822_create_billing_integrations.spree.rb
@@ -0,0 +1,13 @@
+# This migration comes from spree (originally 20091017175558)
+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
40 db/migrate/20120830042823_charge_refactoring.spree.rb
@@ -0,0 +1,40 @@
+# This migration comes from spree (originally 20091021133257)
+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_column(: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_column(: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
12 db/migrate/20120830042824_add_some_indexes.spree.rb
@@ -0,0 +1,12 @@
+# This migration comes from spree (originally 20091104151730)
+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
6 db/migrate/20120830042825_checkout_state_machine.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20091126190904)
+class CheckoutStateMachine < ActiveRecord::Migration
+ def change
+ add_column :checkouts, :state, :string
+ end
+end
View
6 db/migrate/20120830042826_state_for_shipments.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20091209153045)
+class StateForShipments < ActiveRecord::Migration
+ def change
+ add_column :shipments, :state, :string
+ end
+end
View
13 db/migrate/20120830042827_make_state_events_polymorphic.spree.rb
@@ -0,0 +1,13 @@
+# This migration comes from spree (originally 20091209202200)
+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
6 db/migrate/20120830042828_ship_address_id_for_checkouts.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20091211203813)
+class ShipAddressIdForCheckouts < ActiveRecord::Migration
+ def change
+ add_column :checkouts, :ship_address_id, :integer
+ end
+end
View
6 db/migrate/20120830042829_shipping_method_id_for_checkouts.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20091212161118)
+class ShippingMethodIdForCheckouts < ActiveRecord::Migration
+ def change
+ add_column :checkouts, :shipping_method_id, :integer
+ end
+end
View
15 db/migrate/20120830042830_creditcard_last_four_digits.spree.rb
@@ -0,0 +1,15 @@
+# This migration comes from spree (originally 20091213222815)
+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
16 db/migrate/20120830042831_populate_legacy_shipment_state.spree.rb
@@ -0,0 +1,16 @@
+# This migration comes from spree (originally 20091214183826)
+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
6 db/migrate/20120830042832_add_cost_price.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20100105090147)
+class AddCostPrice < ActiveRecord::Migration
+ def change
+ add_column :variants, :cost_price, :decimal, :null => true, :default => nil, :precision => 8, :scale => 2
+ end
+end
View
26 db/migrate/20120830042833_shipment_id_for_inventory_units.spree.rb
@@ -0,0 +1,26 @@
+# This migration comes from spree (originally 20100105132138)
+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_column('shipment_id', shipment.id)
+ end
+ end
+
+ Spree::Shipment.table_name = 'spree_shipments'
+ end
+
+ def down
+ remove_column :inventory_units, :shipment_id
+ end
+end
View
7 db/migrate/20120830042834_cim_fields_for_creditcards.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20100111205525)
+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
13 db/migrate/20120830042835_create_return_authorizations.spree.rb
@@ -0,0 +1,13 @@
+# This migration comes from spree (originally 20100112151511)
+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
6 db/migrate/20120830042836_add_return_authorization_to_inventory_units.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20100113090919)
+class AddReturnAuthorizationToInventoryUnits < ActiveRecord::Migration
+ def change
+ add_column :inventory_units, :return_authorization_id, :integer
+ end
+end
View
11 db/migrate/20120830042837_create_trackers.spree.rb
@@ -0,0 +1,11 @@
+# This migration comes from spree (originally 20100113203104)
+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
6 db/migrate/20120830042838_creditcard_id_for_creditcard_txns.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20100121160010)
+class CreditcardIdForCreditcardTxns < ActiveRecord::Migration
+ def change
+ add_column :creditcard_txns, :creditcard_id, :integer
+ end
+end
View
6 db/migrate/20120830042839_original_creditcard_txn_id_for_creditcard_txns.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20100121183934)
+class OriginalCreditcardTxnIdForCreditcardTxns < ActiveRecord::Migration
+ def change
+ add_column :creditcard_txns, :original_creditcard_txn_id, :integer
+ end
+end
View
7 db/migrate/20120830042840_add_test_mode_to_billing_integration.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20100125145351)
+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
17 db/migrate/20120830042841_create_payment_methods.spree.rb
@@ -0,0 +1,17 @@
+# This migration comes from spree (originally 20100209025806)
+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
43 db/migrate/20120830042842_polymorphic_payments.spree.rb
@@ -0,0 +1,43 @@
+# This migration comes from spree (originally 20100209144531)
+# 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 |credit_card|
+ if checkout = Checkout.find_by_id(credit_card.checkout_id) && checkout.order
+ if payment = checkout.order.payments.first
+ execute "UPDATE payments SET source_type = 'CreditCard', source_id = #{credit_card.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
12 db/migrate/20120830042843_change_payments_payment_method_to_belongs_to.spree.rb
@@ -0,0 +1,12 @@
+# This migration comes from spree (originally 20100213103131)
+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
24 db/migrate/20120830042844_assign_creditcard_txns_to_payment.spree.rb
@@ -0,0 +1,24 @@
+# This migration comes from spree (originally 20100214212536)
+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 credit_card = Spree::CreditCard.find_by_id(txn_attrs['creditcard_id']) && credit_card.payments.first
+ execute "UPDATE creditcard_txns SET payment_id = #{credit_card.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
16 db/migrate/20120830042845_sti_for_transactions.spree.rb
@@ -0,0 +1,16 @@
+# This migration comes from spree (originally 20100223170312)
+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
17 db/migrate/20120830042846_drop_billing_integrations.spree.rb
@@ -0,0 +1,17 @@
+# This migration comes from spree (originally 20100223183812)
+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
15 db/migrate/20120830042847_deleted_at_for_payment_methods.spree.rb
@@ -0,0 +1,15 @@
+# This migration comes from spree (originally 20100224153127)
+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
7 db/migrate/20120830042848_add_adjustments_index.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20100301163454)
+class AddAdjustmentsIndex < ActiveRecord::Migration
+ def change
+ add_index :adjustments, :order_id
+ end
+end
+
View
6 db/migrate/20120830042849_add_alt_text_to_images.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20100317120946)
+class AddAltTextToImages < ActiveRecord::Migration
+ def change
+ add_column :assets, :alt, :text
+ end
+end
View
14 db/migrate/20120830042850_fix_existing_coupon_credits.spree.rb
@@ -0,0 +1,14 @@
+# This migration comes from spree (originally 20100419194457)
+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
6 db/migrate/20120830042851_add_display_to_payment_methods.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20100427121301)
+class AddDisplayToPaymentMethods < ActiveRecord::Migration
+ def change
+ add_column :payment_methods, :display, :string, :default => nil
+ end
+end
View
9 db/migrate/20120830042852_add_addresses_checkouts_indexes.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20100504142133)
+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
18 db/migrate/20120830042853_add_icon_to_taxons.spree.rb
@@ -0,0 +1,18 @@
+# This migration comes from spree (originally 20100506180619)
+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
12 db/migrate/20120830042854_add_description_to_taxons.spree.rb
@@ -0,0 +1,12 @@
+# This migration comes from spree (originally 20100506185838)
+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
6 db/migrate/20120830042855_index_for_shipments_number.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20100528155333)
+class IndexForShipmentsNumber < ActiveRecord::Migration
+ def change
+ add_index :shipments, :number
+ end
+end
View
8 db/migrate/20120830042856_add_index_on_users_persistence_token.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20100528185820)
+class AddIndexOnUsersPersistenceToken < ActiveRecord::Migration
+ def change
+ unless defined?(User)
+ add_index :users, :persistence_token
+ end
+ end
+end
View
6 db/migrate/20120830042857_add_default_to_tax_categories.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20100605152042)
+class AddDefaultToTaxCategories < ActiveRecord::Migration
+ def change
+ add_column :tax_categories, :is_default, :boolean, :default => false
+ end
+end
View
6 db/migrate/20120830042858_add_display_to_shipping_methods.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20100624110730)
+class AddDisplayToShippingMethods < ActiveRecord::Migration
+ def change
+ add_column :shipping_methods, :display_on, :string, :default => nil
+ end
+end
View
6 db/migrate/20120830042859_rename_payment_method_display.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20100624123336)
+class RenamePaymentMethodDisplay < ActiveRecord::Migration
+ def change
+ rename_column :payment_methods, :display, :display_on
+ end
+end
View
6 db/migrate/20120830042860_rename_preferences_field.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20100624175547)
+class RenamePreferencesField < ActiveRecord::Migration
+ def change
+ rename_column :preferences, :attribute, :name
+ end
+end
View
8 db/migrate/20120830042861_add_guest_flag.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20100811163637)
+class AddGuestFlag < ActiveRecord::Migration
+ def change
+ unless defined?(User)
+ add_column :users, :guest, :boolean
+ end
+ end
+end
View
10 db/migrate/20120830042862_drop_order_token.spree.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree (originally 20100811205836)
+class DropOrderToken < ActiveRecord::Migration
+ def up
+ remove_column :orders, :token
+ end
+
+ def down
+ add_column :orders, :token, :string
+ end
+end
View
15 db/migrate/20120830042863_payments_state_and_assigned_to_order_only.spree.rb
@@ -0,0 +1,15 @@
+# This migration comes from spree (originally 20100812162326)
+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
7 db/migrate/20120830042864_create_address_keys_for_order.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20100813023502)
+class CreateAddressKeysForOrder < ActiveRecord::Migration
+ def change
+ add_column :orders, :bill_address_id, :integer
+ add_column :orders, :ship_address_id, :integer
+ end
+end
View
6 db/migrate/20120830042865_payment_total_for_orders.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20100813185745)
+class PaymentTotalForOrders < ActiveRecord::Migration
+ def change
+ add_column :orders, :payment_total, :decimal, :precision => 8, :scale => 2, :default => 0.0
+ end
+end
View
6 db/migrate/20120830042866_shipping_method_id_for_orders.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20100816212146)
+class ShippingMethodIdForOrders < ActiveRecord::Migration
+ def change
+ add_column :orders, :shipping_method_id, :integer
+ end
+end
View
7 db/migrate/20120830042867_add_shipment_and_payment_state.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20100817152723)
+class AddShipmentAndPaymentState < ActiveRecord::Migration
+ def change
+ add_column :orders, :shipment_state, :string
+ add_column :orders, :payment_state, :string
+ end
+end
View
30 db/migrate/20120830042868_refactor_adjustments.spree.rb
@@ -0,0 +1,30 @@
+# This migration comes from spree (originally 20100819170125)
+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
7 db/migrate/20120830042869_response_code_and_avs_response_for_payments.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20100820135707)
+class ResponseCodeAndAvsResponseForPayments < ActiveRecord::Migration
+ def change
+ add_column :payments, :response_code, :string
+ add_column :payments, :avs_response, :string
+ end
+end
View
8 db/migrate/20120830042870_change_guest_flag_to_anonymous.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20100901171814)
+class ChangeGuestFlagToAnonymous < ActiveRecord::Migration
+ def change
+ unless defined?(User)
+ rename_column :users, :guest, :anonymous
+ end
+ end
+end
View
6 db/migrate/20120830042871_email_for_orders.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20100903203949)
+class EmailForOrders < ActiveRecord::Migration
+ def change
+ add_column :orders, :email, :string
+ end
+end
View
11 db/migrate/20120830042872_create_mail_methods.spree.rb
@@ -0,0 +1,11 @@
+# This migration comes from spree (originally 20100923162011)
+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
6 db/migrate/20120830042873_rename_frozen_to_locked.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20100929151905)
+class RenameFrozenToLocked < ActiveRecord::Migration
+ def change
+ rename_column :adjustments, :frozen, :locked
+ end
+end
View
11 db/migrate/20120830042874_move_special_instructions_to_orders.spree.rb
@@ -0,0 +1,11 @@
+# This migration comes from spree (originally 20101008190536)
+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
12 db/migrate/20120830042875_create_log_entries.spree.rb
@@ -0,0 +1,12 @@
+# This migration comes from spree (originally 20101026184700)
+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
99 db/migrate/20120830042876_migrate_transactions_to_payment_state.spree.rb
@@ -0,0 +1,99 @@
+# This migration comes from spree (originally 20101026184714)
+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(&: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(&: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(&: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(&: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
20 db/migrate/20120830042877_delete_in_progress_orders.spree.rb
@@ -0,0 +1,20 @@
+# This migration comes from spree (originally 20101026184746)
+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
24 db/migrate/20120830042878_migrate_checkout_to_orders.spree.rb
@@ -0,0 +1,24 @@
+# This migration comes from spree (originally 20101026184808)
+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
13 db/migrate/20120830042879_remove_shipped_state.spree.rb
@@ -0,0 +1,13 @@
+# This migration comes from spree (originally 20101026184855)
+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
9 db/migrate/20120830042880_prevent_nil_payment_total.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20101026184916)
+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
10 db/migrate/20120830042881_prevent_nil_email.spree.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree (originally 20101026184932)
+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
21 db/migrate/20120830042882_generate_anonymous_users.spree.rb
@@ -0,0 +1,21 @@
+# This migration comes from spree (originally 20101026184959)
+class GenerateAnonymousUsers < ActiveRecord::Migration
+ def up
+ Spree::LegacyUser.table_name = 'users'
+ Spree::Order.table_name = 'orders'
+
+ Spree::LegacyUser.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::LegacyUser.table_name = 'spree_users'
+ Spree::Order.table_name = 'spree_orders'
+ end
+
+ def down
+ end
+end
View
13 db/migrate/20120830042883_update_order_state.spree.rb
@@ -0,0 +1,13 @@
+# This migration comes from spree (originally 20101026185022)
+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
12 db/migrate/20120830042884_cleanup_legacy_tables.spree.rb
@@ -0,0 +1,12 @@
+# This migration comes from spree (originally 20101026192225)
+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
12 db/migrate/20120830042885_remove_number_and_cvv_from_credicard.spree.rb
@@ -0,0 +1,12 @@
+# This migration comes from spree (originally 20101028151745)
+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
12 db/migrate/20120830042886_drop_anonymous_field_for_user.spree.rb
@@ -0,0 +1,12 @@
+# This migration comes from spree (originally 20101103212716)
+class DropAnonymousFieldForUser < ActiveRecord::Migration
+ def up
+ unless defined?(User)
+ remove_column :users, :anonymous
+ end
+ end
+
+ def down
+ add_column :users, :anonymous, :boolean
+ end
+end