Skip to content

Upgrading from FriendlyId 4.0

Guillaume Hain edited this page Oct 4, 2017 · 1 revision

Run rails generate friendly_id --skip-migration and edit the initializer generated in config/initializers/friendly_id.rb. This file contains notes describing how to restore (or not) some of the defaults from FriendlyId 4.0.

If you want to use the :history and :scoped addons together, you must add a :scope column to your friendly_id_slugs table and replace the unique index on :slug and :sluggable_type with a unique index on those two columns, plus the new :scope column.

A migration like this should be sufficient:

add_column   :friendly_id_slugs, :scope, :string
remove_index :friendly_id_slugs, [:slug, :sluggable_type]
add_index    :friendly_id_slugs, [:slug, :sluggable_type]
add_index    :friendly_id_slugs, [:slug, :sluggable_type, :scope], unique: true
Clone this wiki locally