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

Refactor for_each(databases) code #38658

Merged

Conversation

eileencodes
Copy link
Member

While working on something else I noticed this code was duplicated. It
was returning name from for_each and then we'd have to lookup the
db_config again from the name and env. We can instead just return
db_config from for_each and clean up these tasks a little bit.

While working on something else I noticed this code was duplicated. It
was returning `name` from `for_each` and then we'd have to lookup the
`db_config` again from the `name` and `env`. We can instead just return
`db_config` from `for_each` and clean up these tasks a little bit.
@eileencodes eileencodes merged commit 9a5bc24 into rails:master Mar 5, 2020
@eileencodes eileencodes deleted the refactor-for-each-databases-code branch March 5, 2020 19:59
Copy link
Member

@rafaelfranca rafaelfranca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup!

eileencodes added a commit to eileencodes/rails that referenced this pull request Mar 5, 2020
…each-databases-code"

This reverts commit 9a5bc24, reversing
changes made to 227ff44.

I realized afterwards that this was written this way for a reason and it
wasn't accidental. The databases loaded in `for_each` are not complete
database configs because these are generated from the database yaml
before the Rails env is loaded. So we actually do need to refetch the
correct database configuration objects after we've loaded the Rails env.
@eileencodes
Copy link
Member Author

I had to revert this 😢 because I realized I wrote it this way on purpose.

See for explanation #38661. I don't have time right now to add a test but will do that tomorrow so I don't forget again in 2 years why I wrote it this way.

eileencodes added a commit that referenced this pull request Mar 5, 2020
Revert "Merge pull request #38658 from eileencodes/refactor-for-each-…
eileencodes added a commit that referenced this pull request Mar 6, 2020
If I had had these tests previously I would have not created PR #38658
and then promptly realize I needed to revert it.

We need to load and parse the configurations twice. Once before the
environment is loaded to create the named tasks and once after the
environment is loaded to have the real configurations. The configs
loaded before the env have the ERB stripped out and aren't valid
configs.
@eileencodes
Copy link
Member Author

Added tests in 67b102a

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.

None yet

2 participants