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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?