Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[#73] clearance update users migration should have version number in …

…migration class name, not just file name
  • Loading branch information...
commit 340f518feea9e9c294ce922b3890b3f54ce44f01 1 parent 56c280f
@croaky croaky authored
View
12 generators/clearance/clearance_generator.rb
@@ -33,6 +33,12 @@ def manifest
end
end
+ def schema_version_constant
+ if upgrading_clearance_again?
+ "To#{schema_version.gsub('_', '')}"
+ end
+ end
+
private
def migration_source_name
@@ -44,7 +50,7 @@ def migration_source_name
end
def migration_target_name
- if ActiveRecord::Base.connection.table_exists?(:users)
+ if upgrading_clearance_again?
"update_users_to_#{schema_version}"
else
'create_users'
@@ -55,4 +61,8 @@ def schema_version
IO.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).strip.gsub(/[^\d]/, '_')
end
+ def upgrading_clearance_again?
+ ActiveRecord::Base.connection.table_exists?(:users)
+ end
+
end
View
12 generators/clearance/templates/migrations/update_users.rb
@@ -1,14 +1,14 @@
-class ClearanceUpdateUsers < ActiveRecord::Migration
+class ClearanceUpdateUsers<%= schema_version_constant %> < ActiveRecord::Migration
def self.up
<%
existing_columns = ActiveRecord::Base.connection.columns(:users).collect { |each| each.name }
columns = [
[:email, 't.string :email'],
[:encrypted_password, 't.string :encrypted_password, :limit => 128'],
- [:salt, 't.string :salt, :limit => 128'],
+ [:salt, 't.string :salt, :limit => 128'],
[:confirmation_token, 't.string :confirmation_token, :limit => 128'],
- [:remember_token, 't.string :remember_token, :limit => 128'],
- [:email_confirmed, 't.boolean :email_confirmed, :default => false, :null => false']
+ [:remember_token, 't.string :remember_token, :limit => 128'],
+ [:email_confirmed, 't.boolean :email_confirmed, :default => false, :null => false']
].delete_if {|c| existing_columns.include?(c.first.to_s)}
-%>
change_table(:users) do |t|
@@ -22,8 +22,8 @@ def self.up
index_names = existing_indexes.collect { |each| each.name }
new_indexes = [
[:index_users_on_id_and_confirmation_token, 'add_index :users, [:id, :confirmation_token]'],
- [:index_users_on_email, 'add_index :users, :email'],
- [:index_users_on_remember_token, 'add_index :users, :remember_token']
+ [:index_users_on_email, 'add_index :users, :email'],
+ [:index_users_on_remember_token, 'add_index :users, :remember_token']
].delete_if { |each| index_names.include?(each.first.to_s) }
-%>
<% new_indexes.each do |each| -%>
Please sign in to comment.
Something went wrong with that request. Please try again.