❔ Conditional data seedHi !
Currently working on an api where we're trying to manage two different builds (foo and bar)
Foo is using an hellish hybrid database with a bit of SQL (ef core code first), noSQL and a Sequential indexed file database
Bar is using a pure SQL database (EF Core code first)
We already split the DAL so that services from Foo and Bar uses the same interface (calling their respective databases in their implementations)
Foo and Bar are using the same migrations from our repository manager.
But now, we want to use a set of initial data with Bar
We though about doing a migration and adding some insert in raw sql in them
But, considering that Foo and Bar are using the same migrations and that Foo doesn't want those data, we have to find a descent solution that would insert those into Bar while letting Foo untouched (descent meaning " at least maintainable short terms, if possible, maintainable long terms and ideally, not too hard to explain to newcomers in the team")
A solution I dug up over that StackOverflow post
https://stackoverflow.com/questions/37748859/is-it-possible-to-have-conditional-ef-migration-code sounds doable
(but considering it is 6y old and has only 2 answers where the top answer has only 1 upvote,... Yeah, Idk)
We'd have the migration in both Foo and Bar
But the raw sql in the Up and Down would be wrapped in some preprocessor conditions
Like so
protected override void Up(MigrationBuilder migrationBuilder)
{
#if Bar
migrationBuilder.Sql(@"
-- some raw sql where we insert data into the BAR database
")
#endif
}
If this solution doesn't look appealing to you...
Yeah...
To us neither...
That's why I'd like to have your opinion on how to tackle that issue, if you will 🙂