{"action":"created","issue":{"url":"https://api.github.com/repos/godaddy/apartment/issues/4","labels_url":"https://api.github.com/repos/godaddy/apartment/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/godaddy/apartment/issues/4/comments","events_url":"https://api.github.com/repos/godaddy/apartment/issues/4/events","html_url":"https://github.com/godaddy/apartment/pull/4","id":107402733,"number":4,"title":"track current db in Apartment.connection_config for accurate context management","user":{"login":"mtuckergd","id":4377828,"avatar_url":"https://avatars.githubusercontent.com/u/4377828?v=3","gravatar_id":"","url":"https://api.github.com/users/mtuckergd","html_url":"https://github.com/mtuckergd","followers_url":"https://api.github.com/users/mtuckergd/followers","following_url":"https://api.github.com/users/mtuckergd/following{/other_user}","gists_url":"https://api.github.com/users/mtuckergd/gists{/gist_id}","starred_url":"https://api.github.com/users/mtuckergd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtuckergd/subscriptions","organizations_url":"https://api.github.com/users/mtuckergd/orgs","repos_url":"https://api.github.com/users/mtuckergd/repos","events_url":"https://api.github.com/users/mtuckergd/events{/privacy}","received_events_url":"https://api.github.com/users/mtuckergd/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-09-20T16:32:51Z","updated_at":"2015-09-21T18:11:01Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/godaddy/apartment/pulls/4","html_url":"https://github.com/godaddy/apartment/pull/4","diff_url":"https://github.com/godaddy/apartment/pull/4.diff","patch_url":"https://github.com/godaddy/apartment/pull/4.patch"},"body":"This approach updates the `:target_database` value directly in the hash cached by ActiveRecord. I confirmed that our override to `ActiveRecord::ConnectionAdapters::ConnectionHandler` only considers host, database, and port (i.e. not the entire hash) for connection pooling, so modifying the `:target_database` value should not affect ActiveRecord behavior.\r\n\r\nThis approach is the cleanest from a code perspective, as I was even able to remove the `current_database_name` override in the mysql2 adapter and allow the value to always be pulled from `Apartment.current_config[:target_database]`. \r\nThat said, there's something creepy about changing the value in a cached hash. Thus, option2 was born. I'm open to either approach and defer to the group for our final solution."},"comment":{"url":"https://api.github.com/repos/godaddy/apartment/issues/comments/142064314","html_url":"https://github.com/godaddy/apartment/pull/4#issuecomment-142064314","issue_url":"https://api.github.com/repos/godaddy/apartment/issues/4","id":142064314,"user":{"login":"IrvinFan","id":5523239,"avatar_url":"https://avatars.githubusercontent.com/u/5523239?v=3","gravatar_id":"","url":"https://api.github.com/users/IrvinFan","html_url":"https://github.com/IrvinFan","followers_url":"https://api.github.com/users/IrvinFan/followers","following_url":"https://api.github.com/users/IrvinFan/following{/other_user}","gists_url":"https://api.github.com/users/IrvinFan/gists{/gist_id}","starred_url":"https://api.github.com/users/IrvinFan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IrvinFan/subscriptions","organizations_url":"https://api.github.com/users/IrvinFan/orgs","repos_url":"https://api.github.com/users/IrvinFan/repos","events_url":"https://api.github.com/users/IrvinFan/events{/privacy}","received_events_url":"https://api.github.com/users/IrvinFan/received_events","type":"User","site_admin":false},"created_at":"2015-09-21T18:11:01Z","updated_at":"2015-09-21T18:11:01Z","body":"That's a good point. But it doesn't help in favoriting option2 since `target_database` was introduced by us and it exists in option2 as well. Basically it comes down to if we can find a cleaner way to achieve this without messing around AR internal data."}}