From b23fc77db00b1d86283707b7d927f41158f2ce5d Mon Sep 17 00:00:00 2001 From: schreiber Date: Thu, 7 Jan 2010 15:11:56 +0100 Subject: [PATCH] Use PostgreSQL Search path properly PostgreSQL supports multiple schema names in its search path. pg_dump expects each schema as a seperate option. ActiveRecord::Base.connection.dump_schema_information has to be prepended by resetting the schema in the dumpfile. --- railties/lib/tasks/databases.rake | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 8b60839..ffcf330 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -286,7 +286,7 @@ namespace :db do ENV['PGPORT'] = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"] ENV['PGPASSWORD'] = abcs[RAILS_ENV]["password"].to_s if abcs[RAILS_ENV]["password"] search_path = abcs[RAILS_ENV]["schema_search_path"] - search_path = "--schema=#{search_path}" if search_path + search_path = search_path.split(",").map{|s| "-n #{s}"}.join(" ") if search_path `pg_dump -i -U "#{abcs[RAILS_ENV]["username"]}" -s -x -O -f db/#{RAILS_ENV}_structure.sql #{search_path} #{abcs[RAILS_ENV]["database"]}` raise "Error dumping database" if $?.exitstatus == 1 when "sqlite", "sqlite3" @@ -304,7 +304,10 @@ namespace :db do end if ActiveRecord::Base.connection.supports_migrations? - File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information } + File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "a") { |f| + f << "SET search_path = #{abcs[RAILS_ENV]["schema_search_path"]};\n" if abcs[RAILS_ENV]["schema_search_path"] + f << ActiveRecord::Base.connection.dump_schema_information + } end end end -- 1.5.6.5