Skip to content

Commit

Permalink
Add Ensure Created/Deleted methods on DbMigrationProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitrietataru committed May 14, 2024
1 parent 93bfee4 commit 34189ca
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
18 changes: 0 additions & 18 deletions src/CatNip.Infrastructure/Data/Migrations/DbMigrationProvider.cs

This file was deleted.

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ namespace CatNip.Infrastructure.Data.Migrations;
public interface IDbMigrationProvider
{
Task MigrateAsync(CancellationToken cancellation = default);

Task EnsureCreatedAsync(CancellationToken cancellation = default);
Task EnsureDeletedAsync(CancellationToken cancellation = default);
}

0 comments on commit 34189ca

Please sign in to comment.