diff options
author | Ari Pollak <ajp@aripollak.com> | 2017-02-24 16:54:55 -0500 |
---|---|---|
committer | Ari Pollak <ajp@aripollak.com> | 2017-02-24 17:00:11 -0500 |
commit | cfe67a63b6d1c48fb4ddcb9cf5a303bb47036b5f (patch) | |
tree | f79ebe194a2447553f99253478c105cb198ccc1c /activerecord/lib | |
parent | df050484cd3b5e888b50d2e0554a4077407459a8 (diff) | |
download | rails-cfe67a63b6d1c48fb4ddcb9cf5a303bb47036b5f.tar.gz rails-cfe67a63b6d1c48fb4ddcb9cf5a303bb47036b5f.tar.bz2 rails-cfe67a63b6d1c48fb4ddcb9cf5a303bb47036b5f.zip |
Only remove comments before the first statement
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/tasks/postgresql_database_tasks.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb index 83b82506d3..f1af90c1e8 100644 --- a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb +++ b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb @@ -5,6 +5,7 @@ module ActiveRecord 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 @@ -67,7 +68,7 @@ module ActiveRecord end args << configuration["database"] run_cmd("pg_dump", args, "dumping") - remove_sql_comments(filename) + remove_sql_header_comments(filename) File.open(filename, "a") { |f| f << "SET search_path TO #{connection.schema_search_path};\n\n" } end @@ -114,11 +115,15 @@ module ActiveRecord msg end - def remove_sql_comments(filename) - tempfile = Tempfile.open('uncommented_structure.sql') + def remove_sql_header_comments(filename) + removing_comments = true + tempfile = Tempfile.open("uncommented_structure.sql") begin File.foreach(filename) do |line| - tempfile << line unless line.start_with?('--') + unless removing_comments && (line.start_with?(SQL_COMMENT_BEGIN) || line.blank?) + tempfile << line + removing_comments = false + end end ensure tempfile.close |