-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Ensure Created/Deleted methods on DbMigrationProvider
- Loading branch information
1 parent
93bfee4
commit 34189ca
Showing
3 changed files
with
30 additions
and
18 deletions.
There are no files selected for viewing
18 changes: 0 additions & 18 deletions
18
src/CatNip.Infrastructure/Data/Migrations/DbMigrationProvider.cs
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
src/CatNip.Infrastructure/Data/Migrations/EFCoreMigrationProvider.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace CatNip.Infrastructure.Data.Migrations; | ||
|
||
public abstract class EFCoreMigrationProvider<TDbContext> : IDbMigrationProvider | ||
where TDbContext : DbContext | ||
{ | ||
protected EFCoreMigrationProvider(TDbContext dbContext) | ||
{ | ||
DbContext = dbContext; | ||
} | ||
|
||
protected virtual TDbContext DbContext { get; init; } | ||
|
||
public virtual async Task MigrateAsync(CancellationToken cancellation = default) | ||
{ | ||
await DbContext.Database.MigrateAsync(cancellation); | ||
} | ||
|
||
public virtual async Task EnsureCreatedAsync(CancellationToken cancellation = default) | ||
{ | ||
await DbContext.Database.EnsureCreatedAsync(cancellation); | ||
} | ||
|
||
public virtual async Task EnsureDeletedAsync(CancellationToken cancellation = default) | ||
{ | ||
await DbContext.Database.EnsureDeletedAsync(cancellation); | ||
} | ||
} |
This file contains 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