diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-03-17 13:17:29 -0400 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-03-17 13:17:29 -0400 |
commit | 6f7e7aadfdc76990176a5f3c4d0024aa665ef173 (patch) | |
tree | 968b3171def21e2ee030720333351589f017b798 /activerecord/lib | |
parent | 7b02f86680b2d712ea5b0ca541dc620f0a524b5a (diff) | |
parent | cfe67a63b6d1c48fb4ddcb9cf5a303bb47036b5f (diff) | |
download | rails-6f7e7aadfdc76990176a5f3c4d0024aa665ef173.tar.gz rails-6f7e7aadfdc76990176a5f3c4d0024aa665ef173.tar.bz2 rails-6f7e7aadfdc76990176a5f3c4d0024aa665ef173.zip |
Merge pull request #28154 from aripollak/remove-comments-from-structure-sql
Drop comments from structure.sql in postgresql
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/tasks/postgresql_database_tasks.rb | 20 |
1 files changed, 20 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..f1af90c1e8 100644 --- a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb +++ b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb @@ -1,8 +1,11 @@ +require "tempfile" + module ActiveRecord module Tasks # :nodoc: class PostgreSQLDatabaseTasks # :nodoc: DEFAULT_ENCODING = ENV["CHARSET"] || "utf8" ON_ERROR_STOP_1 = "ON_ERROR_STOP=1".freeze + SQL_COMMENT_BEGIN = "--".freeze delegate :connection, :establish_connection, :clear_active_connections!, to: ActiveRecord::Base @@ -65,6 +68,7 @@ module ActiveRecord end args << configuration["database"] run_cmd("pg_dump", args, "dumping") + remove_sql_header_comments(filename) File.open(filename, "a") { |f| f << "SET search_path TO #{connection.schema_search_path};\n\n" } end @@ -110,6 +114,22 @@ 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_header_comments(filename) + removing_comments = true + tempfile = Tempfile.open("uncommented_structure.sql") + begin + File.foreach(filename) do |line| + unless removing_comments && (line.start_with?(SQL_COMMENT_BEGIN) || line.blank?) + tempfile << line + removing_comments = false + end + end + ensure + tempfile.close + end + FileUtils.mv(tempfile.path, filename) + end end end end |