Use view without namespace when dumping schema. #327
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why?
Without this, default behavior of
rake db:schema:load
is broken because ActiveRecord config optionschema_search_path
for Postgres adapters is automatically used to identify where is theview
being loaded to; By explicitly adding the namespace/search_path in the schema.rb it's wrong as you can runrake db:migrate
from multiple computers and configurations which can result innamespace_from_pc_1.view_name
andnamespace_from_pc_2.view_name
on different commits.Scenarios with issues
database.yml
using an environment variable such asschema_search_path: <%= ENV['PG_DB_SCHEMA'] %>
my_view
export PG_DB_SCHEMA=my_schema_1
export PG_DB_SCHEMA=my_schema_2
rake db:migrate
which generates "my_schema_1.my_view" on schema.rbrake db:migrate
which generates "my_schema_2.my_view" on schema.rbPG_DB_SCHEMA=my_ci_schema_3
runrake db:schema:load
, it fails.Changes
Extra
An additional justification is that
schema.rb
does not include namespaces ever, and the default Rails/Activerecord behavior should be conserved.Fixes: #325