< Summary

Class:SVETA.Api.Helpers.MigrationManager
Assembly:SVETA.Api
File(s):/opt/dev/sveta_api_build/SVETA.Api/Helpers/MigrationManager.cs
Covered lines:0
Uncovered lines:23
Coverable lines:23
Total lines:47
Line coverage:0% (0 of 23)
Covered branches:0
Total branches:4
Branch coverage:0% (0 of 4)

Metrics

MethodLine coverage Branch coverage
MigrationDatabase(...)0%0%

File(s)

/opt/dev/sveta_api_build/SVETA.Api/Helpers/MigrationManager.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Threading.Tasks;
 5using AutoMapper.Configuration;
 6using Microsoft.EntityFrameworkCore;
 7using Microsoft.Extensions.DependencyInjection;
 8using Microsoft.Extensions.Hosting;
 9using Microsoft.Extensions.Logging;
 10using Microsoft.Extensions.Options;
 11using SVETA.Api.Data.Domain;
 12using WinSolutions.Sveta.Server.Data.DataModel.Contexts;
 13
 14namespace SVETA.Api.Helpers
 15{
 16    public static class MigrationManager
 17    {
 18        public static IHost MigrationDatabase(this IHost host)
 019        {
 20
 021            using (var scope = host.Services.CreateScope())
 022            {
 023                var env = scope.ServiceProvider.GetRequiredService<IHostEnvironment>();
 024                var migrateConf = scope.ServiceProvider.GetService<IOptions<MigrateSettings>>();
 025                string migrateEnv = migrateConf.Value.MigrateEnv;
 026                if (migrateEnv != null && migrateEnv.Split(",").Contains(env.EnvironmentName))
 027                {
 028                    using (var context = scope.ServiceProvider.GetRequiredService<SvetaDbContext>())
 029                    {
 030                        var logger = scope.ServiceProvider.GetRequiredService<ILogger<IHost>>();
 31                        try
 032                        {
 033                            context.Database.Migrate();
 034                        }
 035                        catch (Exception e)
 036                        {
 037                            logger.LogError(e, e.Message);
 038                            throw;
 39                        }
 040                    }
 041                }
 042            }
 43
 044            return host;
 045        }
 46    }
 47}

Methods/Properties

MigrationDatabase(...)