diff options
author | robertomiranda <rjmaltamar@gmail.com> | 2015-01-11 14:06:41 -0500 |
---|---|---|
committer | robertomiranda <rjmaltamar@gmail.com> | 2015-01-11 14:42:54 -0500 |
commit | 5cca205114280bcbf9b43134ff396f1ac47b5071 (patch) | |
tree | fc8ca672212b1e6570ce49edd7258bd77890595d /activerecord/lib/rails/generators/active_record/migration/templates | |
parent | 7b47f422cf367db4918be76c417d9db592a04adf (diff) | |
download | rails-5cca205114280bcbf9b43134ff396f1ac47b5071.tar.gz rails-5cca205114280bcbf9b43134ff396f1ac47b5071.tar.bz2 rails-5cca205114280bcbf9b43134ff396f1ac47b5071.zip |
Add Secure Token Generator
Diffstat (limited to 'activerecord/lib/rails/generators/active_record/migration/templates')
-rw-r--r-- | activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb | 5 | ||||
-rw-r--r-- | activerecord/lib/rails/generators/active_record/migration/templates/migration.rb | 3 |
2 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb b/activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb index fd94a2d038..5b3e57dcf6 100644 --- a/activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +++ b/activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb @@ -4,6 +4,8 @@ class <%= migration_class_name %> < ActiveRecord::Migration <% attributes.each do |attribute| -%> <% if attribute.password_digest? -%> t.string :password_digest<%= attribute.inject_options %> +<% elsif attribute.token? -%> + t.string :<%= attribute.name %><%= attribute.inject_options %> <% else -%> t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %> <% end -%> @@ -12,6 +14,9 @@ class <%= migration_class_name %> < ActiveRecord::Migration t.timestamps <% end -%> end +<% attributes.select(&:token?).each do |attribute| -%> + add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>, unique: true +<% end -%> <% attributes_with_index.each do |attribute| -%> add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %> <% end -%> diff --git a/activerecord/lib/rails/generators/active_record/migration/templates/migration.rb b/activerecord/lib/rails/generators/active_record/migration/templates/migration.rb index ae9c74fd05..23a377db6a 100644 --- a/activerecord/lib/rails/generators/active_record/migration/templates/migration.rb +++ b/activerecord/lib/rails/generators/active_record/migration/templates/migration.rb @@ -4,6 +4,9 @@ class <%= migration_class_name %> < ActiveRecord::Migration <% attributes.each do |attribute| -%> <%- if attribute.reference? -%> add_reference :<%= table_name %>, :<%= attribute.name %><%= attribute.inject_options %> + <%- elsif attribute.token? -%> + add_column :<%= table_name %>, :<%= attribute.name %>, :string<%= attribute.inject_options %> + add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>, unique: true <%- else -%> add_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %> <%- if attribute.has_index? -%> |