| | | 1 | | using Microsoft.EntityFrameworkCore.Metadata; |
| | | 2 | | using Microsoft.EntityFrameworkCore.Migrations; |
| | | 3 | | using Microsoft.EntityFrameworkCore.Infrastructure; |
| | | 4 | | |
| | | 5 | | namespace Syki.Back.Extensions; |
| | | 6 | | |
| | | 7 | | public static class SykiDbContextExtensions |
| | | 8 | | { |
| | | 9 | | public static bool HasMissingMigration(this SykiDbContext context) |
| | | 10 | | { |
| | 2 | 11 | | var modelDiffer = context.GetService<IMigrationsModelDiffer>(); |
| | | 12 | | |
| | 2 | 13 | | var migrationsAssembly = context.GetService<IMigrationsAssembly>(); |
| | 2 | 14 | | var modelInitializer = context.GetService<IModelRuntimeInitializer>(); |
| | | 15 | | |
| | 2 | 16 | | var snapshotModel = migrationsAssembly.ModelSnapshot?.Model; |
| | 2 | 17 | | if (snapshotModel is IMutableModel mutableModel) |
| | 2 | 18 | | snapshotModel = mutableModel.FinalizeModel(); |
| | 2 | 19 | | if (snapshotModel is not null) |
| | 2 | 20 | | snapshotModel = modelInitializer.Initialize(snapshotModel); |
| | | 21 | | |
| | 2 | 22 | | var designTimeModel = context.GetService<IDesignTimeModel>(); |
| | | 23 | | |
| | 2 | 24 | | return modelDiffer.HasDifferences( |
| | 2 | 25 | | snapshotModel?.GetRelationalModel(), |
| | 2 | 26 | | designTimeModel.Model.GetRelationalModel()); |
| | | 27 | | } |
| | | 28 | | } |