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

Set active_record config for always creating uuids in generators #21762

Merged
merged 1 commit into from Oct 20, 2015

Conversation

jmccartie
Copy link
Contributor

@jmccartie jmccartie commented Sep 25, 2015

UUID's are awesome (and they improve performance). I want them everywhere, but it's annoying to have to modify my DB migrations every time. I wish I could make an application config to force the generators to always add id: :uuid whenever I create a table.

Throw this in your application.rb file...

config.active_record.primary_key = :uuid

...and id: :uuid will be added to every create_table generation:

@rails-bot
Copy link

rails-bot commented Sep 25, 2015

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@sgrif
Copy link
Contributor

sgrif commented Sep 25, 2015

This has falling tests

@jmccartie
Copy link
Contributor Author

jmccartie commented Sep 25, 2015

@sgrif Thanks for the heads up. Tests passing.

I'm pretty unfamiliar with the AR/Railties code, but I think I figured out how these generators work (kinda). I left the primary_key setting wide open for now. Let me know if this is where it should go. (and if this is even a decent idea in the first place .... though it certainly scratches an itch I've had recently)

@@ -221,6 +221,16 @@ def test_create_table_migration
end
end

def test_add_uuid_to_create_table_migration
Rails.application.config.active_record.primary_key = :uuid
Copy link
Contributor

@sgrif sgrif Oct 20, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to set this back to the old value at the end of this test?

@sgrif
Copy link
Contributor

sgrif commented Oct 20, 2015

Can you squash and rebase after addressing that comment? This will need a changelog entry as well.

@jmccartie
Copy link
Contributor Author

jmccartie commented Oct 20, 2015

@sgrif Done. I'll watch the tests and let you know once it's all green...

@sgrif
Copy link
Contributor

sgrif commented Oct 20, 2015

Thanks. I'm going through the backlog so you won't be able to keep up with the merge conflicts I think. Just ping me once the tests are green and I'll merge manually.

@jmccartie
Copy link
Contributor Author

jmccartie commented Oct 20, 2015

@sgrif All checks passed. Merge conflict. :)

@sgrif sgrif merged commit fb42c49 into rails:master Oct 20, 2015
sgrif added a commit that referenced this pull request Oct 20, 2015
Set active_record config for always creating uuids in generators
sonalkr132 added a commit to sonalkr132/rubygems.org that referenced this pull request Dec 20, 2018
`id: :serial` is added because `id: :uuid` support was introduced.
rails/rails#21762
`using: :btree` was redundant rails/rails#27981
Standardaized column spacing was removed to avoid diffs about
aligining columns.
rails/rails@df84e98#r22545295

```diff
-   t.string "zipcode", limit: 5
+   t.string "zipcode",           limit: 5
+   t.string "extra_information", limit: 255
```
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.

None yet