From df050484cd3b5e888b50d2e0554a4077407459a8 Mon Sep 17 00:00:00 2001 From: Ari Pollak <ajp@aripollak.com> Date: Fri, 24 Feb 2017 12:44:11 -0500 Subject: Drop comments from structure.sql in postgresql Fixes #28153. --- .../lib/active_record/tasks/postgresql_database_tasks.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'activerecord/lib') 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 -- cgit v1.2.3