immigrant

Foreign key migration generator for Rails

  • 所有者: jenseng/immigrant
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Immigrant

Immigrant gives Rails a foreign key migration generator so you can
effortlessly find and add missing keys. This is particularly helpful
when you decide to add keys to an established Rails app.

Installation

Add the following to your Gemfile:

gem 'immigrant'

If you're using a version of Rails prior to 4.2, you'll also need the
Foreigner gem.

Usage

rails generate immigration AddKeys

This will create a migration named AddKeys which will have add_foreign_key
statements for any missing foreign keys. Immigrant infers missing ones by
evaluating the associations in your models (e.g. belongs_to, has_many, etc.).
Only missing keys will be added; existing ones will never be altered or
removed.

Rake Task

To help you remember to add keys in the future, there's a handy rake
task you can add to your CI setup. Just run rake immigrant:check_keys,
and if anything is missing it will tell you about it and exit with a
non-zero status.

Skipping associations

Immigrant.ignore_keys allows you to specify a list of keys that should
be ignored (both in the migration generator and the rake task). This is
useful if you have associations spanning databases.

Just create an config/initializers/immigrant.rb file with something like
the following:

Immigrant.ignore_keys = [
  { from_table: "users", column: "account_id" },
  # etc
]

Considerations

If the data in your tables is bad, then the migration will fail to run
(obviously). IOW, ensure you don't have orphaned records before you try to
add foreign keys.

Known Issues

Immigrant currently only looks for foreign keys in ActiveRecord::Base's
database. So if a model is using a different database connection and it has
foreign keys, Immigrant will incorrectly include them again in the generated
migration. Immigrant.ignore_keys can be used to work around this.

Changelog

License

Copyright (c) 2012-2015 Jon Jensen, released under the MIT license

主要指标

概览
名称与所有者jenseng/immigrant
主编程语言Ruby
编程语言Ruby (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2012-04-01 19:59:42
推送于2024-05-08 01:04:14
最后一次提交2017-02-26 12:59:30
发布数12
最新版本名称v0.3.6 (发布于 )
第一版名称v0.1.5 (发布于 )
用户参与
星数484
关注者数8
派生数24
提交数86
已启用问题?
问题数28
打开的问题数4
拉请求数6
打开的拉请求数2
关闭的拉请求数1
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?