arielorvits arielorvits - 3 months ago 10
ASP.NET (C#) Question

how Database.Migrate() method work? can it downgrade database?

I can't find official documentation of this method.
All I found is that it apply migrations that didn't applied yet (and create db if not exists).
but how it work?
is it look at the db Migration History table to see which migration missed?
and what if somehow it see that Migration History table has more migrations than in migrations folder? is it downgrade them?

thanks!

Answer

Does it look at the db Migration History table to see which migration are missing?

Yes, and applies any missing migrations in chronological order.

What if somehow it sees that the Migration History table has more migrations than in the migrations folder? Does it revert them?

It does nothing. They might be for a different model/DbContext/application that is using the same database.