Root Question Message

❔ Conditional data seed

Hi !
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
       -- some raw sql where we insert data into the BAR database

If this solution doesn't look appealing to you...
To us neither...
That's why I'd like to have your opinion on how to tackle that issue, if you will 🙂
I don't know much about the ways you can manage migrations in efcore, but I'd do like 3 folders, a common one and one for project specific migrations. Then you have to make sure they are called in the right order, so some order metadata would be necessary
That looks like a sound idea
thank you 🙂
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy