Replies: 1 comment 1 reply
-
You identified the crux of the problem, it's currently impossible to make the database wait (because it currently doesn't have a lifecycle of its own). |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How are you thinking about doing DB Migrations with
WaitFor
. I've gone through a few iterations that either don't work, or don't work particularly cleanly.In my use case, we have a central database that is shared by several applications. (Potentially in the range of 50-100). So I'm trying to build up a reusable component that multiple teams can use to work with this database. Something that can be used like the following:
Migrations are done by a powershell script, although it could be any other executable (e.g.
dotnet ef database update
). The migrator is something like the following:Take 1
Simplest option is to have each consuming app wait on both the migrator and the database. This isn't a bad option if you only have one consumer of your database, but if you start having multiple consumers it becomes a bit of a pain passing around both the migrator and the database. It makes for a leaky abstraction if you're trying to make a helper hosting package to abstract that database away. Nor does it fit nicely into the existing hosting builder pattern (unless you start using out variables to return the second resource 🤮)
Take 2
I was hoping to be able to do something like the following, where the migrator waits on SQL, and the database then waits on the migrator completing. This didn't work with the 8.x WaitForDependencies extension as only resources with Environment (executables & containers) could wait on other resources. It has worked intermittently on 9.x, but with #5870 it looks like it is no longer expected to work.
As a variant of this, I looked to see if there was an event I could hook into to delay the database resource myself, but I couldn't find anything suitable - the
ResourceReadyEvent
is just a bit too late to work.Take 3
I've now gone back to the solution I was using in 8.x of using a Custom Resource. I have been able to replace a lot of the copy & paste from
WaitForDependenciesRunningHook.WaitForDependenciesRunningHook
with events that plug into 9.x's WaitFor.This option produces a clean API for consumers to use, however it does leak a bit on the dashboard as it now exposes two database resources. It is however rather awkward to have to break out into making custom resources as there's little documentation about making custom resources that don't inherit from Executable or Container resources (and even less about how to integrate them into
WaitFor
). Migrations feel like a common enough scenario that you shouldn't need to make a custom resource for migrations.Alternatives?
Do you have any other recommendations for how to do database migrations with WaitFor? Either modifications to one of the above approaches, or alternative suggestions.
Beta Was this translation helpful? Give feedback.
All reactions