spree_core 4.2.5 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (263) hide show
  1. checksums.yaml +4 -4
  2. data/app/finders/concerns/spree/product_filterable.rb +9 -0
  3. data/app/finders/spree/cms_pages/find.rb +41 -0
  4. data/app/finders/spree/menus/find.rb +11 -0
  5. data/app/finders/spree/option_values/find_available.rb +20 -0
  6. data/app/finders/spree/orders/find_complete.rb +14 -2
  7. data/app/finders/spree/orders/find_current.rb +1 -13
  8. data/app/finders/spree/product_properties/find_available.rb +20 -0
  9. data/app/finders/spree/products/find.rb +80 -21
  10. data/app/finders/spree/stores/find_current.rb +24 -0
  11. data/app/finders/spree/taxons/find.rb +22 -6
  12. data/app/helpers/spree/base_helper.rb +69 -7
  13. data/app/helpers/spree/locale_helper.rb +5 -1
  14. data/app/helpers/spree/products_helper.rb +7 -3
  15. data/app/models/concerns/spree/display_link.rb +42 -0
  16. data/app/models/concerns/spree/display_money.rb +6 -2
  17. data/app/models/concerns/spree/filter_param.rb +21 -0
  18. data/app/models/concerns/spree/image_methods.rb +24 -0
  19. data/app/models/concerns/spree/memoized_data.rb +24 -0
  20. data/app/models/concerns/spree/multi_store_resource.rb +24 -0
  21. data/app/models/concerns/spree/product_scopes.rb +71 -8
  22. data/app/models/concerns/spree/single_store_resource.rb +19 -0
  23. data/app/models/concerns/spree/user_address.rb +19 -0
  24. data/app/models/concerns/spree/user_methods.rb +14 -12
  25. data/app/models/concerns/spree/user_payment_source.rb +1 -1
  26. data/app/models/concerns/spree/user_reporting.rb +35 -10
  27. data/app/models/concerns/spree/user_roles.rb +25 -0
  28. data/app/models/spree/ability.rb +3 -1
  29. data/app/models/spree/address.rb +27 -6
  30. data/app/models/spree/app_configuration.rb +8 -0
  31. data/app/models/spree/app_dependencies.rb +20 -6
  32. data/app/models/spree/base.rb +18 -0
  33. data/app/models/spree/classification.rb +3 -0
  34. data/app/models/spree/cms/pages/feature_page.rb +7 -0
  35. data/app/models/spree/cms/pages/homepage.rb +20 -0
  36. data/app/models/spree/cms/pages/standard_page.rb +4 -0
  37. data/app/models/spree/cms/sections/featured_article.rb +22 -0
  38. data/app/models/spree/cms/sections/hero_image.rb +38 -0
  39. data/app/models/spree/cms/sections/image_gallery.rb +103 -0
  40. data/app/models/spree/cms/sections/product_carousel.rb +14 -0
  41. data/app/models/spree/cms/sections/rich_text_content.rb +13 -0
  42. data/app/models/spree/cms/sections/side_by_side_images.rb +74 -0
  43. data/app/models/spree/cms_page.rb +66 -0
  44. data/app/models/spree/cms_section.rb +69 -0
  45. data/app/models/spree/country.rb +14 -6
  46. data/app/models/spree/credit_card.rb +2 -8
  47. data/app/models/spree/customer_return.rb +8 -2
  48. data/app/models/spree/gateway/bogus.rb +6 -4
  49. data/app/models/spree/icon.rb +9 -0
  50. data/app/models/spree/image/configuration/active_storage.rb +2 -0
  51. data/app/models/spree/image.rb +5 -24
  52. data/app/models/spree/inventory_unit.rb +1 -1
  53. data/app/models/spree/line_item.rb +1 -1
  54. data/app/models/spree/menu.rb +63 -0
  55. data/app/models/spree/menu_item.rb +76 -0
  56. data/app/models/spree/option_type.rb +1 -1
  57. data/app/models/spree/option_value.rb +11 -0
  58. data/app/models/spree/option_value_variant.rb +1 -1
  59. data/app/models/spree/order/address_book.rb +3 -5
  60. data/app/models/spree/order/currency_updater.rb +1 -1
  61. data/app/models/spree/order/emails.rb +32 -0
  62. data/app/models/spree/order/payments.rb +1 -1
  63. data/app/models/spree/order/store_credit.rb +1 -1
  64. data/app/models/spree/order.rb +46 -45
  65. data/app/models/spree/payment.rb +7 -0
  66. data/app/models/spree/payment_method.rb +16 -0
  67. data/app/models/spree/preferences/preferable.rb +12 -0
  68. data/app/models/spree/preferences/preferable_class_methods.rb +10 -1
  69. data/app/models/spree/product.rb +37 -30
  70. data/app/models/spree/product_property.rb +19 -4
  71. data/app/models/spree/promotion/rules/country.rb +1 -1
  72. data/app/models/spree/promotion/rules/first_order.rb +4 -3
  73. data/app/models/spree/promotion/rules/taxon.rb +10 -7
  74. data/app/models/spree/promotion.rb +6 -15
  75. data/app/models/spree/promotion_handler/cart.rb +7 -2
  76. data/app/models/spree/promotion_handler/coupon.rb +5 -4
  77. data/app/models/spree/promotion_handler/free_shipping.rb +5 -6
  78. data/app/models/spree/promotion_handler/page.rb +3 -2
  79. data/app/models/spree/promotion_handler/promotion_duplicator.rb +1 -0
  80. data/app/models/spree/promotion_rule.rb +2 -0
  81. data/app/models/spree/property.rb +28 -1
  82. data/app/models/spree/reimbursement.rb +3 -1
  83. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +2 -1
  84. data/app/models/spree/shipment_handler.rb +4 -2
  85. data/app/models/spree/stock/quantifier.rb +6 -6
  86. data/app/models/spree/stock_location.rb +9 -0
  87. data/app/models/spree/store.rb +90 -7
  88. data/app/models/spree/store_credit.rb +7 -3
  89. data/app/models/spree/store_credit_event.rb +2 -2
  90. data/app/models/spree/store_payment_method.rb +11 -0
  91. data/app/models/spree/store_product.rb +11 -0
  92. data/app/models/spree/store_promotion.rb +11 -0
  93. data/app/models/spree/taxon.rb +22 -1
  94. data/app/models/spree/taxon_image/configuration/active_storage.rb +2 -0
  95. data/app/models/spree/taxon_image.rb +1 -0
  96. data/app/models/spree/taxonomy.rb +3 -1
  97. data/app/models/spree/variant.rb +21 -6
  98. data/app/presenters/spree/filters/options_presenter.rb +47 -0
  99. data/app/presenters/spree/filters/price_presenter.rb +22 -0
  100. data/app/presenters/spree/filters/price_range_presenter.rb +29 -0
  101. data/app/presenters/spree/filters/properties_presenter.rb +23 -0
  102. data/app/presenters/spree/filters/property_presenter.rb +42 -0
  103. data/app/presenters/spree/filters/quantified_price_range_presenter.rb +44 -0
  104. data/app/services/spree/account/addresses/create.rb +1 -0
  105. data/app/services/spree/account/addresses/helper.rb +6 -0
  106. data/app/services/spree/account/addresses/update.rb +9 -3
  107. data/app/services/spree/account/create.rb +17 -0
  108. data/app/services/spree/account/update.rb +15 -0
  109. data/app/services/spree/build_localized_redirect_url.rb +1 -1
  110. data/app/services/spree/cart/associate.rb +16 -0
  111. data/app/services/spree/cart/change_currency.rb +27 -0
  112. data/app/services/spree/cart/create.rb +5 -3
  113. data/app/services/spree/cart/destroy.rb +40 -0
  114. data/app/services/spree/cart/empty.rb +36 -0
  115. data/app/services/spree/cart/estimate_shipping_rates.rb +3 -3
  116. data/app/services/spree/checkout/add_store_credit.rb +1 -1
  117. data/app/services/spree/classifications/reposition.rb +18 -0
  118. data/app/services/spree/credit_cards/destroy.rb +41 -0
  119. data/app/sorters/spree/base_sorter.rb +23 -11
  120. data/app/sorters/spree/products/sort.rb +23 -7
  121. data/app/validators/db_maximum_length_validator.rb +5 -0
  122. data/app/validators/email_validator.rb +3 -1
  123. data/config/initializers/active_storage.rb +2 -0
  124. data/config/locales/en.yml +177 -3
  125. data/config/routes.rb +0 -5
  126. data/db/migrate/20201023152810_add_filterable_to_spree_properties.rb +8 -0
  127. data/db/migrate/20210407200948_create_spree_menus.rb +16 -0
  128. data/db/migrate/20210408092939_create_spree_menu_items.rb +31 -0
  129. data/db/migrate/20210504163720_add_filter_param_to_spree_product_properties.rb +8 -0
  130. data/db/migrate/20210505114659_add_filter_param_to_spree_properties.rb +8 -0
  131. data/db/migrate/20210512191732_create_spree_cms_pages.rb +24 -0
  132. data/db/migrate/20210514204251_create_spree_cms_sections.rb +22 -0
  133. data/db/migrate/20210527094055_create_spree_products_stores.rb +36 -0
  134. data/db/migrate/20210608045519_ensure_store_default_country_is_set.rb +5 -0
  135. data/db/migrate/20210702112334_add_missing_timestamp_columns.rb +46 -0
  136. data/db/migrate/20210713131614_add_unique_index_on_property_id_and_product_id_to_product_properties.rb +29 -0
  137. data/db/migrate/20210715091956_add_store_id_to_spree_store_credits.rb +10 -0
  138. data/db/migrate/20210716093151_add_store_id_to_spree_taxonomies.rb +11 -0
  139. data/db/migrate/20210716104141_add_index_on_name_parent_id_and_taxonomy_id_on_spree_taxons.rb +31 -0
  140. data/db/migrate/20210721120857_add_index_on_permalink_parent_id_and_taxonomy_id_on_spree_taxons.rb +31 -0
  141. data/db/migrate/20210721125657_create_spree_promotions_stores.rb +29 -0
  142. data/db/migrate/20210722090705_add_store_id_to_spree_customer_returns.rb +11 -0
  143. data/db/migrate/20210726065456_change_integer_id_columns_into_bigint.rb +305 -0
  144. data/db/migrate/20210730154425_fix_promotion_code_and_path_unique_indexes.rb +9 -0
  145. data/lib/generators/spree/dummy/dummy_generator.rb +11 -6
  146. data/lib/generators/spree/dummy/templates/rails/test.rb +2 -0
  147. data/lib/generators/spree/dummy_model/templates/model.rb.tt +1 -1
  148. data/lib/generators/spree/install/install_generator.rb +12 -24
  149. data/lib/spree/core/components.rb +8 -0
  150. data/lib/spree/core/controller_helpers/auth.rb +7 -1
  151. data/lib/spree/core/controller_helpers/common.rb +1 -1
  152. data/lib/spree/core/controller_helpers/order.rb +4 -4
  153. data/lib/spree/core/controller_helpers/search.rb +1 -0
  154. data/lib/spree/core/controller_helpers/store.rb +24 -1
  155. data/lib/spree/core/engine.rb +6 -0
  156. data/lib/spree/core/importer/product.rb +3 -1
  157. data/lib/spree/core/product_duplicator.rb +1 -0
  158. data/lib/spree/core/search/base.rb +17 -22
  159. data/lib/spree/core/version.rb +1 -1
  160. data/lib/spree/core.rb +8 -4
  161. data/lib/spree/i18n.rb +1 -1
  162. data/lib/spree/money.rb +2 -1
  163. data/lib/spree/permitted_attributes.rb +21 -3
  164. data/lib/spree/testing_support/authorization_helpers.rb +6 -3
  165. data/lib/spree/testing_support/capybara_config.rb +3 -1
  166. data/lib/spree/testing_support/common_rake.rb +17 -4
  167. data/lib/spree/testing_support/extension_rake.rb +2 -2
  168. data/lib/spree/testing_support/factories/address_factory.rb +1 -1
  169. data/lib/spree/testing_support/factories/classification_factory.rb +8 -0
  170. data/lib/spree/testing_support/factories/cms_page_factory.rb +20 -0
  171. data/lib/spree/testing_support/factories/cms_section_factory.rb +31 -0
  172. data/lib/spree/testing_support/factories/customer_return_factory.rb +24 -17
  173. data/lib/spree/testing_support/factories/icon_factory.rb +7 -0
  174. data/lib/spree/testing_support/factories/line_item_factory.rb +6 -2
  175. data/lib/spree/testing_support/factories/menu_factory.rb +16 -0
  176. data/lib/spree/testing_support/factories/menu_item_factory.rb +10 -0
  177. data/lib/spree/testing_support/factories/options_factory.rb +5 -0
  178. data/lib/spree/testing_support/factories/order_factory.rb +11 -2
  179. data/lib/spree/testing_support/factories/payment_method_factory.rb +6 -2
  180. data/lib/spree/testing_support/factories/product_factory.rb +17 -1
  181. data/lib/spree/testing_support/factories/product_property_factory.rb +1 -1
  182. data/lib/spree/testing_support/factories/promotion_factory.rb +18 -9
  183. data/lib/spree/testing_support/factories/property_factory.rb +22 -0
  184. data/lib/spree/testing_support/factories/stock_location_factory.rb +5 -4
  185. data/lib/spree/testing_support/factories/store_credit_factory.rb +1 -0
  186. data/lib/spree/testing_support/factories/store_factory.rb +11 -0
  187. data/lib/spree/testing_support/factories/taxon_factory.rb +3 -1
  188. data/lib/spree/testing_support/factories/taxon_image_factory.rb +7 -0
  189. data/lib/spree/testing_support/factories/taxonomy_factory.rb +1 -0
  190. data/lib/spree/testing_support/factories/user_factory.rb +7 -2
  191. data/lib/spree/testing_support/factories/variant_factory.rb +2 -2
  192. data/lib/spree/testing_support/flatpickr_capybara.rb +58 -35
  193. data/lib/spree/testing_support/locale_helpers.rb +1 -1
  194. data/lib/spree/testing_support/order_walkthrough.rb +9 -9
  195. data/lib/spree/testing_support/rspec_retry_config.rb +5 -0
  196. data/lib/tasks/core.rake +1 -1
  197. data/spec/fixtures/favicon.ico +0 -0
  198. data/spec/fixtures/files/icon_256x256.gif +0 -0
  199. data/spec/fixtures/files/icon_256x256.png +0 -0
  200. data/spec/fixtures/files/icon_512x512.png +0 -0
  201. data/spec/fixtures/files/img_256x128.png +0 -0
  202. data/spree_core.gemspec +12 -11
  203. metadata +211 -159
  204. data/app/assets/images/logo/spree_50.png +0 -0
  205. data/app/assets/images/noimage/large.png +0 -0
  206. data/app/assets/images/noimage/mini.png +0 -0
  207. data/app/assets/images/noimage/product.png +0 -0
  208. data/app/assets/images/noimage/small.png +0 -0
  209. data/app/assets/javascripts/spree.js +0 -78
  210. data/app/controllers/spree/errors_controller.rb +0 -11
  211. data/app/helpers/spree/mail_helper.rb +0 -29
  212. data/app/mailers/spree/base_mailer.rb +0 -46
  213. data/app/mailers/spree/order_mailer.rb +0 -26
  214. data/app/mailers/spree/reimbursement_mailer.rb +0 -12
  215. data/app/mailers/spree/shipment_mailer.rb +0 -12
  216. data/app/mailers/spree/test_mailer.rb +0 -8
  217. data/app/models/spree/validations/db_maximum_length_validator.rb +0 -22
  218. data/app/views/layouts/spree/base_mailer.html.erb +0 -46
  219. data/app/views/spree/errors/forbidden.html.erb +0 -0
  220. data/app/views/spree/errors/unauthorized.html.erb +0 -0
  221. data/app/views/spree/order_mailer/cancel_email.html.erb +0 -24
  222. data/app/views/spree/order_mailer/cancel_email.text.erb +0 -38
  223. data/app/views/spree/order_mailer/confirm_email.html.erb +0 -23
  224. data/app/views/spree/order_mailer/confirm_email.text.erb +0 -39
  225. data/app/views/spree/order_mailer/store_owner_notification_email.html.erb +0 -23
  226. data/app/views/spree/order_mailer/store_owner_notification_email.text.erb +0 -38
  227. data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +0 -56
  228. data/app/views/spree/reimbursement_mailer/reimbursement_email.text.erb +0 -24
  229. data/app/views/spree/shared/_base_mailer_footer.html.erb +0 -12
  230. data/app/views/spree/shared/_base_mailer_header.html.erb +0 -13
  231. data/app/views/spree/shared/_base_mailer_stylesheets.html.erb +0 -456
  232. data/app/views/spree/shared/_error_messages.html.erb +0 -11
  233. data/app/views/spree/shared/_mailer_line_item.html.erb +0 -16
  234. data/app/views/spree/shared/_paths.html.erb +0 -8
  235. data/app/views/spree/shared/_purchased_items_table.html.erb +0 -69
  236. data/app/views/spree/shared/purchased_items_table/_adjustment.html.erb +0 -13
  237. data/app/views/spree/shared/purchased_items_table/_line_item.html.erb +0 -27
  238. data/app/views/spree/shared/purchased_items_table/_subtotal.html.erb +0 -13
  239. data/app/views/spree/shared/purchased_items_table/_total.html.erb +0 -13
  240. data/app/views/spree/shipment_mailer/shipped_email.html.erb +0 -36
  241. data/app/views/spree/shipment_mailer/shipped_email.text.erb +0 -17
  242. data/app/views/spree/test_mailer/test_email.html.erb +0 -40
  243. data/app/views/spree/test_mailer/test_email.text.erb +0 -4
  244. data/config/initializers/assets.rb +0 -2
  245. data/config/initializers/premailer_assets.rb +0 -1
  246. data/config/initializers/premailer_rails.rb +0 -3
  247. data/db/migrate/20140805171219_make_existing_credit_cards_default.rb +0 -10
  248. data/lib/generators/spree/dummy/templates/initializers/bullet.rb +0 -5
  249. data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/backend/all.js +0 -15
  250. data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -16
  251. data/lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/backend/all.css +0 -16
  252. data/lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +0 -16
  253. data/lib/generators/spree/mailers_preview/mailers_preview_generator.rb +0 -23
  254. data/lib/generators/spree/mailers_preview/templates/mailers/previews/order_preview.rb +0 -13
  255. data/lib/generators/spree/mailers_preview/templates/mailers/previews/reimbursement_preview.rb +0 -5
  256. data/lib/generators/spree/mailers_preview/templates/mailers/previews/shipment_preview.rb +0 -5
  257. data/lib/generators/spree/mailers_preview/templates/mailers/previews/user_preview.rb +0 -11
  258. data/lib/tasks/email.rake +0 -10
  259. data/vendor/assets/javascripts/cleave.js +0 -1669
  260. data/vendor/assets/javascripts/fetch.umd.js +0 -531
  261. data/vendor/assets/javascripts/jquery.payment.js +0 -652
  262. data/vendor/assets/javascripts/jsuri.js +0 -458
  263. data/vendor/assets/javascripts/polyfill.min.js +0 -1
