Created
February 9, 2020 12:47
-
-
Save dodacode/0b2a89ad476c6c4dab5000c5d818c955 to your computer and use it in GitHub Desktop.
UUIDs for Rails ActiveRecords
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configures Rails to use UUIDs instead of incremental integers. | |
# Limits Rails to run with postgresql only (even in development and test environments) | |
# postgresql adapter | |
gem "pg" | |
# default to use uuids in generators | |
initializer 'generators.rb', <<-CODE | |
Rails.application.config.generators do |g| | |
g.orm :active_record, primary_key_type: :uuid | |
end | |
CODE | |
# enable extension in postgresql db | |
generate(:migration, 'EnableUUID') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
enable_extension 'pgcrypto' unless extension_enabled?('pgcrypto')
Needs to be added to the EnableUUID migration to work.