spree_flat_in_range 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/LICENSE +26 -0
  2. data/README.md +39 -0
  3. data/app/models/spree/calculator/flat_in_range.rb +21 -0
  4. data/config/locales/en.yml +5 -0
  5. data/lib/spree_flat_in_range.rb +21 -0
  6. data/spec/dummy/Rakefile +7 -0
  7. data/spec/dummy/app/assets/javascripts/admin/all.js +10 -0
  8. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  9. data/spec/dummy/app/assets/javascripts/store/all.js +10 -0
  10. data/spec/dummy/app/assets/stylesheets/admin/all.css +11 -0
  11. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  12. data/spec/dummy/app/assets/stylesheets/store/all.css +11 -0
  13. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  14. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  15. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  16. data/spec/dummy/config.ru +4 -0
  17. data/spec/dummy/config/application.rb +60 -0
  18. data/spec/dummy/config/boot.rb +6 -0
  19. data/spec/dummy/config/database.yml +18 -0
  20. data/spec/dummy/config/environment.rb +7 -0
  21. data/spec/dummy/config/environments/development.rb +30 -0
  22. data/spec/dummy/config/environments/production.rb +60 -0
  23. data/spec/dummy/config/environments/test.rb +39 -0
  24. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  25. data/spec/dummy/config/initializers/inflections.rb +10 -0
  26. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  27. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  28. data/spec/dummy/config/initializers/session_store.rb +8 -0
  29. data/spec/dummy/config/initializers/spree.rb +12 -0
  30. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  31. data/spec/dummy/config/locales/en.yml +5 -0
  32. data/spec/dummy/config/routes.rb +3 -0
  33. data/spec/dummy/config/spree.yml +2 -0
  34. data/spec/dummy/db/dummy_test +0 -0
  35. data/spec/dummy/db/migrate/20120218160357_spree_zero_nine_zero.rb +389 -0
  36. data/spec/dummy/db/migrate/20120218160358_create_indexes_for_inventory_units.rb +6 -0
  37. data/spec/dummy/db/migrate/20120218160359_add_count_on_hand_to_variants_and_products.rb +49 -0
  38. data/spec/dummy/db/migrate/20120218160360_change_taxons_to_nested_set.rb +46 -0
  39. data/spec/dummy/db/migrate/20120218160361_move_to_configurable_gateways.rb +54 -0
  40. data/spec/dummy/db/migrate/20120218160362_product_groups_and_scopes.rb +18 -0
  41. data/spec/dummy/db/migrate/20120218160363_add_open_id_authentication_tables.rb +15 -0
  42. data/spec/dummy/db/migrate/20120218160364_add_openid_field_to_users.rb +24 -0
  43. data/spec/dummy/db/migrate/20120218160365_change_preference_value_type.rb +10 -0
  44. data/spec/dummy/db/migrate/20120218160366_create_billing_integrations.rb +12 -0
  45. data/spec/dummy/db/migrate/20120218160367_charge_refactoring.rb +39 -0
  46. data/spec/dummy/db/migrate/20120218160368_add_some_indexes.rb +11 -0
  47. data/spec/dummy/db/migrate/20120218160369_checkout_state_machine.rb +5 -0
  48. data/spec/dummy/db/migrate/20120218160370_state_for_shipments.rb +5 -0
  49. data/spec/dummy/db/migrate/20120218160371_make_state_events_polymorphic.rb +12 -0
  50. data/spec/dummy/db/migrate/20120218160372_ship_address_id_for_checkouts.rb +5 -0
  51. data/spec/dummy/db/migrate/20120218160373_shipping_method_id_for_checkouts.rb +5 -0
  52. data/spec/dummy/db/migrate/20120218160374_creditcard_last_four_digits.rb +14 -0
  53. data/spec/dummy/db/migrate/20120218160375_populate_legacy_shipment_state.rb +15 -0
  54. data/spec/dummy/db/migrate/20120218160376_add_cost_price.rb +5 -0
  55. data/spec/dummy/db/migrate/20120218160377_shipment_id_for_inventory_units.rb +25 -0
  56. data/spec/dummy/db/migrate/20120218160378_cim_fields_for_creditcards.rb +6 -0
  57. data/spec/dummy/db/migrate/20120218160379_create_return_authorizations.rb +12 -0
  58. data/spec/dummy/db/migrate/20120218160380_add_return_authorization_to_inventory_units.rb +5 -0
  59. data/spec/dummy/db/migrate/20120218160381_create_trackers.rb +10 -0
  60. data/spec/dummy/db/migrate/20120218160382_creditcard_id_for_creditcard_txns.rb +5 -0
  61. data/spec/dummy/db/migrate/20120218160383_original_creditcard_txn_id_for_creditcard_txns.rb +5 -0
  62. data/spec/dummy/db/migrate/20120218160384_add_test_mode_to_billing_integration.rb +6 -0
  63. data/spec/dummy/db/migrate/20120218160385_create_products_product_groups.rb +8 -0
  64. data/spec/dummy/db/migrate/20120218160386_create_payment_methods.rb +16 -0
  65. data/spec/dummy/db/migrate/20120218160387_polymorphic_payments.rb +42 -0
  66. data/spec/dummy/db/migrate/20120218160388_change_payments_payment_method_to_belongs_to.rb +11 -0
  67. data/spec/dummy/db/migrate/20120218160389_assign_creditcard_txns_to_payment.rb +23 -0
  68. data/spec/dummy/db/migrate/20120218160390_sti_for_transactions.rb +15 -0
  69. data/spec/dummy/db/migrate/20120218160391_drop_billing_integrations.rb +16 -0
  70. data/spec/dummy/db/migrate/20120218160392_deleted_at_for_payment_methods.rb +14 -0
  71. data/spec/dummy/db/migrate/20120218160393_add_adjustments_index.rb +6 -0
  72. data/spec/dummy/db/migrate/20120218160394_fix_by_popularity.rb +9 -0
  73. data/spec/dummy/db/migrate/20120218160395_add_alt_text_to_images.rb +5 -0
  74. data/spec/dummy/db/migrate/20120218160396_fix_existing_coupon_credits.rb +13 -0
  75. data/spec/dummy/db/migrate/20120218160397_add_display_to_payment_methods.rb +5 -0
  76. data/spec/dummy/db/migrate/20120218160398_add_addresses_checkouts_indexes.rb +8 -0
  77. data/spec/dummy/db/migrate/20120218160399_add_icon_to_taxons.rb +17 -0
  78. data/spec/dummy/db/migrate/20120218160400_add_description_to_taxons.rb +11 -0
  79. data/spec/dummy/db/migrate/20120218160401_index_for_shipments_number.rb +5 -0
  80. data/spec/dummy/db/migrate/20120218160402_add_index_on_users_persistence_token.rb +5 -0
  81. data/spec/dummy/db/migrate/20120218160403_add_default_to_tax_categories.rb +5 -0
  82. data/spec/dummy/db/migrate/20120218160404_add_display_to_shipping_methods.rb +5 -0
  83. data/spec/dummy/db/migrate/20120218160405_rename_payment_method_display.rb +5 -0
  84. data/spec/dummy/db/migrate/20120218160406_rename_preferences_field.rb +5 -0
  85. data/spec/dummy/db/migrate/20120218160407_add_guest_flag.rb +5 -0
  86. data/spec/dummy/db/migrate/20120218160408_drop_order_token.rb +9 -0
  87. data/spec/dummy/db/migrate/20120218160409_payments_state_and_assigned_to_order_only.rb +14 -0
  88. data/spec/dummy/db/migrate/20120218160410_create_address_keys_for_order.rb +6 -0
  89. data/spec/dummy/db/migrate/20120218160411_payment_total_for_orders.rb +5 -0
  90. data/spec/dummy/db/migrate/20120218160412_shipping_method_id_for_orders.rb +5 -0
  91. data/spec/dummy/db/migrate/20120218160413_add_shipment_and_payment_state.rb +6 -0
  92. data/spec/dummy/db/migrate/20120218160414_refactor_adjustments.rb +29 -0
  93. data/spec/dummy/db/migrate/20120218160415_response_code_and_avs_response_for_payments.rb +6 -0
  94. data/spec/dummy/db/migrate/20120218160416_change_guest_flag_to_anonymous.rb +5 -0
  95. data/spec/dummy/db/migrate/20120218160417_email_for_orders.rb +5 -0
  96. data/spec/dummy/db/migrate/20120218160418_create_mail_methods.rb +10 -0
  97. data/spec/dummy/db/migrate/20120218160419_rename_frozen_to_locked.rb +5 -0
  98. data/spec/dummy/db/migrate/20120218160420_move_special_instructions_to_orders.rb +10 -0
  99. data/spec/dummy/db/migrate/20120218160421_create_log_entries.rb +11 -0
  100. data/spec/dummy/db/migrate/20120218160422_migrate_transactions_to_payment_state.rb +98 -0
  101. data/spec/dummy/db/migrate/20120218160423_delete_in_progress_orders.rb +19 -0
  102. data/spec/dummy/db/migrate/20120218160424_migrate_checkout_to_orders.rb +23 -0
  103. data/spec/dummy/db/migrate/20120218160425_remove_shipped_state.rb +12 -0
  104. data/spec/dummy/db/migrate/20120218160426_prevent_nil_payment_total.rb +8 -0
  105. data/spec/dummy/db/migrate/20120218160427_prevent_nil_email.rb +9 -0
  106. data/spec/dummy/db/migrate/20120218160428_generate_anonymous_users.rb +20 -0
  107. data/spec/dummy/db/migrate/20120218160429_update_order_state.rb +12 -0
  108. data/spec/dummy/db/migrate/20120218160430_cleanup_legacy_tables.rb +11 -0
  109. data/spec/dummy/db/migrate/20120218160431_remove_number_and_cvv_from_credicard.rb +11 -0
  110. data/spec/dummy/db/migrate/20120218160432_drop_anonymous_field_for_user.rb +9 -0
  111. data/spec/dummy/db/migrate/20120218160433_renamed_rma_cancelled_state.rb +9 -0
  112. data/spec/dummy/db/migrate/20120218160434_fix_problematic_index_names.rb +13 -0
  113. data/spec/dummy/db/migrate/20120218160435_add_position_to_variants.rb +5 -0
  114. data/spec/dummy/db/migrate/20120218160436_add_next_state_to_state_events.rb +5 -0
  115. data/spec/dummy/db/migrate/20120218160437_add_position_to_option_types.rb +5 -0
  116. data/spec/dummy/db/migrate/20120218160438_remove_trailing_slashes_in_taxon_permalinks.rb +19 -0
  117. data/spec/dummy/db/migrate/20120218160439_create_activators.rb +14 -0
  118. data/spec/dummy/db/migrate/20120218160440_eligible_for_adjustments.rb +5 -0
  119. data/spec/dummy/db/migrate/20120218160441_namespace_top_level_models.rb +52 -0
  120. data/spec/dummy/db/migrate/20120218160442_migrate_namespaced_polymorphic_models.rb +52 -0
  121. data/spec/dummy/db/migrate/20120218160443_make_adjustments_polymorphic.rb +9 -0
  122. data/spec/dummy/db/migrate/20120218160444_add_company_to_addresses.rb +5 -0
  123. data/spec/dummy/db/migrate/20120218160445_add_inc_tax_to_tax_rates.rb +5 -0
  124. data/spec/dummy/db/migrate/20120218160446_rename_inc_price_attribute.rb +5 -0
  125. data/spec/dummy/db/migrate/20120218160447_add_default_tax_zone.rb +5 -0
  126. data/spec/dummy/db/migrate/20120218160448_associate_shipping_methods_and_shipping_categories.rb +7 -0
  127. data/spec/dummy/db/migrate/20120218160449_add_match_rules_to_shipping_methods.rb +7 -0
  128. data/spec/dummy/db/migrate/20120218160450_new_preferences.rb +48 -0
  129. data/spec/dummy/db/migrate/20120218160451_add_deleted_at_to_tax_category.rb +5 -0
  130. data/spec/dummy/db/schema.rb +553 -0
  131. data/spec/dummy/db/seeds.rb +11 -0
  132. data/spec/dummy/log/test.log +1136 -0
  133. data/spec/dummy/public/404.html +26 -0
  134. data/spec/dummy/public/422.html +26 -0
  135. data/spec/dummy/public/500.html +26 -0
  136. data/spec/dummy/public/favicon.ico +0 -0
  137. data/spec/dummy/script/rails +6 -0
  138. data/spec/dummy/spec/dummy/script/rails +6 -0
  139. data/spec/flat_in_range_spec.rb +56 -0
  140. data/spec/spec_helper.rb +32 -0
  141. metadata +428 -0
