Only connect SecondaryRecord to secondary DB when MULTI_DB_TEST is set#318
Conversation
## Problem
`database.yml` defines the `secondary` database configuration only when `MULTI_DB_TEST=true`.
However, `SecondaryRecord` always declares:
```rb
connects_to database: { writing: :secondary }
```
As a result, running `annotaterb models` without `MULTI_DB_TEST` set raised the following error:
```sh
Unable to process app/models/secondary/test_default.rb: The secondary database is not
configured for the development environment.
```
## Solution
Make `SecondaryRecord` connect to the `secondary` database only when `MULTI_DB_TEST=true` is set.
When `MULTI_DB_TEST` is not set, `SecondaryRecord` falls back to the primary connection. Since it is an abstract class and its child class `Secondary::TestDefault` does not have a corresponding table in the primary database, both are safely skipped by annotaterb.
b41557b to
b2b1458
Compare
|
This makes sense to me, but are there tests that test this change? I would think that this would break some tests -- but it could be we don't have them to test the secondary database. |
|
Thank you for reviewing.
The existing multi-database tests all run with MULTI_DB_TEST=true, so they continue to pass as before. The single-database integration tests already cover the case without it.
We do have them in annotate_models_in_multi_db_spec.rb — they just always set MULTI_DB_TEST=true, so this change doesn't affect them. Let me know if I'm misunderstanding anything! |
|
Thanks for reviewing this. I’ll go ahead and merge it. |
Problem
database.ymldefines thesecondarydatabase configuration only whenMULTI_DB_TEST=true.However,
SecondaryRecordalways declares:As a result, running
annotaterb modelswithoutMULTI_DB_TESTset raised the following error:Unable to process app/models/secondary/test_default.rb: The secondary database is not configured for the development environment.Solution
Make
SecondaryRecordconnect to thesecondarydatabase only whenMULTI_DB_TEST=trueis set.When
MULTI_DB_TESTis not set,SecondaryRecordfalls back to the primary connection. Since it is an abstract class and its child classSecondary::TestDefaultdoes not have a corresponding table in the primary database, both are safely skipped by annotaterb.This change only affects the test dummy app (
spec/dummyapp/) and does not impact the gem’s runtime behavior.