aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAri Pollak <ajp@aripollak.com>2017-02-24 12:44:11 -0500
committerAri Pollak <ajp@aripollak.com>2017-02-24 12:46:00 -0500
commitdf050484cd3b5e888b50d2e0554a4077407459a8 (patch)
tree7245a326ea2f49a05ec64d4758531f9884bd4990 /activerecord/lib/active_record
parentaa56dc235a341876762f0219738cac46d181fcd3 (diff)
downloadrails-df050484cd3b5e888b50d2e0554a4077407459a8.tar.gz
rails-df050484cd3b5e888b50d2e0554a4077407459a8.tar.bz2
rails-df050484cd3b5e888b50d2e0554a4077407459a8.zip
Drop comments from structure.sql in postgresql
Fixes #28153.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/tasks/postgresql_database_tasks.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb
index 5155ced0e2..83b82506d3 100644
--- a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb
@@ -1,3 +1,5 @@
+require "tempfile"
+
module ActiveRecord
module Tasks # :nodoc:
class PostgreSQLDatabaseTasks # :nodoc:
@@ -65,6 +67,7 @@ module ActiveRecord
end
args << configuration["database"]
run_cmd("pg_dump", args, "dumping")
+ remove_sql_comments(filename)
File.open(filename, "a") { |f| f << "SET search_path TO #{connection.schema_search_path};\n\n" }
end
@@ -110,6 +113,18 @@ module ActiveRecord
msg << "Please check the output above for any errors and make sure that `#{cmd}` is installed in your PATH and has proper permissions.\n\n"
msg
end
+
+ def remove_sql_comments(filename)
+ tempfile = Tempfile.open('uncommented_structure.sql')
+ begin
+ File.foreach(filename) do |line|
+ tempfile << line unless line.start_with?('--')
+ end
+ ensure
+ tempfile.close
+ end
+ FileUtils.mv(tempfile.path, filename)
+ end
end
end
end