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

Tweak db prepare/migrate/seed for multiple gateways #234

Merged
merged 10 commits into from
Sep 24, 2024

Conversation

timriley
Copy link
Member

@timriley timriley commented Sep 24, 2024

Fix a range of issues detected during manual testing with a (soon-to-be) 2.2.beta2 app with multiple DB gateways configured for the app:

  • db prepare was failing, since the ROM/Sequel migrator needs every configured getaway to have its database created before the migrator can run. To fix this, change the order of the nested db prepare commands, so that db create and db structure load are run first for every detected database. After that is done, move onto db migrate for each detected database. Finally, run db seed.
  • Given that db prepare now runs commands in a mixed order (i.e. no longer a single slice at a time), change the handling of command failures such that they halt and exit the entire command immediately. This should make it easier for the user to identify and address failures, and reduces the chance of unexpected outcomes from latter steps being impacted by earlier failures.
  • db seed should run only once for each slice, but our internal #databases method will yield for each database, so when a slice has multiple gateways, we were trying to seed it multiple times. To fix this, track the seeded slices and skip seeding for subsequence detected databases if the slice has already been seeded.
  • Various errors were raised from the ROM/Sequel migrator if a gateway is configured but does not yet have a real migrations dir (e.g. config/db/[gateway_name]_migrate/). This would occur in both db migrate as well as db structure dump (which uses the migrator to know the applied migrations to include at the bottom of the structure file). To fix these, skip attempting to load the migrator for a gateway database if there is no matching migration dir found.
  • Update the warnings around empty migration paths to respect the naming of migration dirs for gateways.
  • Fix bug arising in db prepare from us accidentally assigning the fs as a DB command's inflector.

I've updated the existing db prepare specs to reflect this new behaviour, where applicable. We would do well to add another couple of examples for the edge cases above (e.g. missing migration dirs), but I'm going to defer those until later, so we don't delay a timely 2.2.0.beta2 release this week. See #235 as a reminder to come back and add those tests.

If the migrations dir does not exist, do not attempt to find applied migrations and append them to the structure dump file.

This avoids an error from the ROM/Sequel migrator about missing migration dirs.
This avoids an error from the ROM/Sequel migrator for a missing migrations dir.
This makes the command simpler to understand, especially now that we’re intermingling the order of operations (e.g. creating dbs first for each slice, then migrating for each slices, etc.)
@timriley timriley changed the title Tweak db prepare/db migrate for for multiple gateways Tweak db prepare/migrate/seed for multiple gateways Sep 24, 2024
@timriley timriley merged commit d778ac3 into main Sep 24, 2024
6 checks passed
@timriley timriley deleted the fix-db-prepare-migrate-for-multiple-gateways branch September 24, 2024 10:45
@timriley timriley self-assigned this Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant