Skip to content

Instantly share code, notes, and snippets.

@dsadaka
Created November 29, 2020 22:50
Show Gist options
  • Save dsadaka/5b5d0d3c08cf7431b3670e51acd66844 to your computer and use it in GitHub Desktop.
Save dsadaka/5b5d0d3c08cf7431b3670e51acd66844 to your computer and use it in GitHub Desktop.
Output from Spree 3.1 migrations
Warning: This migration changes the meaning of 'deleted'. Before this change, 'deleted' meant products that were no longer being sold in your store. After this change, you can only delete a product or variant if it has not already been sold to a customer (a model-level check enforces this). Instead, you should use the new field 'discontinue_on' for products or variants which were sold in the past but no longer for sale. This fixes bugs when other objects are attached to deleted products and variants. (Even though acts_as_paranoid gem keeps the records in the database, most associations are automatically scoped to exclude the deleted records.) In thew meaning of 'deleted,' you can still use the delete function on products & variants which are *truly user-error mistakes*, specifically before an order has been placed or the items have gone on sale. You also must use the soft-delete function (which still works after this change) to clean up slug (product) and SKU (variant) duplicates. Otherwise, you should generally over ever need to discontinue products.
Data Fix: We will attempt to reverse engineer the old meaning of 'deleted' (no longer for sale) to the new database field 'discontinue_on'. However, since Slugs and SKUs cannot be duplicated on Products and Variants, we cannot gaurantee this to be foolproof if you have deteled Products and Variants that have duplicate Slugs or SKUs in non-deleted records. In these cases, we recommend you use the additional rake task to clean up your old records (see rake db:fix_orphan_line_items). If you have such records, this migration will leave them in place, preferring the non-deleted records over the deleted ones. However, since old line items will still be associated with deleted objects, you will still the bugs in your app until you run:
rake db:fix_orphan_line_items
We will print out a report of the data we are fixing now:
recovering deleted product id 2 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 3982 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 10 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 8 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 9 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 11 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 12 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 13 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 14 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 15 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 16 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 17 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 18 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 20 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 19 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 21 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 22 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 23 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 24 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 25 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 26 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 27 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 1 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 4903 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 3947 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 3948 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 3949 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 3950 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 3943 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 3944 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 3945 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 3946 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 4994 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 4995 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 4996 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 4997 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 3952 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 3953 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 3954 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 3955 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 5029 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 3956 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 3782 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 4998 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 4800 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 4801 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 4802 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 4803 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 4804 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 4990 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 4991 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 4992 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 4993 ... this will un-delete the record and set it to be discontinued
recovering deleted product id 3935 ... this will un-delete the record and set it to be discontinued
leaving variant id 2 deleted because there are no line items attached to it...
leaving variant id 3982 deleted because there is a duplicate SKU for '9284-BLACK' (variant id 5070)
leaving variant id 10 deleted because there is a duplicate SKU for '*' (variant id 4872)
leaving variant id 8 deleted because there is a duplicate SKU for '#' (variant id 4870)
leaving variant id 9 deleted because there is a duplicate SKU for '#NOTE' (variant id 4871)
leaving variant id 11 deleted because there is a duplicate SKU for '0001AA' (variant id 4873)
leaving variant id 12 deleted because there is a duplicate SKU for '0001AB' (variant id 4874)
leaving variant id 13 deleted because there is a duplicate SKU for '0001AC' (variant id 4875)
leaving variant id 14 deleted because there is a duplicate SKU for '0001AD' (variant id 4876)
leaving variant id 15 deleted because there is a duplicate SKU for '0001AE' (variant id 4877)
leaving variant id 16 deleted because there is a duplicate SKU for '0001AF' (variant id 4878)
leaving variant id 17 deleted because there is a duplicate SKU for '0001AG' (variant id 4879)
leaving variant id 18 deleted because there is a duplicate SKU for '0001AH' (variant id 4880)
leaving variant id 20 deleted because there is a duplicate SKU for '0001AK' (variant id 4882)
leaving variant id 19 deleted because there is a duplicate SKU for '0001AJ' (variant id 4881)
leaving variant id 21 deleted because there is a duplicate SKU for '0001AL' (variant id 4883)
leaving variant id 22 deleted because there is a duplicate SKU for '0001AM' (variant id 4884)
leaving variant id 23 deleted because there is a duplicate SKU for '0001AN' (variant id 4885)
leaving variant id 24 deleted because there is a duplicate SKU for '0001AP' (variant id 4886)
leaving variant id 25 deleted because there is a duplicate SKU for '0001AQ' (variant id 4887)
leaving variant id 26 deleted because there is a duplicate SKU for '0001AR' (variant id 4888)
leaving variant id 27 deleted because there is a duplicate SKU for '0002AA' (variant id 4889)
leaving variant id 1 deleted because there are no line items attached to it...
leaving variant id 4904 deleted because there is a duplicate SKU for '9284-BLACK' (variant id 5070)
leaving variant id 3947 deleted because there is a duplicate SKU for '9247 LARGE' (variant id 5032)
leaving variant id 3948 deleted because there is a duplicate SKU for '9247 MEDIUM' (variant id 5033)
leaving variant id 3949 deleted because there is a duplicate SKU for '9247 SMALL' (variant id 5034)
leaving variant id 3950 deleted because there is a duplicate SKU for '9247 XLARGE' (variant id 5035)
leaving variant id 3943 deleted because there is a duplicate SKU for '9246 LARGE' (variant id 5056)
leaving variant id 3944 deleted because there is a duplicate SKU for '9246 MEDIUM' (variant id 5057)
leaving variant id 3945 deleted because there is a duplicate SKU for '9246 SMALL' (variant id 5058)
leaving variant id 3946 deleted because there is a duplicate SKU for '9246 XLARGE' (variant id 5059)
leaving variant id 4995 deleted because there is a duplicate SKU for '9247 LARGE' (variant id 5032)
leaving variant id 4996 deleted because there is a duplicate SKU for '9247 MEDIUM' (variant id 5033)
leaving variant id 4997 deleted because there is a duplicate SKU for '9247 SMALL' (variant id 5034)
leaving variant id 4998 deleted because there is a duplicate SKU for '9247 XLARGE' (variant id 5035)
leaving variant id 3952 deleted because there is a duplicate SKU for '9249 LARGE' (variant id 5036)
leaving variant id 3953 deleted because there is a duplicate SKU for '9249 MEDIUM' (variant id 5037)
leaving variant id 3954 deleted because there is a duplicate SKU for '9249 NO EMBLEM' (variant id 5038)
leaving variant id 3955 deleted because there is a duplicate SKU for '9249 SMALL' (variant id 5039)
leaving variant id 5030 deleted because there are no line items attached to it...
leaving variant id 3956 deleted because there is a duplicate SKU for '9249 XLARGE' (variant id 5040)
leaving variant id 3782 deleted because there is a duplicate SKU for '8523' (variant id 5055)
leaving variant id 4999 deleted because there is a duplicate SKU for '9284-BLACK' (variant id 5070)
leaving variant id 4800 deleted because there is a duplicate SKU for '9921 LARGE' (variant id 5072)
leaving variant id 4801 deleted because there is a duplicate SKU for '9921 MEDIUM' (variant id 5073)
leaving variant id 4802 deleted because there is a duplicate SKU for '9921 SMALL' (variant id 5074)
leaving variant id 4803 deleted because there is a duplicate SKU for '9921 XLARGE' (variant id 5075)
leaving variant id 4804 deleted because there is a duplicate SKU for '9921 XXLARGE' (variant id 5076)
leaving variant id 4991 deleted because there is a duplicate SKU for '9246 LARGE' (variant id 5056)
leaving variant id 4992 deleted because there is a duplicate SKU for '9246 MEDIUM' (variant id 5057)
leaving variant id 4993 deleted because there is a duplicate SKU for '9246 SMALL' (variant id 5058)
leaving variant id 4994 deleted because there is a duplicate SKU for '9246 XLARGE' (variant id 5059)
leaving variant id 3935 deleted because there is a duplicate SKU for '9227' (variant id 5086)
WARNING: You may still have bugs with variant id 3935 (9227) until you run rake db:fix_orphan_line_items
== 20170123172272 AddDiscontinuedToProductsAndVariants: migrated (0.7273s) ====
== 20170123172273 RemoveShippingMethodIdFromSpreeOrders: migrating ============
-- column_exists?(:spree_orders, :shipping_method_id, :integer)
-> 0.0017s
-- remove_column(:spree_orders, :shipping_method_id, :integer)
-> 0.1328s
== 20170123172273 RemoveShippingMethodIdFromSpreeOrders: migrated (0.1346s) ===
== 20170123172274 AddIdColumnToEarlierHabtmTables: migrating ==================
-- add_column(:spree_option_type_prototypes, :id, :primary_key)
-> 0.0208s
-- add_column(:spree_option_value_variants, :id, :primary_key)
-> 0.0141s
-- add_column(:spree_order_promotions, :id, :primary_key)
-> 0.1091s
-- add_column(:spree_product_promotion_rules, :id, :primary_key)
-> 0.0136s
-- add_column(:spree_promotion_rule_users, :id, :primary_key)
-> 0.0135s
-- add_column(:spree_property_prototypes, :id, :primary_key)
-> 0.0115s
-- add_column(:spree_role_users, :id, :primary_key)
-> 0.1040s
-- add_column(:spree_shipping_method_zones, :id, :primary_key)
-> 0.1061s
== 20170123172274 AddIdColumnToEarlierHabtmTables: migrated (0.3931s) =========
== 20170123172275 AddIndexes: migrating =======================================
-- add_index(:spree_assets, :position)
-> 0.0239s
-- add_index(:spree_option_types, :name)
-> 0.0139s
-- add_index(:spree_option_values, :name)
-> 0.0108s
-- add_index(:spree_prices, :variant_id)
-> 0.0250s
-- add_index(:spree_properties, :name)
-> 0.0227s
-- add_index(:spree_roles, :name)
-> 0.0160s
-- add_index(:spree_shipping_categories, :name)
-> 0.0191s
-- add_index(:spree_taxons, :lft)
-> 0.0141s
-- add_index(:spree_taxons, :rgt)
-> 0.0201s
-- add_index(:spree_taxons, :name)
-> 0.0201s
== 20170123172275 AddIndexes: migrated (0.1864s) ==============================
== 20170123172276 AddMissingIndicesOnUser: migrating ==========================
-- index_name(:spree_users, {:column=>["bill_address_id"]})
-> 0.0000s
-- index_exists?(:spree_users, :bill_address_id, {:name=>"index_spree_users_on_bill_address_id"})
-> 0.0136s
-- add_index(:spree_users, :bill_address_id)
-> 0.0262s
-- index_name(:spree_users, {:column=>["ship_address_id"]})
-> 0.0000s
-- index_exists?(:spree_users, :ship_address_id, {:name=>"index_spree_users_on_ship_address_id"})
-> 0.0004s
-- add_index(:spree_users, :ship_address_id)
-> 0.0157s
== 20170123172276 AddMissingIndicesOnUser: migrated (0.0564s) =================
== 20170123172277 AddInvoiceDetailsToSpreeOrders: migrating ===================
-- add_column(:spree_orders, :invoice_number, :integer)
-> 0.1050s
-- add_column(:spree_orders, :invoice_date, :date)
-> 0.1137s
== 20170123172277 AddInvoiceDetailsToSpreeOrders: migrated (0.2188s) ==========
== 20170123172278 RemoveInvoiceDateColumn: migrating ==========================
-- remove_column(:spree_orders, :invoice_date, :date)
-> 0.1248s
== 20170123172278 RemoveInvoiceDateColumn: migrated (0.1248s) =================
== 20170123172279 CreateSpreeBookkeepingDocuments: migrating ==================
-- create_table(:spree_bookkeeping_documents, {})
-> 0.0129s
-- remove_column(:spree_orders, :invoice_number, :string)
-> 0.1216s
== 20170123172279 CreateSpreeBookkeepingDocuments: migrated (0.1365s) =========
== 20180227163413 AddWebDescToProducts: migrating =============================
-- add_column(:spree_products, :web_description, :text)
-> 0.1820s
-- add_column(:spree_products, :web_title, :string)
-> 0.1650s
== 20180227163413 AddWebDescToProducts: migrated (0.3471s) ====================
== 20201129224444 RemoveCounterCacheFromSpreeVariantsToSpreeStockItems: migrating
-- column_exists?(:spree_variants, :stock_items_count)
-> 0.0010s
-- remove_column(:spree_variants, :stock_items_count)
-> 0.2540s
== 20201129224444 RemoveCounterCacheFromSpreeVariantsToSpreeStockItems: migrated (0.2550s)
== 20201129224445 ActsAsTaggableOnSpreeMigration: migrating ===================
-- create_table(:spree_tags, {})
-> 0.0183s
-- create_table(:spree_taggings, {})
-> 0.0121s
-- add_index(:spree_tags, :name, {:unique=>true})
-> 0.0121s
-- add_index(:spree_taggings, [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], {:unique=>true, :name=>"spree_taggings_idx"})
-> 0.0099s
== 20201129224445 ActsAsTaggableOnSpreeMigration: migrated (0.0528s) ==========
== 20201129224446 ChangeCollationForSpreeTagNames: migrating ==================
-- execute("ALTER TABLE spree_tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
-> 0.0235s
== 20201129224446 ChangeCollationForSpreeTagNames: migrated (0.0236s) =========
== 20201129224447 AddMissingIndexesToSpreeTaggings: migrating =================
-- add_index(:spree_taggings, :tag_id)
-> 0.0135s
-- add_index(:spree_taggings, :taggable_id)
-> 0.0111s
-- add_index(:spree_taggings, :taggable_type)
-> 0.0117s
-- add_index(:spree_taggings, :tagger_id)
-> 0.0105s
-- add_index(:spree_taggings, :context)
-> 0.0109s
-- add_index(:spree_taggings, [:tagger_id, :tagger_type])
-> 0.0114s
-- add_index(:spree_taggings, [:taggable_id, :taggable_type, :tagger_id, :context], {:name=>"spree_taggings_idy"})
-> 0.0106s
== 20201129224447 AddMissingIndexesToSpreeTaggings: migrated (0.0801s) ========
== 20201129224448 AddZipcodeRequiredToSpreeCountries: migrating ===============
-- add_column(:spree_countries, :zipcode_required, :boolean, {:default=>true})
-> 0.1218s
== 20201129224448 AddZipcodeRequiredToSpreeCountries: migrated (0.1327s) ======
== 20201129224449 AddCreatedAtToVariant: migrating ============================
-- add_column(:spree_variants, :created_at, :datetime)
-> 0.1765s
== 20201129224449 AddCreatedAtToVariant: migrated (0.3263s) ===================
== 20201129224450 AddNullFalseToSpreeVariantsTimestamps: migrating ============
-- change_column_null(:spree_variants, :created_at, false)
-> 0.1863s
-- change_column_null(:spree_variants, :updated_at, false)
-> 0.1606s
== 20201129224450 AddNullFalseToSpreeVariantsTimestamps: migrated (0.3471s) ===
➋➂ Dans-MacBook-Pro-3:bayspree dsadaka$ rake db:fix_orphan_line_items
{:styles=>{:mini=>"32x32>", :normal=>"128x128>"}, :default_style=>:mini, :url=>"/taxons/:id/:style/:basename.:extension", :path=>"/taxons/:id/:style/:basename.:extension", :default_url=>""}
WARNING: This task will re-associate any line_items associated with deleted variants to non-deleted variants with matching SKUs. Because other attributes and product associations may switch during the re-association, this may have unintended side-effects. If this task finishes successfully, line items for old order should no longer be orphaned from their varaints. You should run this task after you have already run the db migratoin AddDiscontinuedToProductsAndVariants. If the db migration did not warn you that it was leaving deleted records in place because of duplicate SKUs, then you do not need to run this rake task.
Are you sure you want to continue? (Y/n):
looping through all your deleted variants ...
Ready to fix...
Changing all line items for 9227 variant id 3935 (deleted) to variant id 5086 (not deleted) ...
DONE ! Your database should no longer have line items that are associated with deleted variants.
➋➂ Dans-MacBook-Pro-3:bayspree dsadaka$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment