From b52dfc6726d6471b5fea4ef1bde988157002a224 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sun, 25 Jul 2010 19:04:32 +0200 Subject: [PATCH] Added Rails.application.config.paths.db.migrate to remove hardcoded db/migrate paths --- activerecord/lib/active_record/migration.rb | 10 ++++++---- .../lib/active_record/railties/databases.rake | 13 +++++++------ railties/lib/rails/engine/configuration.rb | 2 ++ 3 files changed, 15 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:" diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index 4588c27277..9aac9c81d0 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -34,6 +34,8 @@ module Rails paths.public.stylesheets "public/stylesheets" paths.vendor "vendor", :load_path => true paths.vendor.plugins "vendor/plugins" + paths.db "db" + paths.db.migrate "db/migrate" paths end end