Created
January 14, 2026 20:43
-
-
Save ssougnez/81a3f5bc2a44d2fbd8554752a5ea8ff1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AppMigrationEngine: BaseMigrationEngine | |
| { | |
| private readonly AppDbContext _db; | |
| public AppMigrationEngine(AppDbContext db) | |
| { | |
| _db = db; | |
| } | |
| public override async Task <IEnumerable<Version>> GetAppliedVersionsAsync() | |
| { | |
| // Important: this method is called BEFORE EF Core migrations run. | |
| // On a fresh database, your table won't exist yet. | |
| if (!await _db.Database.CanConnectAsync()) return []; | |
| try | |
| { | |
| return await _db.MigrationHistory.Select(m => m.Version).ToListAsync(); | |
| } | |
| catch | |
| { | |
| return []; | |
| } | |
| } | |
| public override async Task RegisterVersionAsync(Version version) | |
| { | |
| _db.MigrationHistory.Add(new MigrationRecord | |
| { | |
| Version = version, | |
| AppliedAt = DateTime.UtcNow | |
| }); | |
| await _db.SaveChangesAsync(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment