dotnet / dotnet/efcore

Build a better way to manage custom migration operations

Open
#34,708 5 comments 1 reaction 0 assignees View on GitHub
area-migrations customer-reported needs-design
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

**Problem:**
Currently, it is common to call `.Sql()`, or make an extension method for `MigrationBuilder`, and call inside some generated migration when we need to execute some custom operation using the migration feature. That can become a problem on a scenario where resetting the migration history is required, since one would have to review all migrations in search of custom calls.

Seeding of data, creation of procedures, views, full-text catalogs and any other model changes operation that is not natively supported by Entity Framework Core can be easily lost.

**Proposal:**
What I propose is that we build a feature for managing custom commands similar to entities fluent API configuration and EF should include these custom commands in the migrations and snapshot as well update when something changes.

So, just like we can do:
`modelBuilder.Entity().SomeConfiguration();`

Or:
```csharp
public void SomeEntityConfiguration : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.SomeConfiguration();
}
}
```

We would do:
`modelBuilder.Custom().RunSql("CREATE FULLTEXT CATALOG ftCatalog AS DEFAULT;");`

Or:
```csharp
public void SomeEntityConfiguration : ICustomTypeConfiguration
{
public void Configure(CustomTypeBuilder builder)
{
builder.RunSql("CREATE FULLTEXT CATALOG ftCatalog AS DEFAULT;");
}
}
```

Please do not get too attached to my poor example. It is just a way I found to relate to fluent entity configuration.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.