Skip to content

Commit

Permalink
Merge pull request #43730 from jasoncodes/quiet-structure-load
Browse files Browse the repository at this point in the history
Quieten PostgreSQL structure load
  • Loading branch information
matthewd committed Feb 24, 2022
2 parents 00b03b8 + 37062a8 commit dc0f5db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Expand Up @@ -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")
Expand Down
14 changes: 7 additions & 7 deletions activerecord/test/cases/tasks/postgresql_rake_test.rb
Expand Up @@ -531,7 +531,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)
Expand All @@ -540,7 +540,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
Expand All @@ -552,7 +552,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
Expand All @@ -567,7 +567,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
Expand All @@ -581,7 +581,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
Expand All @@ -592,7 +592,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
Expand All @@ -606,7 +606,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)
Expand Down

0 comments on commit dc0f5db

Please sign in to comment.