data/config/routes.rb CHANGED
@@ -1,6 +1 @@
1
- Spree::Core::Engine.add_routes do
2
- get '/forbidden', to: 'errors#forbidden', as: :forbidden
3
- get '/unauthorized', to: 'errors#unauthorized', as: :unauthorized
4
- end
5
-
6
1
  Spree::Core::Engine.draw_routes
@@ -0,0 +1,8 @@
1
+ class AddFilterableToSpreeProperties < ActiveRecord::Migration[5.2]
2
+ def change
3
+ unless column_exists?(:spree_properties, :filterable)
4
+ add_column :spree_properties, :filterable, :boolean, default: false, null: false
5
+ add_index :spree_properties, :filterable
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,16 @@
1
+ class CreateSpreeMenus < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :spree_menus do |t|
4
+ t.column :name, :string
5
+ t.column :location, :string
6
+ t.column :locale, :string
7
+
8
+ t.belongs_to :store
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :spree_menus, :locale
14
+ add_index :spree_menus, [:store_id, :location, :locale], unique: true
15
+ end
16
+ end
@@ -0,0 +1,31 @@
1
+ class CreateSpreeMenuItems < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :spree_menu_items do |t|
4
+ t.column :name, :string, null: false
5
+ t.column :subtitle, :string
6
+ t.column :destination, :string
7
+ t.column :new_window, :boolean, default: false
8
+ t.column :item_type, :string
9
+ t.column :linked_resource_type, :string, default: 'URL'
10
+ t.column :linked_resource_id, :integer
11
+ t.column :code, :string
12
+
13
+ t.column :parent_id, :integer
14
+ t.column :lft, :integer, null: false
15
+ t.column :rgt, :integer, null: false
16
+ t.column :depth, :integer, null: false, default: 0
17
+
18
+ t.belongs_to :menu
19
+
20
+ t.timestamps
21
+ end
22
+
23
+ add_index :spree_menu_items, :lft
24
+ add_index :spree_menu_items, :rgt
25
+ add_index :spree_menu_items, :depth
26
+ add_index :spree_menu_items, :parent_id
27
+ add_index :spree_menu_items, :item_type
28
+ add_index :spree_menu_items, :code
29
+ add_index :spree_menu_items, [:linked_resource_type, :linked_resource_id], name: 'index_spree_menu_items_on_linked_resource'
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ class AddFilterParamToSpreeProductProperties < ActiveRecord::Migration[5.2]
2
+ def change
3
+ unless column_exists?(:spree_product_properties, :filter_param)
4
+ add_column :spree_product_properties, :filter_param, :string
5
+ add_index :spree_product_properties, :filter_param
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class AddFilterParamToSpreeProperties < ActiveRecord::Migration[5.2]
2
+ def change
3
+ unless column_exists?(:spree_properties, :filter_param)
4
+ add_column :spree_properties, :filter_param, :string
5
+ add_index :spree_properties, :filter_param
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,24 @@
1
+ class CreateSpreeCmsPages < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :spree_cms_pages do |t|
4
+ t.column :title, :string, null: false
5
+ t.column :meta_title, :string
6
+ t.column :content, :text
7
+ t.column :meta_description, :text
8
+ t.column :visible, :boolean, default: true, index: true
9
+ t.column :slug, :string
10
+ t.column :type, :string
11
+ t.column :locale, :string
12
+ t.column :deleted_at, :datetime, index: true
13
+
14
+ t.belongs_to :store
15
+
16
+ t.timestamps
17
+ end
18
+
19
+ add_index :spree_cms_pages, [:slug, :store_id], unique: true
20
+ add_index :spree_cms_pages, [:slug, :store_id, :deleted_at]
21
+ add_index :spree_cms_pages, [:title, :type, :store_id]
22
+ add_index :spree_cms_pages, [:store_id, :locale, :type]
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ class CreateSpreeCmsSections < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :spree_cms_sections do |t|
4
+ t.column :name, :string, null: false
5
+ t.column :content, :text
6
+ t.column :settings, :text
7
+ t.column :fit, :string
8
+ t.column :destination, :string
9
+ t.column :type, :string
10
+ t.column :position, :integer
11
+
12
+ t.references :linked_resource, polymorphic: true, index: { name: 'index_spree_cms_sections_on_linked_resource' }
13
+
14
+ t.belongs_to :cms_page
15
+
16
+ t.timestamps
17
+ end
18
+
19
+ add_index :spree_cms_sections, :type
20
+ add_index :spree_cms_sections, :position
21
+ end
22
+ end
@@ -0,0 +1,36 @@
1
+ class CreateSpreeProductsStores < ActiveRecord::Migration[5.2]
2
+ def up
3
+ if table_exists?(:spree_products_stores)
4
+ unless index_exists?(:spree_products_stores, [:product_id, :store_id], unique: true)
5
+ add_index :spree_products_stores, [:product_id, :store_id], unique: true
6
+ end
7
+ unless column_exists?(:spree_products_stores, :created_at)
8
+ add_timestamps :spree_products_stores
9
+ end
10
+ else
11
+ create_table :spree_products_stores do |t|
12
+ t.references :product, index: true
13
+ t.references :store, index: true
14
+ t.timestamps
15
+
16
+ t.index [:product_id, :store_id], unique: true
17
+ end
18
+
19
+ stores = Spree::Store.all
20
+ product_ids = Spree::Product.with_deleted.order(:id).ids
21
+
22
+ if product_ids.any? && Spree::StoreProduct.respond_to?(:insert_all)
23
+ stores.find_each do |store|
24
+ records = product_ids.map { |product_id| { product_id: product_id, store_id: store.id } }
25
+
26
+ # Rails 5 does not have insert_all
27
+ Spree::StoreProduct.insert_all(records)
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ def down
34
+ drop_table :spree_products_stores
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ class EnsureStoreDefaultCountryIsSet < ActiveRecord::Migration[5.2]
2
+ def change
3
+ Spree::Store.find_each(&:save)
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ class AddMissingTimestampColumns < ActiveRecord::Migration[5.2]
2
+ def change
3
+ # Add missing created_at columns
4
+ %i[
5
+ spree_countries
6
+ spree_option_type_prototypes
7
+ spree_option_value_variants
8
+ spree_order_promotions
9
+ spree_product_promotion_rules
10
+ spree_products_taxons
11
+ spree_promotion_action_line_items
12
+ spree_promotion_actions
13
+ spree_promotion_rule_taxons
14
+ spree_promotion_rule_users
15
+ spree_property_prototypes
16
+ spree_prototype_taxons
17
+ spree_reimbursement_credits
18
+ spree_role_users
19
+ spree_roles
20
+ spree_shipping_method_zones
21
+ spree_states
22
+ ].each do |table|
23
+ add_column table, :created_at, :datetime unless column_exists?(table, :created_at)
24
+ end
25
+ # Add missing updated_at columns
26
+ %i[
27
+ spree_option_type_prototypes
28
+ spree_option_value_variants
29
+ spree_order_promotions
30
+ spree_product_promotion_rules
31
+ spree_products_taxons
32
+ spree_promotion_action_line_items
33
+ spree_promotion_actions
34
+ spree_promotion_rule_taxons
35
+ spree_promotion_rule_users
36
+ spree_property_prototypes
37
+ spree_prototype_taxons
38
+ spree_reimbursement_credits
39
+ spree_role_users
40
+ spree_roles
41
+ spree_shipping_method_zones
42
+ ].each do |table|
43
+ add_column table, :updated_at, :datetime unless column_exists?(table, :updated_at)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,29 @@
1
+ class AddUniqueIndexOnPropertyIdAndProductIdToProductProperties < ActiveRecord::Migration[5.2]
2
+ def up
3
+ klass = Spree::ProductProperty
4
+ columns = %w[property_id product_id]
5
+
6
+ unless index_exists?(klass.table_name, columns)
7
+ scope = klass.unscoped
8
+
9
+ say "Find duplicate #{klass} records"
10
+ duplicates = scope.
11
+ select((columns + %w[COUNT(*)]).join(',')).
12
+ group("#{columns.join(',')}").
13
+ having('COUNT(*) > 1').
14
+ map { |row| row.attributes.slice(*columns) }
15
+
16
+ say "Delete all but the oldest duplicate #{klass} record"
17
+ duplicates.each do |conditions|
18
+ scope.where(conditions).order(:created_at).drop(1).each(&:destroy)
19
+ end
20
+
21
+ say "Add unique index to #{klass.table_name} for #{columns.inspect}"
22
+ add_index klass.table_name, columns, unique: true
23
+ end
24
+ end
25
+
26
+ def down
27
+ remove_index :spree_product_properties, [:property_id, :product_id]
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ class AddStoreIdToSpreeStoreCredits < ActiveRecord::Migration[5.2]
2
+ def change
3
+ unless column_exists?(:spree_store_credits, :store_id)
4
+ add_column :spree_store_credits, :store_id, :bigint
5
+ add_index :spree_store_credits, :store_id
6
+ Spree::StoreCredit.reset_column_information
7
+ Spree::StoreCredit.update_all(store_id: Spree::Store.default.id)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ class AddStoreIdToSpreeTaxonomies < ActiveRecord::Migration[5.2]
2
+ def change
3
+ unless column_exists?(:spree_taxonomies, :store_id)
4
+ add_column :spree_taxonomies, :store_id, :bigint
5
+ add_index :spree_taxonomies, :store_id
6
+ add_index :spree_taxonomies, [:name, :store_id], unique: true
7
+ Spree::Taxonomy.reset_column_information
8
+ Spree::Taxonomy.update_all(store_id: Spree::Store.default.id)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ class AddIndexOnNameParentIdAndTaxonomyIdOnSpreeTaxons < ActiveRecord::Migration[5.2]
2
+ def up
3
+ klass = Spree::Taxon
4
+ columns = %w[name parent_id taxonomy_id]
5
+
6
+ unless index_exists?(klass.table_name, columns)
7
+ remove_index klass.table_name, columns if index_exists?(klass.table_name, columns)
8
+
9
+ say "Find duplicate #{klass} records"
10
+ duplicates = klass.
11
+ select((columns + %w[COUNT(*)]).join(',')).
12
+ group("#{columns.join(',')}").
13
+ having('COUNT(*) > 1').
14
+ map { |row| row.attributes.slice(*columns) }
15
+
16
+ say "Delete all but the oldest duplicate #{klass} record"
17
+ duplicates.each do |conditions|
18
+ klass.where(conditions).order(:created_at).drop(1).each(&:destroy)
19
+ end
20
+
21
+ duplicates.each do |conditions| puts klass.where(conditions).order(:created_at).drop(1) end
22
+
23
+ say "Add unique index to #{klass.table_name} for #{columns.inspect}"
24
+ add_index klass.table_name, columns, unique: true
25
+ end
26
+ end
27
+
28
+ def down
29
+ remove_index :spree_taxons, [:name, :parent_id, :taxonomy_id]
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ class AddIndexOnPermalinkParentIdAndTaxonomyIdOnSpreeTaxons < ActiveRecord::Migration[5.2]
2
+ def up
3
+ klass = Spree::Taxon
4
+ columns = %w[permalink parent_id taxonomy_id]
5
+
6
+ unless index_exists?(klass.table_name, columns)
7
+ remove_index klass.table_name, columns if index_exists?(klass.table_name, columns)
8
+
9
+ say "Find duplicate #{klass} records"
10
+ duplicates = klass.
11
+ select((columns + %w[COUNT(*)]).join(',')).
12
+ group("#{columns.join(',')}").
13
+ having('COUNT(*) > 1').
14
+ map { |row| row.attributes.slice(*columns) }
15
+
16
+ say "Delete all but the oldest duplicate #{klass} record"
17
+ duplicates.each do |conditions|
18
+ klass.where(conditions).order(:created_at).drop(1).each(&:destroy)
19
+ end
20
+
21
+ duplicates.each do |conditions| puts klass.where(conditions).order(:created_at).drop(1) end
22
+
23
+ say "Add unique index to #{klass.table_name} for #{columns.inspect}"
24
+ add_index klass.table_name, columns, unique: true
25
+ end
26
+ end
27
+
28
+ def down
29
+ remove_index :spree_taxons, [:permalink, :parent_id, :taxonomy_id]
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ class CreateSpreePromotionsStores < ActiveRecord::Migration[5.2]
2
+ def up
3
+ unless table_exists?(:spree_promotions_stores)
4
+ create_table :spree_promotions_stores do |t|
5
+ t.references :promotion, index: true
6
+ t.references :store, index: true
7
+ t.timestamps
8
+
9
+ t.index [:promotion_id, :store_id], unique: true
10
+ end
11
+
12
+ stores = Spree::Store.all
13
+ promotion_ids = Spree::Promotion.order(:id).ids
14
+
15
+ stores.find_each do |store|
16
+ prepared_values = promotion_ids.map { |id| "(#{id}, #{store.id}, '#{Time.current.to_s(:db)}', '#{Time.current.to_s(:db)}')" }.join(', ')
17
+ next if prepared_values.empty?
18
+
19
+ begin
20
+ execute "INSERT INTO spree_promotions_stores (promotion_id, store_id, created_at, updated_at) VALUES #{prepared_values};"
21
+ rescue ActiveRecord::RecordNotUnique; end
22
+ end
23
+ end
24
+ end
25
+
26
+ def down
27
+ drop_table :spree_promotions_stores
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ class AddStoreIdToSpreeCustomerReturns < ActiveRecord::Migration[5.2]
2
+ def change
3
+ unless column_exists?(:spree_customer_returns, :store_id)
4
+ add_column :spree_customer_returns, :store_id, :bigint
5
+ add_index :spree_customer_returns, :store_id
6
+ Spree::CustomerReturn.reset_column_information
7
+ default_store_id = Spree::Store.default.id
8
+ Spree::CustomerReturn.find_each { |cr| cr.update_column(:store_id, cr.order&.store_id || default_store_id) }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,305 @@
1
+ class ChangeIntegerIdColumnsIntoBigint < ActiveRecord::Migration[5.2]
2
+ def change
3
+ change_table(:active_storage_attachments) do |t|
4
+ t.change :record_id, :bigint
5
+ t.change :blob_id, :bigint
6
+ end
7
+
8
+ change_column :friendly_id_slugs, :sluggable_id, :bigint
9
+
10
+ change_table(:spree_addresses) do |t|
11
+ t.change :state_id, :bigint
12
+ t.change :country_id, :bigint
13
+ t.change :user_id, :bigint
14
+ end
15
+
16
+ change_table(:spree_adjustments) do |t|
17
+ t.change :source_id, :bigint
18
+ t.change :adjustable_id, :bigint
19
+ t.change :order_id, :bigint
20
+ end
21
+
22
+ change_column :spree_assets, :viewable_id, :bigint
23
+
24
+ change_column :spree_calculators, :calculable_id, :bigint
25
+
26
+ change_table(:spree_credit_cards) do |t|
27
+ t.change :address_id, :bigint
28
+ t.change :user_id, :bigint
29
+ t.change :payment_method_id, :bigint
30
+ end
31
+
32
+ change_column :spree_customer_returns, :stock_location_id, :bigint
33
+
34
+ change_table(:spree_inventory_units) do |t|
35
+ t.change :variant_id, :bigint
36
+ t.change :order_id, :bigint
37
+ t.change :shipment_id, :bigint
38
+ t.change :line_item_id, :bigint
39
+ t.change :original_return_item_id, :bigint
40
+ end
41
+
42
+ change_table(:spree_line_items) do |t|
43
+ t.change :variant_id, :bigint
44
+ t.change :order_id, :bigint
45
+ t.change :tax_category_id, :bigint
46
+ end
47
+
48
+ change_column :spree_log_entries, :source_id, :bigint
49
+
50
+ change_table(:spree_menu_items) do |t|
51
+ t.change :linked_resource_id, :bigint
52
+ t.change :parent_id, :bigint
53
+ t.change :lft, :bigint
54
+ t.change :rgt, :bigint
55
+ t.change :menu_id, :bigint
56
+ end
57
+
58
+ change_column :spree_menus, :store_id, :bigint
59
+
60
+ change_table(:spree_option_type_prototypes) do |t|
61
+ t.change :prototype_id, :bigint
62
+ t.change :option_type_id, :bigint
63
+ end
64
+
65
+ change_table(:spree_option_value_variants) do |t|
66
+ t.change :variant_id, :bigint
67
+ t.change :option_value_id, :bigint
68
+ end
69
+
70
+ change_column :spree_option_values, :option_type_id, :bigint
71
+
72
+ change_table(:spree_order_promotions) do |t|
73
+ t.change :order_id, :bigint
74
+ t.change :promotion_id, :bigint
75
+ end
76
+
77
+ change_table(:spree_orders) do |t|
78
+ t.change :user_id, :bigint
79
+ t.change :bill_address_id, :bigint
80
+ t.change :ship_address_id, :bigint
81
+ t.change :created_by_id, :bigint
82
+ t.change :approver_id, :bigint
83
+ t.change :canceler_id, :bigint
84
+ t.change :store_id, :bigint
85
+ end
86
+
87
+ change_column :spree_payment_capture_events, :payment_id, :bigint
88
+
89
+ change_table(:spree_payment_methods_stores) do |t|
90
+ t.change :payment_method_id, :bigint
91
+ t.change :store_id, :bigint
92
+ end
93
+
94
+ change_table(:spree_payments) do |t|
95
+ t.change :order_id, :bigint
96
+ t.change :source_id, :bigint
97
+ t.change :payment_method_id, :bigint
98
+ end
99
+
100
+ change_column :spree_prices, :variant_id, :bigint
101
+
102
+ change_table(:spree_product_option_types) do |t|
103
+ t.change :product_id, :bigint
104
+ t.change :option_type_id, :bigint
105
+ end
106
+
107
+ change_table(:spree_product_promotion_rules) do |t|
108
+ t.change :product_id, :bigint
109
+ t.change :promotion_rule_id, :bigint
110
+ end
111
+
112
+ change_table(:spree_product_properties) do |t|
113
+ t.change :product_id, :bigint
114
+ t.change :property_id, :bigint
115
+ end
116
+
117
+ change_table(:spree_products) do |t|
118
+ t.change :tax_category_id, :bigint
119
+ t.change :shipping_category_id, :bigint
120
+ end
121
+
122
+ change_table(:spree_products_stores) do |t|
123
+ t.change :product_id, :bigint
124
+ t.change :store_id, :bigint
125
+ end
126
+
127
+ change_table(:spree_products_taxons) do |t|
128
+ t.change :product_id, :bigint
129
+ t.change :taxon_id, :bigint
130
+ end
131
+
132
+ change_table(:spree_promotion_action_line_items) do |t|
133
+ t.change :promotion_action_id, :bigint
134
+ t.change :variant_id, :bigint
135
+ end
136
+
137
+ change_column :spree_promotion_actions, :promotion_id, :bigint
138
+
139
+ change_table(:spree_promotion_rule_taxons) do |t|
140
+ t.change :taxon_id, :bigint
141
+ t.change :promotion_rule_id, :bigint
142
+ end
143
+
144
+ change_table(:spree_promotion_rule_users) do |t|
145
+ t.change :user_id, :bigint
146
+ t.change :promotion_rule_id, :bigint
147
+ end
148
+
149
+ change_table(:spree_promotion_rules) do |t|
150
+ t.change :promotion_id, :bigint
151
+ t.change :user_id, :bigint
152
+ t.change :product_group_id, :bigint
153
+ end
154
+
155
+ change_column :spree_promotions, :promotion_category_id, :bigint
156
+
157
+ change_table(:spree_promotions_stores) do |t|
158
+ t.change :promotion_id, :bigint
159
+ t.change :store_id, :bigint
160
+ end
161
+
162
+ change_table(:spree_property_prototypes) do |t|
163
+ t.change :prototype_id, :bigint
164
+ t.change :property_id, :bigint
165
+ end
166
+
167
+ change_table(:spree_prototype_taxons) do |t|
168
+ t.change :taxon_id, :bigint
169
+ t.change :prototype_id, :bigint
170
+ end
171
+
172
+ change_table(:spree_refunds) do |t|
173
+ t.change :payment_id, :bigint
174
+ t.change :refund_reason_id, :bigint
175
+ t.change :reimbursement_id, :bigint
176
+ end
177
+
178
+ change_table(:spree_reimbursement_credits) do |t|
179
+ t.change :reimbursement_id, :bigint
180
+ t.change :creditable_id, :bigint
181
+ end
182
+
183
+ change_table(:spree_reimbursements) do |t|
184
+ t.change :customer_return_id, :bigint
185
+ t.change :order_id, :bigint
186
+ end
187
+
188
+ change_table(:spree_return_authorizations) do |t|
189
+ t.change :order_id, :bigint
190
+ t.change :stock_location_id, :bigint
191
+ t.change :return_authorization_reason_id, :bigint
192
+ end
193
+
194
+ change_table(:spree_return_items) do |t|
195
+ t.change :return_authorization_id, :bigint
196
+ t.change :inventory_unit_id, :bigint
197
+ t.change :exchange_variant_id, :bigint
198
+ t.change :customer_return_id, :bigint
199
+ t.change :reimbursement_id, :bigint
200
+ t.change :preferred_reimbursement_type_id, :bigint
201
+ t.change :override_reimbursement_type_id, :bigint
202
+ end
203
+
204
+ change_table(:spree_role_users) do |t|
205
+ t.change :role_id, :bigint
206
+ t.change :user_id, :bigint
207
+ end
208
+
209
+ change_table(:spree_shipments) do |t|
210
+ t.change :order_id, :bigint
211
+ t.change :address_id, :bigint
212
+ t.change :stock_location_id, :bigint
213
+ end
214
+
215
+ change_table(:spree_shipping_method_categories) do |t|
216
+ t.change :shipping_method_id, :bigint
217
+ t.change :shipping_category_id, :bigint
218
+ end
219
+
220
+ change_table(:spree_shipping_method_zones) do |t|
221
+ t.change :shipping_method_id, :bigint
222
+ t.change :zone_id, :bigint
223
+ end
224
+
225
+ change_column :spree_shipping_methods, :tax_category_id, :bigint
226
+
227
+ change_table(:spree_shipping_rates) do |t|
228
+ t.change :shipment_id, :bigint
229
+ t.change :shipping_method_id, :bigint
230
+ t.change :tax_rate_id, :bigint
231
+ end
232
+
233
+ change_table(:spree_state_changes) do |t|
234
+ t.change :stateful_id, :bigint
235
+ t.change :user_id, :bigint
236
+ end
237
+
238
+ change_column :spree_states, :country_id, :bigint
239
+
240
+ change_table(:spree_stock_items) do |t|
241
+ t.change :stock_location_id, :bigint
242
+ t.change :variant_id, :bigint
243
+ end
244
+
245
+ change_table(:spree_stock_locations) do |t|
246
+ t.change :state_id, :bigint
247
+ t.change :country_id, :bigint
248
+ end
249
+
250
+ change_table(:spree_stock_movements) do |t|
251
+ t.change :stock_item_id, :bigint
252
+ t.change :originator_id, :bigint
253
+ end
254
+
255
+ change_table(:spree_stock_transfers) do |t|
256
+ t.change :source_location_id, :bigint
257
+ t.change :destination_location_id, :bigint
258
+ end
259
+
260
+ change_table(:spree_store_credit_events) do |t|
261
+ t.change :store_credit_id, :bigint
262
+ t.change :originator_id, :bigint
263
+ end
264
+
265
+ change_table(:spree_store_credits) do |t|
266
+ t.change :user_id, :bigint
267
+ t.change :category_id, :bigint
268
+ t.change :created_by_id, :bigint
269
+ t.change :originator_id, :bigint
270
+ t.change :type_id, :bigint
271
+ end
272
+
273
+ change_table(:spree_stores) do |t|
274
+ t.change :default_country_id, :bigint
275
+ t.change :checkout_zone_id, :bigint
276
+ end
277
+
278
+ change_table(:spree_tax_rates) do |t|
279
+ t.change :zone_id, :bigint
280
+ t.change :tax_category_id, :bigint
281
+ end
282
+
283
+ change_table(:spree_taxons) do |t|
284
+ t.change :parent_id, :bigint
285
+ t.change :taxonomy_id, :bigint
286
+ t.change :lft, :bigint
287
+ t.change :rgt, :bigint
288
+ end
289
+
290
+ change_table(:spree_users) do |t|
291
+ t.change :ship_address_id, :bigint
292
+ t.change :bill_address_id, :bigint
293
+ end
294
+
295
+ change_table(:spree_variants) do |t|
296
+ t.change :product_id, :bigint
297
+ t.change :tax_category_id, :bigint
298
+ end
299
+
300
+ change_table(:spree_zone_members) do |t|
301
+ t.change :zoneable_id, :bigint
302
+ t.change :zone_id, :bigint
303
+ end
304
+ end
305
+ end