diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-07-25 19:04:32 +0200 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-09-03 22:59:08 +0200 |
commit | b52dfc6726d6471b5fea4ef1bde988157002a224 (patch) | |
tree | 1a41119ae647c99167108f4c856f0156c7a3f81b /activerecord | |
parent | 0c1cd15470b6f953e1af8f47d072270b55474c31 (diff) | |
download | rails-b52dfc6726d6471b5fea4ef1bde988157002a224.tar.gz rails-b52dfc6726d6471b5fea4ef1bde988157002a224.tar.bz2 rails-b52dfc6726d6471b5fea4ef1bde988157002a224.zip |
Added Rails.application.config.paths.db.migrate to remove hardcoded db/migrate paths
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 10 | ||||
-rw-r--r-- | activerecord/lib/active_record/railties/databases.rake | 13 |
2 files changed, 13 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 198f0a18cb..932ded414a 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -409,6 +409,8 @@ module ActiveRecord class Migrator#:nodoc: class << self + attr_writer :migrations_path + def migrate(migrations_path, target_version = nil) case when target_version.nil? @@ -441,10 +443,6 @@ module ActiveRecord self.new(direction, migrations_path, target_version).run end - def migrations_path - 'db/migrate' - end - def schema_migrations_table_name Base.table_name_prefix + 'schema_migrations' + Base.table_name_suffix end @@ -468,6 +466,10 @@ module ActiveRecord name.table_name rescue "#{ActiveRecord::Base.table_name_prefix}#{name}#{ActiveRecord::Base.table_name_suffix}" end + def migrations_path + @migrations_path ||= 'db/migrate' + end + private def move(direction, migrations_path, steps) diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index b1aad0d496..f8a5114870 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -2,6 +2,7 @@ namespace :db do task :load_config => :rails_env do require 'active_record' ActiveRecord::Base.configurations = Rails.application.config.database_configuration + ActiveRecord::Migrator.migrations_path = Rails.application.config.paths.db.migrate.to_a.first end namespace :create do @@ -139,7 +140,7 @@ namespace :db do desc "Migrate the database (options: VERSION=x, VERBOSE=false)." task :migrate => :environment do ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true - ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) + ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_path, ENV["VERSION"] ? ENV["VERSION"].to_i : nil) Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby end @@ -162,7 +163,7 @@ namespace :db do task :up => :environment do version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil raise "VERSION is required" unless version - ActiveRecord::Migrator.run(:up, "db/migrate/", version) + ActiveRecord::Migrator.run(:up, ActiveRecord::Migrator.migrations_path, version) Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby end @@ -170,7 +171,7 @@ namespace :db do task :down => :environment do version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil raise "VERSION is required" unless version - ActiveRecord::Migrator.run(:down, "db/migrate/", version) + ActiveRecord::Migrator.run(:down, ActiveRecord::Migrator.migrations_path, version) Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby end @@ -208,14 +209,14 @@ namespace :db do desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).' task :rollback => :environment do step = ENV['STEP'] ? ENV['STEP'].to_i : 1 - ActiveRecord::Migrator.rollback('db/migrate/', step) + ActiveRecord::Migrator.rollback(ActiveRecord::Migrator.migrations_path, step) Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby end # desc 'Pushes the schema to the next version (specify steps w/ STEP=n).' task :forward => :environment do step = ENV['STEP'] ? ENV['STEP'].to_i : 1 - ActiveRecord::Migrator.forward('db/migrate/', step) + ActiveRecord::Migrator.forward(ActiveRecord::Migrator.migrations_path, step) Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby end @@ -260,7 +261,7 @@ namespace :db do # desc "Raises an error if there are pending migrations" task :abort_if_pending_migrations => :environment do if defined? ActiveRecord - pending_migrations = ActiveRecord::Migrator.new(:up, 'db/migrate').pending_migrations + pending_migrations = ActiveRecord::Migrator.new(:up, ActiveRecord::Migrator.migrations_path).pending_migrations if pending_migrations.any? puts "You have #{pending_migrations.size} pending migrations:" |