This repository has been archived by the owner on May 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
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.
- Go to config/initializers
- Rename automatic_foreign_key.rb to schema_plus.rb
- Open schema_plus.rb in your favorite editor(TM).
- Change AutomaticForeignKey.setup to SchemaPlus.config
- open schema_plus.rb and change
config.on_delete
toconfig.foreign_keys.on_delete
,config.auto_index
toconfig.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
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.