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

Move db and shard selector initalizer to Railties #45368

Conversation

eileencodes
Copy link
Member

In #45162 it was discovered that the multi_db generator that was created
for 7.0 doesn't work correctly because that file is loaded after the
initializer in active record is run. I tried moving everything to an
after_initialize but the middleware stack is frozen at that point. I
also attempted to fix this in #45353 but it just didn't feel right to
have to deprecate this behavior that should work.

I then realized that most of the middleware in Rails is installed in the
middleware stack file in railties. If I move the middleware installation
to this file, everything works as necessary.

The only caveat is we need to check if config responds to
active_record but I think that should be fine - we already do that in
the framework defaults configuration.

Fixes #45162

In rails#45162 it was discovered that the multi_db generator that was created
for 7.0 doesn't work correctly because that file is loaded _after_ the
initializer in active record is run. I tried moving everything to an
after_initialize but the middleware stack is frozen at that point. I
also attempted to fix this in rails#45353 but it just didn't feel right to
have to deprecate this behavior that _should_ work.

I then realized that most of the middleware in Rails is installed in the
middleware stack file in railties. If I move the middleware installation
to this file, everything works as necessary.

The only caveat is we need to check if `config` responds to
`active_record` but I think that should be fine - we already do that in
the framework defaults configuration.

Fixes rails#45162
@eileencodes eileencodes force-pushed the move-db-and-shard-selector-middleware-to-railtie branch from 6c7761d to d179383 Compare June 15, 2022 16:26
@eileencodes eileencodes merged commit fd0f114 into rails:main Jun 15, 2022
@eileencodes eileencodes deleted the move-db-and-shard-selector-middleware-to-railtie branch June 15, 2022 17:27
eileencodes added a commit that referenced this pull request Jun 15, 2022
…-middleware-to-railtie

Move db and shard selector initalizer to Railties
@eileencodes
Copy link
Member Author

Backported to 7-0-stable in 7f5015a

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.

config/initializers/multi_db doesn't work
1 participant