-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add TableFor and ColumnFor extensions with NameCompatibilityManager support #7968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,89 +15,93 @@ public class SchemaMigration : ForwardOnlyMigration | |
| public override void Up() | ||
| { | ||
| //#7387 | ||
| var productTableName = nameof(Product); | ||
|
|
||
| var ageVerificationColumnName = nameof(Product.AgeVerification); | ||
| if (!Schema.Table(productTableName).Column(ageVerificationColumnName).Exists()) | ||
| if (!Schema.TableFor<Product>().ColumnFor<Product>(t => t.AgeVerification).Exists()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This chain looks redundant and not very attractive. It's better to simplify the call to something like this: |
||
| { | ||
| Alter.Table(productTableName) | ||
| .AddColumn(ageVerificationColumnName) | ||
| Alter.TableFor<Product>() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and all similar calls also need to be simplified to Alter.AddColumnFor(t => t.AgeVerification) |
||
| .AddColumnFor<Product>(t => t.AgeVerification) | ||
| .AsBoolean() | ||
| .NotNullable() | ||
| .WithDefaultValue(false); | ||
| } | ||
|
|
||
| var minimumAgeToPurchaseColumnName = nameof(Product.MinimumAgeToPurchase); | ||
| if (!Schema.Table(productTableName).Column(minimumAgeToPurchaseColumnName).Exists()) | ||
| if (!Schema.TableFor<Product>().ColumnFor<Product>(t => t.MinimumAgeToPurchase).Exists()) | ||
| { | ||
| Alter.Table(productTableName) | ||
| .AddColumn(minimumAgeToPurchaseColumnName) | ||
| Alter.TableFor<Product>() | ||
| .AddColumnFor<Product>(t => t.MinimumAgeToPurchase) | ||
| .AsInt32() | ||
| .NotNullable() | ||
| .WithDefaultValue(0); | ||
| } | ||
|
|
||
| //#7294 | ||
| var topicTableName = nameof(Topic); | ||
| var topicAvailableEndDateColumnName = nameof(Topic.AvailableEndDateTimeUtc); | ||
| var topicAvailableStartDateColumnName = nameof(Topic.AvailableStartDateTimeUtc); | ||
|
|
||
| if (!Schema.Table(topicTableName).Column(topicAvailableEndDateColumnName).Exists()) | ||
| if (!Schema.TableFor<Topic>().ColumnFor<Topic>(t => t.AvailableEndDateTimeUtc).Exists()) | ||
| { | ||
| Alter.Table(topicTableName) | ||
| .AddColumn(topicAvailableEndDateColumnName) | ||
| Alter.TableFor<Topic>() | ||
| .AddColumnFor<Topic>(t => t.AvailableEndDateTimeUtc) | ||
| .AsDateTime() | ||
| .Nullable(); | ||
| } | ||
|
|
||
| if (!Schema.Table(topicTableName).Column(topicAvailableStartDateColumnName).Exists()) | ||
| if (!Schema.TableFor<Topic>().ColumnFor<Topic>(t => t.AvailableStartDateTimeUtc).Exists()) | ||
| { | ||
| Alter.Table(topicTableName) | ||
| .AddColumn(topicAvailableStartDateColumnName) | ||
| Alter.TableFor<Topic>() | ||
| .AddColumnFor<Topic>(t => t.AvailableStartDateTimeUtc) | ||
| .AsDateTime() | ||
| .Nullable(); | ||
| } | ||
|
|
||
| //#873 | ||
| var productTagTableName = nameof(ProductTag); | ||
|
|
||
| if (!Schema.Table(productTagTableName).Column(nameof(ProductTag.MetaDescription)).Exists()) | ||
| Alter.Table(productTagTableName).AddColumn(nameof(ProductTag.MetaDescription)).AsString().Nullable(); | ||
| if (!Schema.TableFor<ProductTag>().ColumnFor<ProductTag>(t => t.MetaDescription).Exists()) | ||
| { | ||
| Alter.TableFor<ProductTag>() | ||
| .AddColumnFor<ProductTag>(t => t.MetaDescription) | ||
| .AsString() | ||
| .Nullable(); | ||
| } | ||
|
|
||
| if (!Schema.Table(productTagTableName).Column(nameof(ProductTag.MetaKeywords)).Exists()) | ||
| Alter.Table(productTagTableName).AddColumn(nameof(ProductTag.MetaKeywords)).AsString(400).Nullable(); | ||
| if (!Schema.TableFor<ProductTag>().ColumnFor<ProductTag>(t => t.MetaKeywords).Exists()) | ||
| { | ||
| Alter.TableFor<ProductTag>() | ||
| .AddColumnFor<ProductTag>(t => t.MetaKeywords) | ||
| .AsString(400) | ||
| .Nullable(); | ||
| } | ||
|
|
||
| if (!Schema.Table(productTagTableName).Column(nameof(ProductTag.MetaTitle)).Exists()) | ||
| Alter.Table(productTagTableName).AddColumn(nameof(ProductTag.MetaTitle)).AsString(400).Nullable(); | ||
| if (!Schema.TableFor<ProductTag>().ColumnFor<ProductTag>(t => t.MetaTitle).Exists()) | ||
| { | ||
| Alter.TableFor<ProductTag>() | ||
| .AddColumnFor<ProductTag>(t => t.MetaTitle) | ||
| .AsString(400) | ||
| .Nullable(); | ||
| } | ||
|
|
||
| //#7390 | ||
| if (!Schema.Table(nameof(Menu)).Exists()) | ||
| if (!Schema.TableFor<Menu>().Exists()) | ||
| Create.TableFor<Menu>(); | ||
|
|
||
| if (!Schema.Table(nameof(MenuItem)).Exists()) | ||
| if (!Schema.TableFor<Menu>().Exists()) | ||
| Create.TableFor<MenuItem>(); | ||
|
|
||
| var footerColumn1ColumnName = "IncludeInFooterColumn1"; | ||
| if (Schema.Table(topicTableName).Column(footerColumn1ColumnName).Exists()) | ||
| Delete.Column(footerColumn1ColumnName).FromTable(topicTableName); | ||
| if (Schema.TableFor<Topic>().Column(footerColumn1ColumnName).Exists()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and in similar places, there should also be a call to ColumnFor |
||
| Delete.Column(footerColumn1ColumnName).FromTable<Topic>(); | ||
|
|
||
| var footerColumn2ColumnName = "IncludeInFooterColumn2"; | ||
| if (Schema.Table(topicTableName).Column(footerColumn2ColumnName).Exists()) | ||
| Delete.Column(footerColumn2ColumnName).FromTable(topicTableName); | ||
| if (Schema.TableFor<Topic>().Column(footerColumn2ColumnName).Exists()) | ||
| Delete.Column(footerColumn2ColumnName).FromTable<Topic>(); | ||
|
|
||
| var footerColumn3ColumnName = "IncludeInFooterColumn3"; | ||
| if (Schema.Table(topicTableName).Column(footerColumn3ColumnName).Exists()) | ||
| Delete.Column(footerColumn3ColumnName).FromTable(topicTableName); | ||
| if (Schema.TableFor<Topic>().Column(footerColumn3ColumnName).Exists()) | ||
| Delete.Column(footerColumn3ColumnName).FromTable<Topic>(); | ||
|
|
||
| var includeTopicInTopMenuColumnName = "IncludeInTopMenu"; | ||
| if (Schema.Table(topicTableName).Column(includeTopicInTopMenuColumnName).Exists()) | ||
| Delete.Column(includeTopicInTopMenuColumnName).FromTable(topicTableName); | ||
| if (Schema.TableFor<Topic>().Column(includeTopicInTopMenuColumnName).Exists()) | ||
| Delete.Column(includeTopicInTopMenuColumnName).FromTable<Topic>(); | ||
|
|
||
| var categoryTableName = nameof(Category); | ||
| var includeCategoryInTopMenuColumnName = "IncludeInTopMenu"; | ||
| if (Schema.Table(categoryTableName).Column(includeCategoryInTopMenuColumnName).Exists()) | ||
| Delete.Column(includeCategoryInTopMenuColumnName).FromTable(categoryTableName); | ||
|
|
||
|
|
||
| if (Schema.TableFor<Category>().Column(includeCategoryInTopMenuColumnName).Exists()) | ||
| Delete.Column(includeCategoryInTopMenuColumnName).FromTable<Category>(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The static analyzer says that the null checks in this code are redundant