aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/rails/generators/active_record/migration/templates
diff options
context:
space:
mode:
authorrobertomiranda <rjmaltamar@gmail.com>2015-01-11 14:06:41 -0500
committerrobertomiranda <rjmaltamar@gmail.com>2015-01-11 14:42:54 -0500
commit5cca205114280bcbf9b43134ff396f1ac47b5071 (patch)
treefc8ca672212b1e6570ce49edd7258bd77890595d /activerecord/lib/rails/generators/active_record/migration/templates
parent7b47f422cf367db4918be76c417d9db592a04adf (diff)
downloadrails-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.rb5
-rw-r--r--activerecord/lib/rails/generators/active_record/migration/templates/migration.rb3
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? -%>