I found the basis for something similar that this would work. Itโs a hack, but Iโll post it here because I know that others wanted something like that, judging by the other issues Iโm involved with.
The idea is to link another migration command that can be run from the package manager and which will not change the database itself - I will use Get-Migrations
. This will allow the package manager team to do the hard work of finding the right configurations, loading the right assemblies, etc. I will contact this command by invoking my cleanup code from the constructor of my subclass DbMigrationsConfiguration. I only want to run the cleanup code intentionally, and not every time the configuration is configured, so I will also check the sentinel environment variable before running the cleanup code. Later, I plan to move the cleanup code from Seed () to separate it from the actual seeding, but as others have asked to manually run Seed () in the past, I will use this as an example here.
I changed my subclass of DbMigrationsConfiguration as follows:
internal sealed class Configuration : DbMigrationsConfiguration<TimsDB> { public Configuration() { if ("true".Equals(Environment.GetEnvironmentVariable("RUN_SEED"))) using (TimsDB db = new TimsDB()) { Database.SetInitializer<TimsDB>(null); Seed(db); } } } ... }
This can then be used to manually call the Seed () method from the package manager:
PM> $Env:RUN_SEED = "true" PM> Get-Migrations PM> $Env:RUN_SEED = "false"
source share