@@ -0,0 +1,6 @@
1
+ class CreateIndexesForInventoryUnits < ActiveRecord::Migration
2
+ def change
3
+ add_index :inventory_units, :variant_id
4
+ add_index :inventory_units, :order_id
5
+ end
6
+ end
@@ -0,0 +1,49 @@
1
+ class AddCountOnHandToVariantsAndProducts < ActiveRecord::Migration
2
+ def up
3
+ add_column :variants, :count_on_hand, :integer, :default => 0, :null => false
4
+ add_column :products, :count_on_hand, :integer, :default => 0, :null => false
5
+
6
+ # Due to our namespacing changes, this migration (from earlier Spree versions) is broken
7
+ # To fix it, temporarily set table name on each of the models involved
8
+ # And then...
9
+ Spree::Variant.table_name = 'variants'
10
+ Spree::Product.table_name = 'products'
11
+ Spree::InventoryUnit.table_name = 'inventory_units'
12
+
13
+ # In some cases needed to reflect changes in table structure
14
+ Spree::Variant.reset_column_information
15
+ Spree::Product.reset_column_information
16
+
17
+ say_with_time 'Transfering inventory units with status on_hand to variants table...' do
18
+ Spree::Variant.all.each do |v|
19
+ v.update_attribute(:count_on_hand, v.inventory_units.with_state('on_hand').size)
20
+ Spree::InventoryUnit.destroy_all(:variant_id => v.id, :state => 'on_hand')
21
+ end
22
+ end
23
+
24
+ say_with_time 'Updating products count on hand' do
25
+ Spree::Product.all.each do |p|
26
+ product_count_on_hand = p.has_variants? ?
27
+ p.variants.inject(0) { |acc, v| acc + v.count_on_hand } :
28
+ (p.master ? p.master.count_on_hand : 0)
29
+ p.update_attribute(:count_on_hand, product_count_on_hand)
30
+ end
31
+ end
32
+
33
+ # ... Switch things back at the end of the migration
34
+ Spree::Variant.table_name = 'spree_variants'
35
+ Spree::Product.table_name = 'spree_products'
36
+ Spree::InventoryUnit.table_name = 'spree_inventory_units'
37
+ end
38
+
39
+ def down
40
+ Spree::Variant.all.each do |v|
41
+ v.count_on_hand.times do
42
+ Spree::InventoryUnit.create(:variant => variant, :state => 'on_hand')
43
+ end
44
+ end
45
+
46
+ remove_column :variants, :count_on_hand
47
+ remove_column :products, :count_on_hand
48
+ end
49
+ end
@@ -0,0 +1,46 @@
1
+ class ChangeTaxonsToNestedSet < ActiveRecord::Migration
2
+ def up
3
+ add_column :taxons, :lft, :integer
4
+ add_column :taxons, :rgt, :integer
5
+
6
+ Spree::Taxon.reset_column_information # So the new root ids get saved
7
+
8
+ # Temporarily set the table back to taxons
9
+ Spree::Taxon.table_name = 'taxons'
10
+
11
+ Spree::Taxon.class_eval do
12
+ # adapted from awesome nested set to use 'position' information
13
+ indices = {}
14
+
15
+ left_column_name = 'lft'
16
+ right_column_name = 'rgt'
17
+ quoted_parent_column_name = 'parent_id'
18
+ scope = lambda{|node|}
19
+
20
+ set_left_and_rights = lambda do |node|
21
+ # set left
22
+ node[left_column_name] = indices[scope.call(node)] += 1
23
+ # find
24
+ where("#{quoted_parent_column_name} = ?", node).order('position ASC').each{ |n| set_left_and_rights.call(n) }
25
+ # set right
26
+ node[right_column_name] = indices[scope.call(node)] += 1
27
+ node.save!
28
+ end
29
+
30
+ # Find root node(s)
31
+ where("#{quoted_parent_column_name}" => nil).order('position ASC').each do |root_node|
32
+ # setup index for this scope
33
+ indices[scope.call(root_node)] ||= 0
34
+ set_left_and_rights.call(root_node)
35
+ end
36
+ end
37
+
38
+ # Set it back after the migration
39
+ Spree::Taxon.table_name = 'spree_taxons'
40
+ end
41
+
42
+ def down
43
+ remove_column :taxons, :lft
44
+ remove_column :taxons, :rgt
45
+ end
46
+ end
@@ -0,0 +1,54 @@
1
+ class MoveToConfigurableGateways < ActiveRecord::Migration
2
+ def up
3
+ drop_table :gateways
4
+ drop_table :gateway_options
5
+ drop_table :gateway_option_values
6
+ drop_table :gateway_configurations
7
+
8
+ create_table :gateways, :force => true do |t|
9
+ t.string :type, :name
10
+ t.text :description
11
+ t.boolean :active, :default => true
12
+ t.string :environment, :default => 'development'
13
+ t.string :server, :default => 'test'
14
+ t.boolean :test_mode, :default => true
15
+
16
+ t.timestamps
17
+ end
18
+ end
19
+
20
+ def down
21
+ drop_table :gateways
22
+
23
+ create_table :gateway_configurations, :force => true do |t|
24
+ t.references :gateway
25
+
26
+ t.timestamps
27
+ end
28
+
29
+ create_table :gateway_option_values, :force => true do |t|
30
+ t.text :value
31
+ t.references :gateway_configuration
32
+ t.references :gateway_option
33
+
34
+ t.timestamps
35
+ end
36
+
37
+ create_table :gateway_options, :force => true do |t|
38
+ t.string :name
39
+ t.text :description
40
+ t.boolean :textarea, :default => false
41
+ t.references :gateway
42
+
43
+ t.timestamps
44
+ end
45
+
46
+ create_table :gateways, :force => true do |t|
47
+ t.string :clazz, :name
48
+ t.text :description
49
+ t.boolean :active
50
+
51
+ t.timestamps
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,18 @@
1
+ class ProductGroupsAndScopes < ActiveRecord::Migration
2
+ def change
3
+ create_table :product_groups do |t|
4
+ t.string :name, :permalink, :order
5
+ end
6
+
7
+ create_table :product_scopes do |t|
8
+ t.string :name
9
+ t.text :arguments
10
+ t.references :product_group
11
+ end
12
+
13
+ add_index :product_groups, :name
14
+ add_index :product_groups, :permalink
15
+ add_index :product_scopes, :name
16
+ add_index :product_scopes, :product_group_id
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ class AddOpenIdAuthenticationTables < ActiveRecord::Migration
2
+ def change
3
+ create_table :open_id_authentication_associations, :force => true do |t|
4
+ t.integer :issued, :lifetime
5
+ t.string :handle, :assoc_type
6
+ t.binary :server_url, :secret
7
+ end
8
+
9
+ create_table :open_id_authentication_nonces, :force => true do |t|
10
+ t.integer :timestamp, :null => false
11
+ t.string :server_url, :null => true
12
+ t.string :salt, :null => false
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ class AddOpenidFieldToUsers < ActiveRecord::Migration
2
+ def up
3
+ add_column :users, :openid_identifier, :string
4
+ add_index :users, :openid_identifier
5
+
6
+ change_column :users, :login, :string, :default => nil, :null => true
7
+ change_column :users, :crypted_password, :string, :default => nil, :null => true
8
+ change_column :users, :salt, :string, :default => nil, :null => true
9
+ end
10
+
11
+ def down
12
+ remove_column :users, :openid_identifier
13
+
14
+ # Due to namespacing change, temporarily set the table back to users
15
+ Spree::User.table_name = 'users'
16
+
17
+ [:login, :crypted_password, :salt].each do |field|
18
+ Spree::User.where(field => nil).each { |user| user.update_attribute(field, '') if user.send(field).nil? }
19
+ change_column :users, field, :string, :default => '', :null => false
20
+ end
21
+
22
+ Spree::User.table_name = 'spree_users'
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ class ChangePreferenceValueType < ActiveRecord::Migration
2
+ def up
3
+ remove_index :preferences, :name => 'index_preferences_on_owner_and_attribute_and_preference'
4
+ change_column :preferences, :value, :text
5
+ end
6
+
7
+ def down
8
+ change_column :preferences, :value, :string
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ class CreateBillingIntegrations < ActiveRecord::Migration
2
+ def change
3
+ create_table :billing_integrations do |t|
4
+ t.string :type, :name
5
+ t.text :description
6
+ t.boolean :active, :default => true
7
+ t.string :environment, :default => 'development'
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,39 @@
1
+ class Checkout < ActiveRecord::Base; end;
2
+
3
+ # Hack to prevent issues with legacy migrations
4
+ class Order < ActiveRecord::Base
5
+ has_one :checkout
6
+ end
7
+
8
+ class ChargeRefactoring < ActiveRecord::Migration
9
+ def up
10
+ # Temporarily set table name for legacy support
11
+ Spree::Adjustment.table_name = 'adjustments'
12
+
13
+ add_column :orders, :completed_at, :timestamp
14
+ Order.reset_column_information
15
+ Order.all.each { |o| o.update_attribute(:completed_at, o.checkout && o.checkout.read_attribute(:completed_at)) }
16
+ remove_column :checkouts, :completed_at
17
+
18
+ change_column :adjustments, :amount, :decimal, :null => true, :default => nil, :precision => 8, :scale => 2
19
+ Spree::Adjustment.update_all :type => 'secondary_type'
20
+ Spree::Adjustment.where(:type => 'Credit').update_all(:type => 'CouponCredit')
21
+ remove_column :adjustments, :secondary_type
22
+
23
+ # Reset table name
24
+ Spree::Adjustment.table_name = 'spree_adjustments'
25
+ end
26
+
27
+ def down
28
+ add_column :checkouts, :completed_at, :timestamp
29
+ Spree::Checkout.reset_column_information
30
+ Spree::Checkout.all.each { |c| c.update_attribute(:completed_at, c.order && c.order.completed_at) }
31
+ remove_column :orders, :completed_at
32
+
33
+ add_column :adjustments, :secondary_type, :string
34
+ Spree::Adjustment.update_all :secondary_type => 'type'
35
+ Spree::Adjustment.where('type LIKE ?', '%Charge').update_all(:type => 'Charge')
36
+ Spree::Adjustment.where('type LIKE ?', '%Credit').update_all(:type => 'Credit')
37
+ change_column :adjustments, :amount, :decimal, :null => false, :default => 0, :precision => 8, :scale => 2
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ class AddSomeIndexes < ActiveRecord::Migration
2
+ def change
3
+ add_index :taxons, :permalink
4
+ add_index :taxons, :parent_id
5
+ add_index :taxons, :taxonomy_id
6
+ add_index :assets, :viewable_id
7
+ add_index :assets, [:viewable_type, :type]
8
+ add_index :product_properties, :product_id
9
+ add_index :option_values_variants, [:variant_id, :option_value_id]
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class CheckoutStateMachine < ActiveRecord::Migration
2
+ def change
3
+ add_column :checkouts, :state, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class StateForShipments < ActiveRecord::Migration
2
+ def change
3
+ add_column :shipments, :state, :string
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ class MakeStateEventsPolymorphic < ActiveRecord::Migration
2
+ def up
3
+ rename_column :state_events, :order_id, :stateful_id
4
+ add_column :state_events, :stateful_type, :string
5
+ execute "UPDATE state_events SET stateful_type = 'Order'"
6
+ end
7
+
8
+ def down
9
+ rename_column :state_events, :stateful_id, :order_id
10
+ remove_column :state_events, :stateful_type
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ class ShipAddressIdForCheckouts < ActiveRecord::Migration
2
+ def change
3
+ add_column :checkouts, :ship_address_id, :integer
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class ShippingMethodIdForCheckouts < ActiveRecord::Migration
2
+ def change
3
+ add_column :checkouts, :shipping_method_id, :integer
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ class CreditcardLastFourDigits < ActiveRecord::Migration
2
+ def up
3
+ rename_column :creditcards, :display_number, :last_digits
4
+
5
+ creditcards = select_all "SELECT * FROM creditcards"
6
+ creditcards.each do |card|
7
+ execute "UPDATE creditcards SET last_digits = '#{card['last_digits'].gsub('XXXX-XXXX-XXXX-', '')}' WHERE id = #{card['id']}" if card['last_digits'].present?
8
+ end
9
+ end
10
+
11
+ def down
12
+ rename_column :creditcards, :last_digits, :display_number
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ class PopulateLegacyShipmentState < ActiveRecord::Migration
2
+ def up
3
+ shipments = select_all "SELECT * FROM shipments"
4
+ shipments.each do |shipment|
5
+ if shipment['shipped_at']
6
+ execute "UPDATE shipments SET state = 'shipped'"
7
+ else
8
+ execute "UPDATE shipments SET state = 'pending'"
9
+ end
10
+ end
11
+ end
12
+
13
+ def down
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ class AddCostPrice < ActiveRecord::Migration
2
+ def change
3
+ add_column :variants, :cost_price, :decimal, :null => true, :default => nil, :precision => 8, :scale => 2
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ class ShipmentIdForInventoryUnits < ActiveRecord::Migration
2
+ def up
3
+ add_column :inventory_units, :shipment_id, :integer
4
+ add_index :inventory_units, :shipment_id
5
+
6
+ # migrate legacy shipments
7
+ Spree::Shipment.table_name = 'shipments'
8
+
9
+ Spree::Shipment.all.each do |shipment|
10
+ unless shipment.order
11
+ puts "Warning: shipment has invalid order - #{shipment.id}"
12
+ next
13
+ end
14
+ shipment.order.inventory_units.each do |unit|
15
+ unit.update_attribute('shipment_id', shipment.id)
16
+ end
17
+ end
18
+
19
+ Spree::Shipment.table_name = 'spree_shipments'
20
+ end
21
+
22
+ def down
23
+ remove_column :inventory_units, :shipment_id
24
+ end
25
+ end
@@ -0,0 +1,6 @@
1
+ class CimFieldsForCreditcards < ActiveRecord::Migration
2
+ def change
3
+ add_column :creditcards, :gateway_customer_profile_id, :string
4
+ add_column :creditcards, :gateway_payment_profile_id, :string
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ class CreateReturnAuthorizations < ActiveRecord::Migration
2
+ def change
3
+ create_table :return_authorizations do |t|
4
+ t.string :number, :state
5
+ t.decimal :amount, :precision => 8, :scale => 2, :default => 0.0, :null => false
6
+ t.references :order
7
+ t.text :reason
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ class AddReturnAuthorizationToInventoryUnits < ActiveRecord::Migration
2
+ def change
3
+ add_column :inventory_units, :return_authorization_id, :integer
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ class CreateTrackers < ActiveRecord::Migration
2
+ def change
3
+ create_table :trackers do |t|
4
+ t.string :environment, :analytics_id
5
+ t.boolean :active, :default => true
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end