spree/spree — pull request #5046 by mtuckergd (2014-07-24 04:28:44+00:00)
Title: migrataion to copy current product slug values into slug history table

Per request from https://github.com/spree/spree/pull/5021.

This copies current slug values into slug history table. Slugs are only copied into this table by FriendlyId gem when changed, and then only the new value is set in the table (seems to me should be old value since history table is a fallback), so this migration ensures all current values can serve as a fallback when slugs are changed. This effectively enables immediate slug history tracking upon migration.

I did this as a sql migration, rather than AR syntax, to ensure that large product tables would not slow down migration significantly.
Alternate, AR-syntax implementation would have looked something like this:
```
Spree::Product.select(:id, :slug).where.not(slug: nil).order_by(:id).find_each do |p|
FriendlyId::Slug.create!(slug: p.slug, sluggable_id: p.id, sluggable_type: p.class.to_s)
end
```
The AR implementation has the major downside of eventually loading every product record into memory. Since recent discussions have suggested product tables with records in the millions (due to paranoid deletion), the SQL approach seems safer.