From 37062a8f71eb547573514f3698d958ae2eb2f377 Mon Sep 17 00:00:00 2001 From: Jason Weathered Date: Fri, 26 Nov 2021 12:53:52 +1000 Subject: [PATCH] Quieten PostgreSQL structure load MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Suppresses the following output during `rails db:test:prepare`: set_config ------------ (1 row) This is caused by `SELECT set_config(…)` statements in `db/structure.sql`. --- .../tasks/postgresql_database_tasks.rb | 2 +- .../test/cases/tasks/postgresql_rake_test.rb | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb index 3913ef938f028..c9daa4b5a2637 100644 --- a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb +++ b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb @@ -81,7 +81,7 @@ def structure_dump(filename, extra_flags) end def structure_load(filename, extra_flags) - args = ["--set", ON_ERROR_STOP_1, "--quiet", "--no-psqlrc", "--file", filename] + args = ["--set", ON_ERROR_STOP_1, "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename] args.concat(Array(extra_flags)) if extra_flags args << db_config.database run_cmd("psql", args, "loading") diff --git a/activerecord/test/cases/tasks/postgresql_rake_test.rb b/activerecord/test/cases/tasks/postgresql_rake_test.rb index 62c99099e3241..a1c9066ac0985 100644 --- a/activerecord/test/cases/tasks/postgresql_rake_test.rb +++ b/activerecord/test/cases/tasks/postgresql_rake_test.rb @@ -529,7 +529,7 @@ def test_structure_load assert_called_with( Kernel, :system, - [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--file", filename, @configuration["database"]], + [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, @configuration["database"]], returns: true ) do ActiveRecord::Tasks::DatabaseTasks.structure_load(@configuration, filename) @@ -538,7 +538,7 @@ def test_structure_load def test_structure_load_with_extra_flags filename = "awesome-file.sql" - expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--file", filename, "--noop", @configuration["database"]] + expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, "--noop", @configuration["database"]] assert_called_with(Kernel, :system, expected_command, returns: true) do with_structure_load_flags(["--noop"]) do @@ -550,7 +550,7 @@ def test_structure_load_with_extra_flags def test_structure_load_with_env filename = "awesome-file.sql" expected_env = { "PGHOST" => "my.server.tld", "PGPORT" => "2345", "PGUSER" => "jane", "PGPASSWORD" => "s3cr3t" } - expected_command = [expected_env, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--file", filename, "--noop", @configuration["database"]] + expected_command = [expected_env, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, "--noop", @configuration["database"]] assert_called_with(Kernel, :system, expected_command, returns: true) do with_structure_load_flags(["--noop"]) do @@ -565,7 +565,7 @@ def test_structure_load_with_env def test_structure_load_with_ssl_env filename = "awesome-file.sql" expected_env = { "PGSSLMODE" => "verify-full", "PGSSLCERT" => "client.crt", "PGSSLKEY" => "client.key", "PGSSLROOTCERT" => "root.crt" } - expected_command = [expected_env, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--file", filename, "--noop", @configuration["database"]] + expected_command = [expected_env, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, "--noop", @configuration["database"]] assert_called_with(Kernel, :system, expected_command, returns: true) do with_structure_load_flags(["--noop"]) do @@ -579,7 +579,7 @@ def test_structure_load_with_ssl_env def test_structure_load_with_hash_extra_flags_for_a_different_driver filename = "awesome-file.sql" - expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--file", filename, @configuration["database"]] + expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, @configuration["database"]] assert_called_with(Kernel, :system, expected_command, returns: true) do with_structure_load_flags({ mysql2: ["--noop"] }) do @@ -590,7 +590,7 @@ def test_structure_load_with_hash_extra_flags_for_a_different_driver def test_structure_load_with_hash_extra_flags_for_the_correct_driver filename = "awesome-file.sql" - expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--file", filename, "--noop", @configuration["database"]] + expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, "--noop", @configuration["database"]] assert_called_with(Kernel, :system, expected_command, returns: true) do with_structure_load_flags({ postgresql: ["--noop"] }) do @@ -604,7 +604,7 @@ def test_structure_load_accepts_path_with_spaces assert_called_with( Kernel, :system, - [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--file", filename, @configuration["database"]], + [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, @configuration["database"]], returns: true ) do ActiveRecord::Tasks::DatabaseTasks.structure_load(@configuration, filename)