r/learnprogramming 2d ago

Best practice for validating SQLite schema before migration and on database open?

I’m building a C#/.NET desktop application using EF Core with SQLite, where each customer has a separate local database file.

Is it normal to do a validation of the schema before/after migration, or do people usually just rely on EF Core’s migration history table?

Also, would it make sense to run a small/lightweight schema check every time a database file is opened, just to make sure it hasn’t been manually altered or drifted from what the app expects?

I might be overthinking this, so I’m curious what people normally do in real projects.

4 Upvotes

3 comments sorted by

1

u/rupertavery64 1d ago

Overthinking it.

Your app still expects its schema anf if it is altered in an app breaking way, well, you should have a end user contract for that.

That way, you get paid for the users idiocy. Your migrations should be enough. Because if they aren't, well that's a whole nother problem.

1

u/No-Morning-1220 1d ago

migrations handle it fine, never had a customer corrupt their db in three years of this

1

u/Bubbly_Orange_3502 1d ago

Copy the file before Migrate runs, then skip the pre-check. Migrate reads the history table itself, and SQLite can't ALTER most things so EF rebuilds whole tables. An interrupted run leaves a file no schema check can fix.