Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Migration from Automatic Foreign Key

mlomnicki edited this page Aug 2, 2011 · 1 revision

If you're migrating from automatic foreign key you have to slightly change the initializer.

  1. Go to config/initializers
  2. Rename automatic_foreign_key.rb to schema_plus.rb
  3. Open schema_plus.rb in your favorite editor(TM).
  4. Change AutomaticForeignKey.setup to SchemaPlus.config
  5. open schema_plus.rb and change config.on_delete to config.foreign_keys.on_delete, config.auto_index to config.foreign_keys.auto_index and so on.

Let's say your automatic_foreign_key initializer looks like

    AutomaticForeignKey.setup do |config|
      config.on_delete = :cascade
      config.on_update = :cascade
      config.auto_index = true
    end

After the migration it should become:

    SchemaPlus.config do |config|
      config.foreign_keys.on_delete = :cascade
      config.foreign_keys.on_update = :cascade
      config.foreign_keys.auto_index = true
    end

Note to MySQL users

schema_plus enables auto_index feature by default. MySQL users should manually disable it to prevent duplicated indexes. To do it edit schema_plus initializer:

   config.foreign_keys.auto_index = false

InnoDB indexes foreign keys itself so schema_plus shouldn't duplicate its job.

PostgreSQL and Sqlite users are encouraged to leave it enabled.

Clone this wiki locally