Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Append the version number to generated update migrations

  • Loading branch information...
commit 61bed1155c8fe3c610fb784a21050331b29f0427 1 parent 6caee9c
@jferris jferris authored
Showing with 15 additions and 3 deletions.
  1. +15 −3 generators/clearance/clearance_generator.rb
View
18 generators/clearance/clearance_generator.rb
@@ -25,9 +25,9 @@ def manifest
m.directory File.join("test", "factories")
m.file "factories.rb", "test/factories/clearance.rb"
- m.migration_template "migrations/#{migration_name}.rb",
+ m.migration_template "migrations/#{migration_source_name}.rb",
'db/migrate',
- :migration_file_name => "clearance_#{migration_name}"
+ :migration_file_name => "clearance_#{migration_target_name}"
m.readme "README"
end
@@ -35,7 +35,7 @@ def manifest
private
- def migration_name
+ def migration_source_name
if ActiveRecord::Base.connection.table_exists?(:users)
'update_users'
else
@@ -43,4 +43,16 @@ def migration_name
end
end
+ def migration_target_name
+ if ActiveRecord::Base.connection.table_exists?(:users)
+ "update_users_to_#{schema_version}"
+ else
+ 'create_users'
+ end
+ end
+
+ def schema_version
+ IO.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).strip.gsub(/[^\d]/, '_')
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.