spree_flat_in_range 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +26 -0
- data/README.md +39 -0
- data/app/models/spree/calculator/flat_in_range.rb +21 -0
- data/config/locales/en.yml +5 -0
- data/lib/spree_flat_in_range.rb +21 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/admin/all.js +10 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/javascripts/store/all.js +10 -0
- data/spec/dummy/app/assets/stylesheets/admin/all.css +11 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/assets/stylesheets/store/all.css +11 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +60 -0
- data/spec/dummy/config/boot.rb +6 -0
- data/spec/dummy/config/database.yml +18 -0
- data/spec/dummy/config/environment.rb +7 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +60 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/spree.rb +12 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/spree.yml +2 -0
- data/spec/dummy/db/dummy_test +0 -0
- data/spec/dummy/db/migrate/20120218160357_spree_zero_nine_zero.rb +389 -0
- data/spec/dummy/db/migrate/20120218160358_create_indexes_for_inventory_units.rb +6 -0
- data/spec/dummy/db/migrate/20120218160359_add_count_on_hand_to_variants_and_products.rb +49 -0
- data/spec/dummy/db/migrate/20120218160360_change_taxons_to_nested_set.rb +46 -0
- data/spec/dummy/db/migrate/20120218160361_move_to_configurable_gateways.rb +54 -0
- data/spec/dummy/db/migrate/20120218160362_product_groups_and_scopes.rb +18 -0
- data/spec/dummy/db/migrate/20120218160363_add_open_id_authentication_tables.rb +15 -0
- data/spec/dummy/db/migrate/20120218160364_add_openid_field_to_users.rb +24 -0
- data/spec/dummy/db/migrate/20120218160365_change_preference_value_type.rb +10 -0
- data/spec/dummy/db/migrate/20120218160366_create_billing_integrations.rb +12 -0
- data/spec/dummy/db/migrate/20120218160367_charge_refactoring.rb +39 -0
- data/spec/dummy/db/migrate/20120218160368_add_some_indexes.rb +11 -0
- data/spec/dummy/db/migrate/20120218160369_checkout_state_machine.rb +5 -0
- data/spec/dummy/db/migrate/20120218160370_state_for_shipments.rb +5 -0
- data/spec/dummy/db/migrate/20120218160371_make_state_events_polymorphic.rb +12 -0
- data/spec/dummy/db/migrate/20120218160372_ship_address_id_for_checkouts.rb +5 -0
- data/spec/dummy/db/migrate/20120218160373_shipping_method_id_for_checkouts.rb +5 -0
- data/spec/dummy/db/migrate/20120218160374_creditcard_last_four_digits.rb +14 -0
- data/spec/dummy/db/migrate/20120218160375_populate_legacy_shipment_state.rb +15 -0
- data/spec/dummy/db/migrate/20120218160376_add_cost_price.rb +5 -0
- data/spec/dummy/db/migrate/20120218160377_shipment_id_for_inventory_units.rb +25 -0
- data/spec/dummy/db/migrate/20120218160378_cim_fields_for_creditcards.rb +6 -0
- data/spec/dummy/db/migrate/20120218160379_create_return_authorizations.rb +12 -0
- data/spec/dummy/db/migrate/20120218160380_add_return_authorization_to_inventory_units.rb +5 -0
- data/spec/dummy/db/migrate/20120218160381_create_trackers.rb +10 -0
- data/spec/dummy/db/migrate/20120218160382_creditcard_id_for_creditcard_txns.rb +5 -0
- data/spec/dummy/db/migrate/20120218160383_original_creditcard_txn_id_for_creditcard_txns.rb +5 -0
- data/spec/dummy/db/migrate/20120218160384_add_test_mode_to_billing_integration.rb +6 -0
- data/spec/dummy/db/migrate/20120218160385_create_products_product_groups.rb +8 -0
- data/spec/dummy/db/migrate/20120218160386_create_payment_methods.rb +16 -0
- data/spec/dummy/db/migrate/20120218160387_polymorphic_payments.rb +42 -0
- data/spec/dummy/db/migrate/20120218160388_change_payments_payment_method_to_belongs_to.rb +11 -0
- data/spec/dummy/db/migrate/20120218160389_assign_creditcard_txns_to_payment.rb +23 -0
- data/spec/dummy/db/migrate/20120218160390_sti_for_transactions.rb +15 -0
- data/spec/dummy/db/migrate/20120218160391_drop_billing_integrations.rb +16 -0
- data/spec/dummy/db/migrate/20120218160392_deleted_at_for_payment_methods.rb +14 -0
- data/spec/dummy/db/migrate/20120218160393_add_adjustments_index.rb +6 -0
- data/spec/dummy/db/migrate/20120218160394_fix_by_popularity.rb +9 -0
- data/spec/dummy/db/migrate/20120218160395_add_alt_text_to_images.rb +5 -0
- data/spec/dummy/db/migrate/20120218160396_fix_existing_coupon_credits.rb +13 -0
- data/spec/dummy/db/migrate/20120218160397_add_display_to_payment_methods.rb +5 -0
- data/spec/dummy/db/migrate/20120218160398_add_addresses_checkouts_indexes.rb +8 -0
- data/spec/dummy/db/migrate/20120218160399_add_icon_to_taxons.rb +17 -0
- data/spec/dummy/db/migrate/20120218160400_add_description_to_taxons.rb +11 -0
- data/spec/dummy/db/migrate/20120218160401_index_for_shipments_number.rb +5 -0
- data/spec/dummy/db/migrate/20120218160402_add_index_on_users_persistence_token.rb +5 -0
- data/spec/dummy/db/migrate/20120218160403_add_default_to_tax_categories.rb +5 -0
- data/spec/dummy/db/migrate/20120218160404_add_display_to_shipping_methods.rb +5 -0
- data/spec/dummy/db/migrate/20120218160405_rename_payment_method_display.rb +5 -0
- data/spec/dummy/db/migrate/20120218160406_rename_preferences_field.rb +5 -0
- data/spec/dummy/db/migrate/20120218160407_add_guest_flag.rb +5 -0
- data/spec/dummy/db/migrate/20120218160408_drop_order_token.rb +9 -0
- data/spec/dummy/db/migrate/20120218160409_payments_state_and_assigned_to_order_only.rb +14 -0
- data/spec/dummy/db/migrate/20120218160410_create_address_keys_for_order.rb +6 -0
- data/spec/dummy/db/migrate/20120218160411_payment_total_for_orders.rb +5 -0
- data/spec/dummy/db/migrate/20120218160412_shipping_method_id_for_orders.rb +5 -0
- data/spec/dummy/db/migrate/20120218160413_add_shipment_and_payment_state.rb +6 -0
- data/spec/dummy/db/migrate/20120218160414_refactor_adjustments.rb +29 -0
- data/spec/dummy/db/migrate/20120218160415_response_code_and_avs_response_for_payments.rb +6 -0
- data/spec/dummy/db/migrate/20120218160416_change_guest_flag_to_anonymous.rb +5 -0
- data/spec/dummy/db/migrate/20120218160417_email_for_orders.rb +5 -0
- data/spec/dummy/db/migrate/20120218160418_create_mail_methods.rb +10 -0
- data/spec/dummy/db/migrate/20120218160419_rename_frozen_to_locked.rb +5 -0
- data/spec/dummy/db/migrate/20120218160420_move_special_instructions_to_orders.rb +10 -0
- data/spec/dummy/db/migrate/20120218160421_create_log_entries.rb +11 -0
- data/spec/dummy/db/migrate/20120218160422_migrate_transactions_to_payment_state.rb +98 -0
- data/spec/dummy/db/migrate/20120218160423_delete_in_progress_orders.rb +19 -0
- data/spec/dummy/db/migrate/20120218160424_migrate_checkout_to_orders.rb +23 -0
- data/spec/dummy/db/migrate/20120218160425_remove_shipped_state.rb +12 -0
- data/spec/dummy/db/migrate/20120218160426_prevent_nil_payment_total.rb +8 -0
- data/spec/dummy/db/migrate/20120218160427_prevent_nil_email.rb +9 -0
- data/spec/dummy/db/migrate/20120218160428_generate_anonymous_users.rb +20 -0
- data/spec/dummy/db/migrate/20120218160429_update_order_state.rb +12 -0
- data/spec/dummy/db/migrate/20120218160430_cleanup_legacy_tables.rb +11 -0
- data/spec/dummy/db/migrate/20120218160431_remove_number_and_cvv_from_credicard.rb +11 -0
- data/spec/dummy/db/migrate/20120218160432_drop_anonymous_field_for_user.rb +9 -0
- data/spec/dummy/db/migrate/20120218160433_renamed_rma_cancelled_state.rb +9 -0
- data/spec/dummy/db/migrate/20120218160434_fix_problematic_index_names.rb +13 -0
- data/spec/dummy/db/migrate/20120218160435_add_position_to_variants.rb +5 -0
- data/spec/dummy/db/migrate/20120218160436_add_next_state_to_state_events.rb +5 -0
- data/spec/dummy/db/migrate/20120218160437_add_position_to_option_types.rb +5 -0
- data/spec/dummy/db/migrate/20120218160438_remove_trailing_slashes_in_taxon_permalinks.rb +19 -0
- data/spec/dummy/db/migrate/20120218160439_create_activators.rb +14 -0
- data/spec/dummy/db/migrate/20120218160440_eligible_for_adjustments.rb +5 -0
- data/spec/dummy/db/migrate/20120218160441_namespace_top_level_models.rb +52 -0
- data/spec/dummy/db/migrate/20120218160442_migrate_namespaced_polymorphic_models.rb +52 -0
- data/spec/dummy/db/migrate/20120218160443_make_adjustments_polymorphic.rb +9 -0
- data/spec/dummy/db/migrate/20120218160444_add_company_to_addresses.rb +5 -0
- data/spec/dummy/db/migrate/20120218160445_add_inc_tax_to_tax_rates.rb +5 -0
- data/spec/dummy/db/migrate/20120218160446_rename_inc_price_attribute.rb +5 -0
- data/spec/dummy/db/migrate/20120218160447_add_default_tax_zone.rb +5 -0
- data/spec/dummy/db/migrate/20120218160448_associate_shipping_methods_and_shipping_categories.rb +7 -0
- data/spec/dummy/db/migrate/20120218160449_add_match_rules_to_shipping_methods.rb +7 -0
- data/spec/dummy/db/migrate/20120218160450_new_preferences.rb +48 -0
- data/spec/dummy/db/migrate/20120218160451_add_deleted_at_to_tax_category.rb +5 -0
- data/spec/dummy/db/schema.rb +553 -0
- data/spec/dummy/db/seeds.rb +11 -0
- data/spec/dummy/log/test.log +1136 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/spec/dummy/script/rails +6 -0
- data/spec/flat_in_range_spec.rb +56 -0
- data/spec/spec_helper.rb +32 -0
- metadata +428 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
class Transaction < ActiveRecord::Base; end
|
2
|
+
class CreditcardTxn < Transaction; end
|
3
|
+
|
4
|
+
class MigrateTransactionsToPaymentState < ActiveRecord::Migration
|
5
|
+
|
6
|
+
AUTHORIZED=1
|
7
|
+
COMPLETED=2
|
8
|
+
PURCHASED=3
|
9
|
+
VOIDED = 4
|
10
|
+
CREDITED =5
|
11
|
+
|
12
|
+
PAYMENT_COMPLETE = 'completed'
|
13
|
+
PAYMENT_VOID = 'void'
|
14
|
+
PAYMENT_PENDING = 'pending'
|
15
|
+
|
16
|
+
# Temporarily set the table back to payments
|
17
|
+
Spree::Payment.table_name = 'payments'
|
18
|
+
|
19
|
+
def up
|
20
|
+
migrate_authorized_only_transactions
|
21
|
+
migrate_voided_transactions
|
22
|
+
migrate_completed_transactions
|
23
|
+
migrate_purchased_transactions
|
24
|
+
migrate_credited_transactions
|
25
|
+
|
26
|
+
Spree::Payment.table_name = 'spree_payments'
|
27
|
+
end
|
28
|
+
|
29
|
+
def migrate_credited_transactions
|
30
|
+
credited = Transaction.find_by_sql("SELECT * FROM transactions WHERE txn_type = #{CREDITED}")
|
31
|
+
credited.each do |tx|
|
32
|
+
payment = Spree::Payment.find(tx)
|
33
|
+
order = payment.order
|
34
|
+
order.create_payment(
|
35
|
+
:amount => tx.amount,
|
36
|
+
:source_id => payment.source_id, :source_type => 'Creditcard',
|
37
|
+
:payment_method_id => payment.payment_method_id, :state => PAYMENT_COMPLETE,
|
38
|
+
:avs_response => tx.avs_response, :response_code => tx.response_code
|
39
|
+
)
|
40
|
+
end
|
41
|
+
credited.each { |rec| rec.destroy }
|
42
|
+
end
|
43
|
+
|
44
|
+
def migrate_voided_transactions
|
45
|
+
voided = Transaction.find_by_sql("SELECT * FROM transactions WHERE txn_type = #{VOIDED}")
|
46
|
+
voided.each do |tx|
|
47
|
+
update_payment(tx, PAYMENT_VOID)
|
48
|
+
end
|
49
|
+
unless voided.empty?
|
50
|
+
all_but_credited = [AUTHORIZED, COMPLETED, PURCHASED, VOIDED]
|
51
|
+
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(',')})")
|
52
|
+
voided_and_subsequent_transactions.each { |rec| rec.destroy }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def migrate_purchased_transactions
|
57
|
+
migrate_transactions(PURCHASED)
|
58
|
+
end
|
59
|
+
|
60
|
+
def migrate_completed_transactions
|
61
|
+
migrate_transactions(COMPLETED)
|
62
|
+
end
|
63
|
+
|
64
|
+
def migrate_transactions(type)
|
65
|
+
txs = Transaction.find_by_sql("SELECT * FROM transactions WHERE txn_type = #{type}")
|
66
|
+
txs.each do |tx|
|
67
|
+
update_payment(tx, PAYMENT_COMPLETE)
|
68
|
+
end
|
69
|
+
txs.each { |rec| rec.destroy }
|
70
|
+
end
|
71
|
+
|
72
|
+
def migrate_authorized_only_transactions
|
73
|
+
if (ActiveRecord::Base.connection.adapter_name == 'PostgreSQL')
|
74
|
+
group_by_clause = 'GROUP BY transactions.' + Transaction.column_names.join(', transactions.')
|
75
|
+
else
|
76
|
+
group_by_clause = 'GROUP BY payment_id'
|
77
|
+
end
|
78
|
+
authorized_only = Transaction.find_by_sql("SELECT * FROM transactions #{group_by_clause} HAVING COUNT(payment_id) = 1 AND txn_type = #{AUTHORIZED}")
|
79
|
+
authorized_only.each do |tx|
|
80
|
+
update_payment(tx, PAYMENT_PENDING)
|
81
|
+
end
|
82
|
+
authorized_only.each { |rec| rec.destroy }
|
83
|
+
end
|
84
|
+
|
85
|
+
def update_payment(tx, state)
|
86
|
+
payment = Spree::Payment.find(tx.payment_id)
|
87
|
+
payment.update_attributes_without_callbacks({
|
88
|
+
:state => state,
|
89
|
+
:source_type => 'Creditcard',
|
90
|
+
:amount => tx.amount,
|
91
|
+
:response_code => tx.response_code,
|
92
|
+
:avs_response => tx.avs_response
|
93
|
+
})
|
94
|
+
end
|
95
|
+
|
96
|
+
def down
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class DeleteInProgressOrders < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
execute("DELETE FROM orders WHERE orders.state = 'in_progress'")
|
4
|
+
delete_orphans('adjustments')
|
5
|
+
delete_orphans('checkouts')
|
6
|
+
delete_orphans('shipments')
|
7
|
+
delete_orphans('payments')
|
8
|
+
delete_orphans('line_items')
|
9
|
+
delete_orphans('inventory_units')
|
10
|
+
end
|
11
|
+
|
12
|
+
def down
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def delete_orphans(table_name)
|
17
|
+
execute "DELETE FROM #{table_name} WHERE order_id NOT IN (SELECT id FROM orders)"
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class MigrateCheckoutToOrders < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
orders = select_all "SELECT * FROM orders"
|
4
|
+
|
5
|
+
orders.each do |order|
|
6
|
+
checkout = update_order(order)
|
7
|
+
execute "DELETE FROM checkouts WHERE id = #{checkout['id']}" if checkout
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def down
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def update_order(order)
|
16
|
+
checkout = select_one "SELECT * FROM checkouts WHERE order_id = #{order['id']}"
|
17
|
+
|
18
|
+
if checkout
|
19
|
+
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']}"
|
20
|
+
end
|
21
|
+
checkout
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class RemoveShippedState < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
execute "UPDATE orders SET state = 'complete' WHERE state = 'shipped'"
|
4
|
+
shipments = select_all "SELECT shipments.id FROM shipments WHERE order_id IN (SELECT orders.id FROM orders WHERE orders.state = 'shipped')"
|
5
|
+
shipments.each do |shipment|
|
6
|
+
execute "UPDATE shipments SET state='shipped' WHERE id = #{shipment[:id]}"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def down
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class GenerateAnonymousUsers < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
Spree::User.table_name = 'users'
|
4
|
+
Spree::Order.table_name = 'orders'
|
5
|
+
|
6
|
+
Spree::User.reset_column_information
|
7
|
+
Spree::Order.where(:user_id => nil).each do |order|
|
8
|
+
user = Spree::User.anonymous!
|
9
|
+
user.email ||= order.email
|
10
|
+
order.user = user
|
11
|
+
order.save!
|
12
|
+
end
|
13
|
+
|
14
|
+
Spree::User.table_name = 'spree_users'
|
15
|
+
Spree::Order.table_name = 'spree_orders'
|
16
|
+
end
|
17
|
+
|
18
|
+
def down
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class RemoveNumberAndCvvFromCredicard < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
remove_column :creditcards, :number
|
4
|
+
remove_column :creditcards, :verification_value
|
5
|
+
end
|
6
|
+
|
7
|
+
def down
|
8
|
+
add_column :creditcards, :verification_value, :text
|
9
|
+
add_column :creditcards, :number, :text
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class RenamedRmaCancelledState < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
execute "UPDATE return_authorizations SET state = 'canceled' WHERE state = 'cancelled'"
|
4
|
+
end
|
5
|
+
|
6
|
+
def down
|
7
|
+
execute "UPDATE return_authorizations SET state = 'cancelled' WHERE state = 'canceled'"
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class FixProblematicIndexNames < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
begin
|
4
|
+
remove_index :preferences, :name => 'index_preferences_on_owner_and_attribute_and_preference'
|
5
|
+
rescue ArgumentError
|
6
|
+
# ignore - already remove then
|
7
|
+
end
|
8
|
+
add_index :preferences, [:owner_id, :owner_type, :name, :group_id, :group_type], :name => 'ix_prefs_on_owner_attr_pref', :unique => true
|
9
|
+
end
|
10
|
+
|
11
|
+
def down
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class RemoveTrailingSlashesInTaxonPermalinks < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
taxons = select_all "SELECT * FROM taxons"
|
4
|
+
taxons.each do |taxon|
|
5
|
+
if taxon['permalink'] && taxon['permalink'][-1..-1] == '/'
|
6
|
+
execute "UPDATE taxons SET permalink = '#{taxon['permalink'][0...-1]}' WHERE id = #{taxon['id']}"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def down
|
12
|
+
taxons = select_all "SELECT * FROM taxons"
|
13
|
+
taxons.each do |taxon|
|
14
|
+
if taxon['permalink'] && taxon['permalink'][-1..-1] != '/'
|
15
|
+
execute "UPDATE taxons SET permalink = '#{taxon['permalink'] + '/'}' WHERE id = #{taxon['id']}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateActivators < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :activators, :force => true do |t|
|
4
|
+
t.string :description
|
5
|
+
t.datetime :expires_at
|
6
|
+
t.datetime :created_at
|
7
|
+
t.datetime :updated_at
|
8
|
+
t.datetime :starts_at
|
9
|
+
t.string :name
|
10
|
+
t.string :event_name
|
11
|
+
t.string :type
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class NamespaceTopLevelModels < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
rename_table :activators, :spree_activators
|
4
|
+
rename_table :addresses, :spree_addresses
|
5
|
+
rename_table :adjustments, :spree_adjustments
|
6
|
+
rename_table :configurations, :spree_configurations
|
7
|
+
rename_table :assets, :spree_assets
|
8
|
+
rename_table :calculators, :spree_calculators
|
9
|
+
rename_table :countries, :spree_countries
|
10
|
+
rename_table :creditcards, :spree_creditcards
|
11
|
+
rename_table :gateways, :spree_gateways
|
12
|
+
rename_table :inventory_units, :spree_inventory_units
|
13
|
+
rename_table :line_items, :spree_line_items
|
14
|
+
rename_table :log_entries, :spree_log_entries
|
15
|
+
rename_table :mail_methods, :spree_mail_methods
|
16
|
+
rename_table :option_types, :spree_option_types
|
17
|
+
rename_table :option_values, :spree_option_values
|
18
|
+
rename_table :option_types_prototypes, :spree_option_types_prototypes
|
19
|
+
rename_table :option_values_variants, :spree_option_values_variants
|
20
|
+
rename_table :orders, :spree_orders
|
21
|
+
rename_table :payments, :spree_payments
|
22
|
+
rename_table :payment_methods, :spree_payment_methods
|
23
|
+
rename_table :preferences, :spree_preferences
|
24
|
+
rename_table :products, :spree_products
|
25
|
+
rename_table :product_groups, :spree_product_groups
|
26
|
+
rename_table :product_groups_products, :spree_product_groups_products
|
27
|
+
rename_table :product_option_types, :spree_product_option_types
|
28
|
+
rename_table :product_properties, :spree_product_properties
|
29
|
+
rename_table :product_scopes, :spree_product_scopes
|
30
|
+
rename_table :products_taxons, :spree_products_taxons
|
31
|
+
rename_table :properties, :spree_properties
|
32
|
+
rename_table :prototypes, :spree_prototypes
|
33
|
+
rename_table :properties_prototypes, :spree_properties_prototypes
|
34
|
+
rename_table :return_authorizations, :spree_return_authorizations
|
35
|
+
rename_table :roles, :spree_roles
|
36
|
+
rename_table :roles_users, :spree_roles_users
|
37
|
+
rename_table :shipments, :spree_shipments
|
38
|
+
rename_table :shipping_categories, :spree_shipping_categories
|
39
|
+
rename_table :shipping_methods, :spree_shipping_methods
|
40
|
+
rename_table :states, :spree_states
|
41
|
+
rename_table :state_events, :spree_state_events
|
42
|
+
rename_table :tax_categories, :spree_tax_categories
|
43
|
+
rename_table :tax_rates, :spree_tax_rates
|
44
|
+
rename_table :taxons, :spree_taxons
|
45
|
+
rename_table :taxonomies, :spree_taxonomies
|
46
|
+
rename_table :trackers, :spree_trackers
|
47
|
+
rename_table :users, :spree_users
|
48
|
+
rename_table :variants, :spree_variants
|
49
|
+
rename_table :zones, :spree_zones
|
50
|
+
rename_table :zone_members, :spree_zone_members
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class MigrateNamespacedPolymorphicModels < ActiveRecord::Migration
|
2
|
+
def concat(str1, str2)
|
3
|
+
dbtype = Rails.configuration.database_configuration[Rails.env]['adapter'].to_sym
|
4
|
+
|
5
|
+
case dbtype
|
6
|
+
when :mysql, :mysql2
|
7
|
+
"CONCAT(#{str1}, #{str2})"
|
8
|
+
when :sqlserver
|
9
|
+
"(#{str1} + #{str2})"
|
10
|
+
else
|
11
|
+
"(#{str1} || #{str2})"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def update_column_data(table_names, column_name)
|
16
|
+
tables = Array.wrap(table_names)
|
17
|
+
tables.each do |table|
|
18
|
+
execute "UPDATE #{table} SET #{column_name} = #{concat("'Spree::'", column_name)}" +
|
19
|
+
" where #{column_name} NOT LIKE 'Spree::%' AND #{column_name} IS NOT NULL"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def replace_column_data(table_names, column_name)
|
24
|
+
tables = Array.wrap(table_names)
|
25
|
+
tables.each do |table|
|
26
|
+
execute "UPDATE #{table} SET #{column_name} = REPLACE(#{column_name}, 'Spree::', '') " +
|
27
|
+
" where #{column_name} LIKE 'Spree::%'"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def up
|
32
|
+
update_column_data(['spree_payments', 'spree_adjustments', 'spree_log_entries'], 'source_type')
|
33
|
+
update_column_data('spree_adjustments', 'originator_type')
|
34
|
+
update_column_data('spree_calculators', 'calculable_type')
|
35
|
+
update_column_data('spree_preferences', 'owner_type')
|
36
|
+
update_column_data('spree_state_events', 'stateful_type')
|
37
|
+
update_column_data(['spree_activators', 'spree_assets', 'spree_calculators', 'spree_configurations', 'spree_gateways', 'spree_payment_methods'], 'type')
|
38
|
+
update_column_data('spree_assets', 'viewable_type')
|
39
|
+
update_column_data('spree_zone_members', 'zoneable_type')
|
40
|
+
end
|
41
|
+
|
42
|
+
def down
|
43
|
+
replace_column_data(['spree_payments', 'spree_adjustments', 'spree_log_entries'], 'source_type')
|
44
|
+
replace_column_data('spree_adjustments', 'originator_type')
|
45
|
+
replace_column_data('spree_calculators', 'calculable_type')
|
46
|
+
replace_column_data('spree_preferences', 'owner_type')
|
47
|
+
replace_column_data('spree_state_events', 'stateful_type')
|
48
|
+
replace_column_data(['spree_activators', 'spree_assets', 'spree_calculators', 'spree_configurations', 'spree_gateways', 'spree_payment_methods'], 'type')
|
49
|
+
replace_column_data('spree_assets', 'viewable_type')
|
50
|
+
replace_column_data('spree_zone_members', 'zoneable_type')
|
51
|
+
end
|
52
|
+
end
|