-
Notifications
You must be signed in to change notification settings - Fork 460
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
Updated database connection handling via pg_dump. #128
base: development
Are you sure you want to change the base?
Conversation
# read database config | ||
db_config = Rails.configuration.database_configuration.fetch Rails.env | ||
db_name = db_config['database'] | ||
db_host = db_config['socket'] ? File.dirname(db_config['socket']) : db_config['host'] || 'localhost' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [108/80]
+1 |
From what I can see here, the problem with the excluded models is not really being fixed by leaving out those models when dumping/restoring. Now your FK constraints won't be prepended by the schema unless they point to a table in a different schema, than the one you dump from. Let me give an example: Let's say you have an excluded model called --
-- PostgreSQL database dump
--
--
-- Name: food_blog; Type: SCHEMA; Schema: -; Owner: -
--
CREATE SCHEMA food_blog;
--
-- Name: SCHEMA food_blog; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON SCHEMA IS 'standard public schema';
SET search_path = food_blog;
(...)
--
-- Name: posts_user_id_fk; Type: FK CONSTRAINT; Schema: food_blog; Owner: -
--
ALTER TABLE ONLY posts
ADD CONSTRAINT posts_user_id_fk FOREIGN KEY (users_id) REFERENCES users(id);
Now we have a problem, because when creating the new schema ALTER TABLE ONLY posts
ADD CONSTRAINT posts_user_id_fk FOREIGN KEY (users_id) REFERENCES wine_blog.users(id); However that is never going to happen, because the wine_blog is your Now to get the right behavior, you would have to move all excluded models into a different schema (e.g. To wrap up, the best idea is probably to leave the excluded models in all schemas, then make sure, that your FK's referring to excluded models, refer to the excluded model tables residing in the Do you follow me? |
as a workaround for those waiting on this PR, pg_dump and friends support a variety of environment variables (e.g. PGUSER, PGPORT, etc.). when coupled with something like dotenv you can still keep all your db config in one place (e.g. database.yml could also pull from env vars) |
# schema. In that case FK on 'tenant.tableA' references to | ||
# non-existing row in 'tenant.tableB', but should ref. to | ||
# 'public.tableB', that's why tables from excluded models shouldn't | ||
# be copied to tenant schemes.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made an alternative to this: #182
…into development Conflicts: apartment.gemspec lib/apartment/adapters/postgresql_adapter.rb
Prepare Release - 2.8.1 **Implemented enhancements:** **Fixed bugs:** - New version raises an error with ActiveSupport::LogSubscriber [influitive#128](rails-on-services/apartment#128) - Weird logs when tenant fails to create [influitive#127](<rails-on-services/apartment#127>) **Closed issues:** - Removed travis and slim configured circleci [influitive#130](rails-on-services/apartment#130)
Connection arguments for
pg_dump
command are built from Rails.configuration.database_configuration` for current environment.This reflects only on
PostgresqlSchemaFromSqlAdapter
.