Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema and database awareness #21

Open
jenseng opened this issue Mar 13, 2015 · 0 comments
Open

schema and database awareness #21

jenseng opened this issue Mar 13, 2015 · 0 comments
Labels

Comments

@jenseng
Copy link
Owner

jenseng commented Mar 13, 2015

as indicated in the readme, immigrant might detect "missing" keys if you use multiple databases or schemas. those "missing" keys are actually:

  1. keys that already exist (e.g. between two tables in a different db),
  2. keys that cannot exist (from one database to another), or
  3. keys that should probably not exist (from one schema to another, e.g. if you're using the apartment gem ... while they could be created, it all falls apart once you move beyond a single db ... see point 2.)

immigrant should:

  1. ask each model's connection for its foreign keys, rather than ActiveRecord::Base.connection ... this partially addresses the first problem
  2. ignore associations across databases
  3. for tables within the same database, ignore associations across schemas (for apartment+postgres at least, we can tell this from the table_name's prefix ... "public." vs. ""). might need to do a little research to make sure this is done in a sharding-agnostic way (if possible)
@jenseng jenseng added the bug label Mar 13, 2015
jenseng added a commit that referenced this issue May 18, 2015
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 schemas or databases (see #21)

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

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

note that you need to specify both the from_table and the column
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant