Created
May 14, 2011 02:35
-
-
Save AquaGeek/971818 to your computer and use it in GitHub Desktop.
Rails Lighthouse ticket #6603
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 5884cf30a5c95366b1aef84961dac7b0be4627f1 Mon Sep 17 00:00:00 2001 | |
From: Juan M. Cuello <juanmacuello@gmail.com> | |
Date: Mon, 21 Mar 2011 22:26:32 -0300 | |
Subject: [PATCH] Set search_path after pg_dump in db:structure:dump. | |
This patch resets the postgres search path in the structure.sql file | |
prior to dump schema information in order to find schema_migrations | |
table when multiples schemas are dumped. | |
--- | |
.../lib/active_record/railties/databases.rake | 4 +++- | |
1 files changed, 3 insertions(+), 1 deletions(-) | |
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake | |
index ff36814..d033bb4 100644 | |
--- a/activerecord/lib/active_record/railties/databases.rake | |
+++ b/activerecord/lib/active_record/railties/databases.rake | |
@@ -358,12 +358,14 @@ db_namespace = namespace :db do | |
ENV['PGHOST'] = abcs[Rails.env]["host"] if abcs[Rails.env]["host"] | |
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"] | |
+ schema_file = "#{Rails.root}/db/#{Rails.env}_structure.sql" | |
search_path = abcs[Rails.env]["schema_search_path"] | |
unless search_path.blank? | |
search_path = search_path.split(",").map{|search_path| "--schema=#{search_path.strip}" }.join(" ") | |
end | |
- `pg_dump -i -U "#{abcs[Rails.env]["username"]}" -s -x -O -f db/#{Rails.env}_structure.sql #{search_path} #{abcs[Rails.env]["database"]}` | |
+ `pg_dump -i -U "#{abcs[Rails.env]["username"]}" -s -x -O -f #{schema_file} #{search_path} #{abcs[Rails.env]["database"]}` | |
raise "Error dumping database" if $?.exitstatus == 1 | |
+ File.open(schema_file, "a") { |f| f << "SET search_path TO #{ActiveRecord::Base.connection.schema_search_path};\n\n" } | |
when "sqlite", "sqlite3" | |
dbfile = abcs[Rails.env]["database"] || abcs[Rails.env]["dbfile"] | |
`#{abcs[Rails.env]["adapter"]} #{dbfile} .schema > db/#{Rails.env}_structure.sql` | |
-- | |
1.7.4.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment