aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/rails_generator/generators/components/migration/migration_generator.rb2
2 files changed, 4 insertions, 0 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index ed54849e69..935a47fa0b 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added prevention of duplicate migrations from the generator #2240 [fbeausoleil@ftml.net]
+
* Add db_schema_dump and db_schema_import rake tasks to work with the new ActiveRecord::SchemaDumper (for dumping a schema to and reading a schema from a ruby file).
* Reformed all the config/environments/* files to conform to the new Rails::Configuration approach. Fully backwards compatible.
diff --git a/railties/lib/rails_generator/generators/components/migration/migration_generator.rb b/railties/lib/rails_generator/generators/components/migration/migration_generator.rb
index d1f4d4c41b..c830d715bb 100644
--- a/railties/lib/rails_generator/generators/components/migration/migration_generator.rb
+++ b/railties/lib/rails_generator/generators/components/migration/migration_generator.rb
@@ -2,6 +2,8 @@ class MigrationGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
m.directory File.join('db/migrate')
+ existing_migrations = Dir.glob("db/migrate/[0-9]*_#{file_name}.rb")
+ raise "Another migration already exists with the same name" unless existing_migrations.empty?
next_migration_number = Dir.glob("db/migrate/[0-9]*.*").size + 1
m.template 'migration.rb', File.join('db/migrate', "#{next_migration_number}_#{file_name}.rb")
end