fix AutoMigrationCreator

This commit is contained in:
Vashchuk Nikita 2022-07-08 14:19:13 +03:00
parent 5f7b346334
commit 841dd52eac
5 changed files with 27 additions and 27 deletions

View File

@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Webhooks.Core", "common
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.MessagingSystem", "common\ASC.MessagingSystem\ASC.MessagingSystem.csproj", "{E37086CF-3E93-475F-BE0D-A77EE144D9B9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.EventBus.Extensions.Logger", "common\ASC.EventBus.Extensions.Logger\ASC.EventBus.Extensions.Logger.csproj", "{254E71BE-4BA7-4CF4-8B35-162E46C53D71}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -51,6 +53,10 @@ Global
{E37086CF-3E93-475F-BE0D-A77EE144D9B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E37086CF-3E93-475F-BE0D-A77EE144D9B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E37086CF-3E93-475F-BE0D-A77EE144D9B9}.Release|Any CPU.Build.0 = Release|Any CPU
{254E71BE-4BA7-4CF4-8B35-162E46C53D71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{254E71BE-4BA7-4CF4-8B35-162E46C53D71}.Debug|Any CPU.Build.0 = Debug|Any CPU
{254E71BE-4BA7-4CF4-8B35-162E46C53D71}.Release|Any CPU.ActiveCfg = Release|Any CPU
{254E71BE-4BA7-4CF4-8B35-162E46C53D71}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -25,19 +25,21 @@
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using AutoMigrationCreator.Core;
namespace AutoMigrationCreator;
public class MigrationCreator
public static class MigrationCreator
{
public static void RunCreateMigrations()
{
var counter = 0;
var solution = new Solution();
foreach (var projectInfo in solution.GetProjects())
foreach (var projectInfo in Solution.GetProjects())
{
var ctxTypesFinder = new ProjectInfoContextFinder(projectInfo);
@ -67,9 +69,8 @@ public class MigrationCreator
public static void RunApplyMigrations(string path)
{
var counter = 0;
var solution = new Solution();
foreach (var assembly in solution.GetAssemblies(path))
foreach (var assembly in GetAssemblies(path))
{
var ctxTypesFinder = new AssemblyContextFinder(assembly);
@ -85,4 +86,14 @@ public class MigrationCreator
Console.WriteLine($"Applied {counter} migrations");
}
private static IEnumerable<Assembly> GetAssemblies(string path)
{
var assemblyPaths = Directory.GetFiles(path, "ASC.*.dll");
foreach (var assembly in assemblyPaths)
{
yield return Assembly.LoadFrom(assembly);
}
}
}

View File

@ -37,7 +37,7 @@ namespace AutoMigrationCreator;
public class ModelDifferenceChecker
{
private BaseDbContext _dbContext;
private readonly BaseDbContext _dbContext;
public ModelDifferenceChecker(BaseDbContext context)
{
_dbContext = context;
@ -58,7 +58,7 @@ public class ModelDifferenceChecker
var lastModel = scaffolderDependecies.SnapshotModelProcessor.Process(modelSnapshot.Model)
.GetRelationalModel();
if (modelSnapshot == null)
if (lastModel == null)
{
return true;
}

View File

@ -33,11 +33,11 @@ using Microsoft.Build.Construction;
namespace AutoMigrationCreator.Core;
public class Solution
public static class Solution
{
private const string SOLUTION_NAME = "ASC.Tools.sln";
public IEnumerable<ProjectInfo> GetProjects()
public static IEnumerable<ProjectInfo> GetProjects()
{
var solutionPath = Path.GetFullPath(Path.Combine("..", "..", "..", "..", "..", "..", SOLUTION_NAME));
var source = SolutionFile.Parse(solutionPath);
@ -52,14 +52,4 @@ public class Solution
Path = p.AbsolutePath.Replace($"{p.ProjectName}.csproj", string.Empty)
});
}
public IEnumerable<Assembly> GetAssemblies(string path)
{
var assemblyPaths = Directory.GetFiles(path, "ASC.*.dll");
foreach (var assembly in assemblyPaths)
{
yield return Assembly.LoadFrom(assembly);
}
}
}

View File

@ -25,10 +25,6 @@
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutoMigrationCreator.Utils;
public static class ArgsParser
@ -43,10 +39,7 @@ public static class ArgsParser
throw new Exception("Incorrect combination of parameters. First parametr: string path, Second parametr: bool created");
}
if (args.Length < 2)
{
path = args[0];
}
path = args[0];
if (args.Length == 2)
{