-
Notifications
You must be signed in to change notification settings - Fork 162
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
Add foreign keys when creating a new transition table #248
Conversation
@@ -9,6 +9,8 @@ class Create<%= migration_class_name %> < ActiveRecord::Migration | |||
t.timestamps null: false | |||
end | |||
|
|||
add_foreign_key :<%= table_name %>, :<%= parent_table_name %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that you should change lib/generators/statesman/templates/update_migration.rb.erb
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deliberately kept it out of there, under the assumption that the end user would have already added a foreign key to the existing table they're updating if they wanted one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
under the assumption that the end user would have already added a foreign key to the existing table they're updating if they wanted one.
I see, but it depends on the situation.
I think that introducing foreign key constraints depends on team and project policies. |
@kenchan0130 - good point, I've updated the migration to include a comment above the foreign key addition. |
Your comment approach is working out a compromise. |
Agree with having them by default in the template. If people don't like foreign keys they can always delete them from the generated migration. |
An afterthought: I hadn't thought about I'm not sure if we care about SQLite support (we don't test it). I'll have a chat with another maintainer or two and either add SQLite to the build or add an explicit notice in |
Because
Statesman is ... designed to provide ... data integrity.
.