Created
April 13, 2016 20:32
-
-
Save minch/15f35f61bc3a640a167fc809818c0aab to your computer and use it in GitHub Desktop.
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
diff --git a/config/initializers/active_record.rb b/config/initializers/active_record.rb | |
index 2f966a7..51a5cc7 100644 | |
--- a/config/initializers/active_record.rb | |
+++ b/config/initializers/active_record.rb | |
@@ -18,3 +18,23 @@ ActiveSupport.on_load(:active_record) do | |
Audited.configure_database_connection(config) | |
ActiveRecord::Base.establish_connection(config) | |
end | |
+ | |
+module ActiveRecord | |
+ module Tasks | |
+ class PostgreSQLDatabaseTasks | |
+ def structure_dump(filename) | |
+ set_psql_env | |
+ search_path = configuration['schema_search_path'] | |
+ unless search_path.blank? | |
+ search_path = search_path.split(",").map{|search_path_part| "--schema=#{Shellwords.escape(search_path_part.strip)}" }.join(" ") | |
+ end | |
+ | |
+ #remove deprecated -i flag | |
+ command = "pg_dump -s -x -O -f #{Shellwords.escape(filename)} #{search_path} #{Shellwords.escape(configuration['database'])}" | |
+ raise 'Error dumping database' unless Kernel.system(command) | |
+ | |
+ File.open(filename, "a") { |f| f << "SET search_path TO #{connection.schema_search_path};\n\n" } | |
+ end | |
+ end | |
+ end | |
+end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment