Код: Выделить всё
// Apply migrations / create database on startup
using (var scope = app.Services.CreateScope())
{
var logger = scope.ServiceProvider.GetRequiredService();
logger.LogInformation("Starting database migration. Environment: {Environment}", app.Environment.EnvironmentName);
try
{
var dbFactory = scope.ServiceProvider.GetRequiredService();
var db = dbFactory.CreateAssortmentDbContext();
if (db.Database.IsRelational())
{
logger.LogInformation("Applying migrations...");
db.Database.Migrate();
logger.LogInformation("Migrations applied successfully.");
}
else
{
db.Database.EnsureCreated();
}
//CREATE CUSTOM TABLE TYPES
_ = db.Database.ExecuteSqlRaw(ProductVariantType.Create);
_ = db.Database.ExecuteSqlRaw(SalesAccountType.Create);
logger.LogInformation("Database setup completed successfully.");
}
catch (Exception ex)
{
logger.LogError(ex, "An error occurred while migrating the database.");
throw;
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... d-to-azure