Skip to content

Add TableFor and ColumnFor support for Alter, Delete and Schema operations using NameCompatibilityManager #7967

@atiq-bs23

Description

@atiq-bs23

We currently have TableFor<TEntity> extension support only for ICreateExpressionRoot, where it correctly uses NameCompatibilityManager for resolving table names.

But we also need similar support for IDeleteExpressionRoot, IAlterExpressionRoot and ISchemaExpressionRoot

And additionally, we need ColumnFor as well to support for schema checks, so NameCompatibilityManager is also used for column name mapping.

Otherwise migrations can break when database table/column names differ from entity class/property names.

Current implementation

var productTableName = nameof(Product);
if (!Schema.Table(productTableName).Column(ageVerificationColumnName).Exists())
{
    Alter.Table(productTableName)....
}

Expected code like below

if (!Schema.TableFor<Topic>().ColumnFor<Topic>(t => t.AvailableEndDateTimeUtc).Exists())
 {
     Alter.TableFor<Topic>()
         .AddColumnFor<Topic>(t => t.AvailableEndDateTimeUtc)
         .AsDateTime()
         .Nullable();
 }
 
var footerColumn1ColumnName = "IncludeInFooterColumn1";
if (Schema.TableFor<Topic>().Column(footerColumn1ColumnName).Exists())
    Delete.Column(footerColumn1ColumnName).FromTable<Topic>();

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions