Skip to content

Commit e2f36ff

Browse files
authored
Merge pull request rails#54813 from AliceLoeser/append_structure_load_args
With postgres adapter, prepend `structure_load_flags` instead of appending them.
2 parents 8945f10 + 6718aeb commit e2f36ff

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

activerecord/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
* Prepend `extra_flags` in postgres' `structure_load`
2+
3+
When specifying `structure_load_flags` with a postgres adapter, the flags
4+
were appended to the default flags, instead of prepended.
5+
This caused issues with flags not being taken into account by postgres.
6+
7+
*Alice Loeser*
8+
19
* Allow bypassing primary key/constraint addition in `implicit_order_column`
210

311
When specifying multiple columns in an array for `implicit_order_column`, adding

activerecord/lib/active_record/tasks/postgresql_database_tasks.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ def structure_dump(filename, extra_flags)
7878
end
7979

8080
def structure_load(filename, extra_flags)
81-
args = ["--set", ON_ERROR_STOP_1, "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename]
81+
args = ["--set", ON_ERROR_STOP_1, "--quiet", "--no-psqlrc", "--output", File::NULL]
8282
args.concat(Array(extra_flags)) if extra_flags
83+
args.concat(["--file", filename])
8384
args << db_config.database
8485
run_cmd("psql", args, "loading")
8586
end

activerecord/test/cases/adapters/postgresql/postgresql_rake_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def test_structure_load
517517

518518
def test_structure_load_with_extra_flags
519519
filename = "awesome-file.sql"
520-
expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, "--noop", @configuration["database"]]
520+
expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--noop", "--file", filename, @configuration["database"]]
521521

522522
assert_called_with(Kernel, :system, expected_command, returns: true) do
523523
with_structure_load_flags(["--noop"]) do
@@ -529,7 +529,7 @@ def test_structure_load_with_extra_flags
529529
def test_structure_load_with_env
530530
filename = "awesome-file.sql"
531531
expected_env = { "PGHOST" => "my.server.tld", "PGPORT" => "2345", "PGUSER" => "jane", "PGPASSWORD" => "s3cr3t" }
532-
expected_command = [expected_env, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, "--noop", @configuration["database"]]
532+
expected_command = [expected_env, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--noop", "--file", filename, @configuration["database"]]
533533

534534
assert_called_with(Kernel, :system, expected_command, returns: true) do
535535
with_structure_load_flags(["--noop"]) do
@@ -544,7 +544,7 @@ def test_structure_load_with_env
544544
def test_structure_load_with_ssl_env
545545
filename = "awesome-file.sql"
546546
expected_env = { "PGSSLMODE" => "verify-full", "PGSSLCERT" => "client.crt", "PGSSLKEY" => "client.key", "PGSSLROOTCERT" => "root.crt" }
547-
expected_command = [expected_env, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, "--noop", @configuration["database"]]
547+
expected_command = [expected_env, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--noop", "--file", filename, @configuration["database"]]
548548

549549
assert_called_with(Kernel, :system, expected_command, returns: true) do
550550
with_structure_load_flags(["--noop"]) do
@@ -569,7 +569,7 @@ def test_structure_load_with_hash_extra_flags_for_a_different_driver
569569

570570
def test_structure_load_with_hash_extra_flags_for_the_correct_driver
571571
filename = "awesome-file.sql"
572-
expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, "--noop", @configuration["database"]]
572+
expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--noop", "--file", filename, @configuration["database"]]
573573

574574
assert_called_with(Kernel, :system, expected_command, returns: true) do
575575
with_structure_load_flags({ postgresql: ["--noop"] }) do

0 commit comments

Comments
 (0)