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

Add foreign keys when creating a new transition table #248

Merged
merged 2 commits into from
May 22, 2017
Merged

Add foreign keys when creating a new transition table #248

merged 2 commits into from
May 22, 2017

Conversation

greysteil
Copy link
Contributor

@greysteil greysteil commented May 18, 2017

Because Statesman is ... designed to provide ... data integrity.. :octocat:

@@ -9,6 +9,8 @@ class Create<%= migration_class_name %> < ActiveRecord::Migration
t.timestamps null: false
end

add_foreign_key :<%= table_name %>, :<%= parent_table_name %>
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@kenchan0130
Copy link
Contributor

I think that introducing foreign key constraints depends on team and project policies.
Is it more appropriate to put it in the template as a position of this gem?

@greysteil
Copy link
Contributor Author

@kenchan0130 - good point, I've updated the migration to include a comment above the foreign key addition.

@kenchan0130
Copy link
Contributor

@greysteil

Your comment approach is working out a compromise.
look to me good.

@Sinjo
Copy link
Contributor

Sinjo commented May 22, 2017

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.

@Sinjo Sinjo merged commit 41419af into gocardless:master May 22, 2017
@Sinjo
Copy link
Contributor

Sinjo commented May 22, 2017

An afterthought: I hadn't thought about add_foreign_key with SQLite. It turns out it's just a no-op there.

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 README.md that we only support Postgres and MySQL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants