Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rake db:structure:dump on Postgres when multiple schemas are used #22345

Merged
merged 1 commit into from
Nov 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
* Fix `rake db:structure:dump` on Postgres when multiple schemas are used.

If postgresql is being used and there are multiple schemas listed on the
`schema_search_path`, then `structure.sql` dumps (triggered by `rake
db:structure:dump` or `config.active_record.schema_format = :sql`) began
failing in Rails 4.2.5.

*Nick Muerdter*

* Except keys of `build_record`'s argument from `create_scope` in `initialize_attributes`.

Fixes #21893.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def structure_dump(filename)

args = ['-s', '-x', '-O', '-f', filename]
unless search_path.blank?
args << search_path.split(',').map do |part|
args += search_path.split(',').map do |part|
"--schema=#{part.strip}"
end.join(' ')
end
end
args << configuration['database']
run_cmd('pg_dump', args, 'dumping')
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/tasks/postgresql_rake_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def test_structure_dump
def test_structure_dump_with_schema_search_path
@configuration['schema_search_path'] = 'foo,bar'

Kernel.expects(:system).with('pg_dump', '-s', '-x', '-O', '-f', @filename, '--schema=foo --schema=bar', 'my-app-db').returns(true)
Kernel.expects(:system).with('pg_dump', '-s', '-x', '-O', '-f', @filename, '--schema=foo', '--schema=bar', 'my-app-db').returns(true)

ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, @filename)
end
Expand All @@ -228,7 +228,7 @@ def test_structure_dump_with_schema_search_path_and_dump_schemas_all
end

def test_structure_dump_with_dump_schemas_string
Kernel.expects(:system).with("pg_dump", '-s', '-x', '-O', '-f', @filename, '--schema=foo --schema=bar', "my-app-db").returns(true)
Kernel.expects(:system).with("pg_dump", '-s', '-x', '-O', '-f', @filename, '--schema=foo', '--schema=bar', "my-app-db").returns(true)

with_dump_schemas('foo,bar') do
ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, @filename)
Expand Down