Skip to content

Instantly share code, notes, and snippets.

@wullemsb
Created June 12, 2019 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wullemsb/45f31bb7cbd04b9645af35813762e0d9 to your computer and use it in GitHub Desktop.
Save wullemsb/45f31bb7cbd04b9645af35813762e0d9 to your computer and use it in GitHub Desktop.
if (!Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT").Equals("local", StringComparison.OrdinalIgnoreCase))
{
var serviceProvider = services.BuildServiceProvider();
using (var ctx = serviceProvider.GetService<SampleContext>())
{
var pendingMigrations = ctx.Database.GetPendingMigrations().ToList();
if (pendingMigrations.Any())
{
throw new Exception(
$@"Please contact the administrator. The following database migrations are pending:
{string.Join(Environment.NewLine, pendingMigrations)}
");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment