Permalink
Browse files

Append the version number to generated update migrations

  • Loading branch information...
jferris committed Feb 17, 2010
1 parent 6caee9c commit 61bed1155c8fe3c610fb784a21050331b29f0427
Showing with 15 additions and 3 deletions.
  1. +15 −3 generators/clearance/clearance_generator.rb
@@ -25,22 +25,34 @@ 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
end
private
- def migration_name
+ def migration_source_name
if ActiveRecord::Base.connection.table_exists?(:users)
'update_users'
else
'create_users'
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

0 comments on commit 61bed11

Please sign in to comment.