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

Conversation

GUI
Copy link
Contributor

@GUI GUI commented Nov 19, 2015

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.

This is due to the changes made in #17885 The problem is that multiple schemas were getting getting passed to Kernel.system as a single, space delimited string argument (for example, "--schema=foo --schema=bar"). However, with the updated array style of calling Kernel.system, these need to be passed as separate arguments (for example, "--schema=foo", "--schema=bar"). If they get passed as a single string, then the underlying pg_dump program isn't sure how to interpret that single argument and you'll get an error like:

pg_dump: No matching schemas were found
rake aborted!
failed to execute:
pg_dump -s -x -O -f structure.sql --schema=foo --schema=bar my-app-db


Please check the output above for any errors and make sure that `pg_dump` is installed in your PATH and has proper permissions.

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.

This is due to the changes made in
rails#17885 The problem is that multiple
schemas were getting getting passed to `Kernel.system` as a single,
space delimited string argument (for example, "--schema=foo
--schema=bar"). However, with the updated array style of calling
`Kernel.system`, these need to be passed as separate arguments (for
example, "--schema=foo", "--schema=bar"). If they get passed as a single
string, then the underlying pg_dump program isn't sure how to interpret
that single argument and you'll get an error reporting: "pg_dump: No
matching schemas were found"
@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @carlosantoniodasilva (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@masterkain
Copy link
Contributor

related #22346

@senny
Copy link
Member

senny commented Nov 30, 2015

r? @senny

@senny senny merged commit d1dcdf2 into rails:master Nov 30, 2015
senny added a commit that referenced this pull request Nov 30, 2015
Fix rake db:structure:dump on Postgres when multiple schemas are used

Conflicts:
	activerecord/CHANGELOG.md

Closes #22346.
senny added a commit that referenced this pull request Nov 30, 2015
Fix rake db:structure:dump on Postgres when multiple schemas are used

Conflicts:
	activerecord/CHANGELOG.md

Closes #22346.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/tasks/postgresql_rake_test.rb
@senny
Copy link
Member

senny commented Nov 30, 2015

@GUI thank you for the fix. I did a backport to 4-2-stable.

@GUI
Copy link
Contributor Author

GUI commented Nov 30, 2015

Thanks for the merge and backport!

@GUI
Copy link
Contributor Author

GUI commented Jan 28, 2016

If anyone else is needing this functionality in Rails 4.2.5 (namely to get the security updates in 4.2.5.1), I put together a quick gem to monkey-patch this functionality for Rails 4.2.5: https://github.com/GUI/rails_425_structure_dump_patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants