| | | 1 | | using System.Diagnostics.CodeAnalysis; |
| | | 2 | | using System.Reflection; |
| | | 3 | | using Microsoft.EntityFrameworkCore; |
| | | 4 | | using Microsoft.EntityFrameworkCore.Diagnostics; |
| | | 5 | | using Microsoft.EntityFrameworkCore.Infrastructure; |
| | | 6 | | using Microsoft.EntityFrameworkCore.Migrations; |
| | | 7 | | using Microsoft.EntityFrameworkCore.Migrations.Internal; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Persistence.EFCore; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Class That enable Schema change for Migration |
| | | 13 | | /// </summary> |
| | | 14 | | [SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "Required to customize migration assembl |
| | | 15 | | public class DbSchemaAwareMigrationAssembly( |
| | | 16 | | ICurrentDbContext currentContext, |
| | | 17 | | IDbContextOptions options, |
| | | 18 | | IMigrationsIdGenerator idGenerator, |
| | | 19 | | IDiagnosticsLogger<DbLoggerCategory.Migrations> logger) |
| | 6 | 20 | | : MigrationsAssembly(currentContext, options, idGenerator, logger) |
| | | 21 | | { |
| | 6 | 22 | | private readonly DbContext _context = currentContext.Context; |
| | | 23 | | |
| | | 24 | | public override Migration CreateMigration(TypeInfo migrationClass, string activeProvider) |
| | | 25 | | { |
| | 44 | 26 | | if (activeProvider == null) |
| | 0 | 27 | | throw new ArgumentNullException(nameof(activeProvider)); |
| | | 28 | | |
| | 44 | 29 | | var hasCtorWithSchema = migrationClass.GetConstructor([typeof(IElsaDbContextSchema)]) != null; |
| | | 30 | | |
| | 44 | 31 | | if (hasCtorWithSchema && _context is IElsaDbContextSchema schema) |
| | | 32 | | { |
| | 44 | 33 | | var instance = (Migration)Activator.CreateInstance(migrationClass.AsType(), schema)!; |
| | 44 | 34 | | instance.ActiveProvider = activeProvider; |
| | 44 | 35 | | return instance; |
| | | 36 | | } |
| | | 37 | | |
| | 0 | 38 | | return base.CreateMigration(migrationClass, activeProvider); |
| | | 39 | | } |
| | | 40 | | } |