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

Add config.active_record.dump_schemas. #19347

Merged
merged 1 commit into from Mar 17, 2015
Merged

Conversation

rywall
Copy link
Contributor

@rywall rywall commented Mar 15, 2015

Fixes db:structure:dump when using schema_search_path and PostgreSQL extensions.

Closes #17157.

@rywall
Copy link
Contributor Author

rywall commented Mar 15, 2015

@senny @jimmykarily Here is a first pass. Feedback appreciated. :)

# Specifies which database schemas to dump when calling db:structure:dump.
# If :schema_search_path, it will dumps any schemas listed in schema_search_path.
# Use :all to always dumps all schemas regardless of the schema_search_path.
# A string of comma separated schemas can also be used to pass a custom list of schemas.
Copy link
Member

@senny senny Mar 16, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs should mention the default value.

Copy link
Contributor Author

@rywall rywall Mar 16, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to model it after the documentation for schema_format (above) which doesn't specify the default in the doc. Should I change both?

Copy link
Member

@senny senny Mar 17, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's focus on this change for now. If you have time, you can update the other in a separate PR.

Copy link
Contributor Author

@rywall rywall Mar 17, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@senny
Copy link
Member

senny commented Mar 16, 2015

@rywall looking good. Do you think you could add test-cases for this new functionality?

@jimmykarily
Copy link

jimmykarily commented Mar 16, 2015

👍

@rywall
Copy link
Contributor Author

rywall commented Mar 16, 2015

@senny I've added some tests. Anything else?

end

def test_structure_dump_with_dump_schemas_string
ActiveRecord::Base.dump_schemas = 'test'
Copy link
Member

@senny senny Mar 17, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use an example with two schemas as well.

Copy link
Contributor Author

@rywall rywall Mar 17, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@senny
Copy link
Member

senny commented Mar 17, 2015

@rywall I added a couple comments. Thank you for your work on this 💛

Fixes db:structure:dump when using schema_search_path and PostgreSQL
extensions.

Closes rails#17157.
@rywall
Copy link
Contributor Author

rywall commented Mar 17, 2015

I've refactored the tests to avoid side effects. I think I've addressed all you other comments as well. Thanks for your feedback. The pull request is much better for it. 👍

senny added a commit that referenced this pull request Mar 17, 2015
Add config.active_record.dump_schemas.
@senny senny merged commit ec85089 into rails:master Mar 17, 2015
@senny
Copy link
Member

senny commented Mar 17, 2015

@rywall awesome! Thank you for your work 💛

@jimmykarily
Copy link

jimmykarily commented Mar 18, 2015

Thanks!

@rywall rywall deleted the dump-schemas-config branch Apr 17, 2015
@GUI
Copy link
Contributor

GUI commented Nov 13, 2015

Thanks, @rywall! If anyone else stumbles upon this and would find this functionality useful in Rails 3 or Rails 4, I created a gem to backport this functionality to those versions of Rails: https://github.com/GUI/activerecord-postgres-dump-schemas

@njakobsen
Copy link
Contributor

njakobsen commented Jan 23, 2016

❤️ @GUI.

@NikolayS
Copy link

NikolayS commented May 18, 2017

Thanks for this.

Any plans to support pg_dump's --exclude-schema as well?

In some cases, it might be more convenient to have a "black list", not a "white" one.

@rainhead
Copy link

rainhead commented Oct 16, 2017

For anyone looking for a way to dump extensions along with a subset of schemas, or otherwise needing extra control over pg_dump, set ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags:

ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = %w{
  --exclude-schema=schema2
  --exclude-schema=schema3
}

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.

No extensions in structure.sql when schema_search_path is defined
8 participants