diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-20 05:13:59 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-20 05:13:59 +0000 |
commit | c2bb269cd5c0b2aa42b9206a0994db4e92a24b27 (patch) | |
tree | 9d046bae465af48e6d318dc846c1c4d1da01484b /railties | |
parent | cd8686b45639365ac3af87ddd82254fdc19ec414 (diff) | |
download | rails-c2bb269cd5c0b2aa42b9206a0994db4e92a24b27.tar.gz rails-c2bb269cd5c0b2aa42b9206a0994db4e92a24b27.tar.bz2 rails-c2bb269cd5c0b2aa42b9206a0994db4e92a24b27.zip |
Allows generator to specify migrations directory. References #2960.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3101 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties')
4 files changed, 10 insertions, 5 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 96f423f1bb..18a138181e 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,6 +1,6 @@ *SVN* -* Introducing the session_migration generator. Creates an add_session_table migration. #2958 [Rick Olson] +* Introducing the session_migration generator. Creates an add_session_table migration. Allows generator to specify migrations directory. #2958, #2960 [Rick Olson] * Update to Prototype 1.4.0_rc4. Closes #2943 (old Array.prototype.reverse behavior can be obtained by passing false as an argument). [Sam Stephenson] diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb index 97b23fbf5e..32a7b602d7 100644 --- a/railties/lib/rails_generator/commands.rb +++ b/railties/lib/rails_generator/commands.rb @@ -56,8 +56,12 @@ module Rails end protected + def migration_directory(relative_path) + directory(@migration_directory = relative_path) + end + def existing_migrations(file_name) - Dir.glob("db/migrate/[0-9]*_#{file_name}.rb") + Dir.glob("#{@migration_directory}/[0-9]*_#{file_name}.rb") end def migration_exists?(file_name) @@ -65,7 +69,7 @@ module Rails end def current_migration_number - Dir.glob('db/migrate/[0-9]*.rb').inject(0) do |max, file_path| + Dir.glob("#{@migration_directory}/[0-9]*.rb").inject(0) do |max, file_path| n = File.basename(file_path).split('_', 2).first.to_i if n > max then n else max end end @@ -305,6 +309,7 @@ module Rails # When creating a migration, it knows to find the first available file in db/migrate and use the migration.rb template. def migration_template(relative_source, relative_destination, template_options = {}) + migration_directory relative_destination raise "Another migration is already named #{file_name}: #{existing_migrations(file_name).first}" if migration_exists?(file_name) template(relative_source, "#{relative_destination}/#{next_migration_string}_#{file_name}.rb", template_options) end @@ -418,6 +423,7 @@ end_message # When deleting a migration, it knows to delete every file named "[0-9]*_#{file_name}". def migration_template(relative_source, relative_destination, template_options = {}) + migration_directory relative_destination raise "There is no migration named #{file_name}" unless migration_exists?(file_name) existing_migrations(file_name).each do |file_path| file(relative_source, file_path, template_options) @@ -457,6 +463,7 @@ end_message end def migration_template(relative_source, relative_destination, options = {}) + migration_directory relative_destination logger.migration_template file_name end end 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 95652139f9..a0d0d472c2 100644 --- a/railties/lib/rails_generator/generators/components/migration/migration_generator.rb +++ b/railties/lib/rails_generator/generators/components/migration/migration_generator.rb @@ -1,7 +1,6 @@ class MigrationGenerator < Rails::Generator::NamedBase def manifest record do |m| - m.directory 'db/migrate' m.migration_template 'migration.rb', 'db/migrate' end end diff --git a/railties/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb b/railties/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb index 12802858f6..a513fa5cbf 100644 --- a/railties/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +++ b/railties/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb @@ -6,7 +6,6 @@ class SessionMigrationGenerator < Rails::Generator::NamedBase def manifest record do |m| - m.directory 'db/migrate' m.migration_template 'migration.rb', 'db/migrate' end end |