diff --git a/src/EFCore.Design/Migrations/Design/CSharpMigrationOperationGenerator.cs b/src/EFCore.Design/Migrations/Design/CSharpMigrationOperationGenerator.cs
index 709bbb21dd3..81967ab3b1b 100644
--- a/src/EFCore.Design/Migrations/Design/CSharpMigrationOperationGenerator.cs
+++ b/src/EFCore.Design/Migrations/Design/CSharpMigrationOperationGenerator.cs
@@ -422,16 +422,16 @@ protected virtual void Generate([NotNull] AddUniqueConstraintOperation operation
}
///
- /// Generates code for an .
+ /// Generates code for an .
///
/// The operation.
/// The builder code is added to.
- protected virtual void Generate([NotNull] CreateCheckConstraintOperation operation, [NotNull] IndentedStringBuilder builder)
+ protected virtual void Generate([NotNull] AddCheckConstraintOperation operation, [NotNull] IndentedStringBuilder builder)
{
Check.NotNull(operation, nameof(operation));
Check.NotNull(builder, nameof(builder));
- builder.AppendLine(".CreateCheckConstraint(");
+ builder.AppendLine(".AddCheckConstraint(");
using (builder.Indent())
{
diff --git a/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs b/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs
index 461917dedc6..6f3878223b4 100644
--- a/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs
+++ b/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs
@@ -63,7 +63,7 @@ public class MigrationsModelDiffer : IMigrationsModelDiffer
{
typeof(AddForeignKeyOperation),
typeof(CreateIndexOperation),
- typeof(CreateCheckConstraintOperation)
+ typeof(AddCheckConstraintOperation)
};
private IUpdateAdapter _sourceUpdateAdapter;
@@ -662,7 +662,7 @@ protected virtual IEnumerable Add(
.Cast());
createTableOperation.CheckConstraints.AddRange(
target.CheckConstraints.SelectMany(c => Add(c, diffContext))
- .Cast());
+ .Cast());
diffContext.AddCreate(target, createTableOperation);
@@ -1395,20 +1395,7 @@ protected virtual IEnumerable Add(
[NotNull] ITableIndex target,
[NotNull] DiffContext diffContext)
{
- var targetTable = target.Table;
-
- var operation = new CreateIndexOperation
- {
- Name = target.Name,
- Schema = targetTable.Schema,
- Table = targetTable.Name,
- Columns = target.Columns.Select(c => c.Name).ToArray(),
- IsUnique = target.IsUnique,
- Filter = target.Filter
- };
- operation.AddAnnotations(target.GetAnnotations());
-
- yield return operation;
+ yield return CreateIndexOperation.For(target);
}
///
@@ -1477,7 +1464,7 @@ protected virtual IEnumerable Add([NotNull] ICheckConstraint
{
var targetEntityType = target.EntityType;
- var operation = new CreateCheckConstraintOperation
+ var operation = new AddCheckConstraintOperation
{
Name = target.Name,
Sql = target.Sql,
@@ -2127,7 +2114,7 @@ protected virtual IEnumerable GetDataOperations(
var dataOperations = GetDataOperations(forSource: true, changedTableMappings, entriesWithRemovedMappings, diffContext)
.Concat(GetDataOperations(forSource: false, changedTableMappings, entriesWithRemovedMappings, diffContext));
- foreach(var operation in dataOperations)
+ foreach (var operation in dataOperations)
{
yield return operation;
}
diff --git a/src/EFCore.Relational/Migrations/MigrationBuilder.cs b/src/EFCore.Relational/Migrations/MigrationBuilder.cs
index 4befab87c82..742a6463444 100644
--- a/src/EFCore.Relational/Migrations/MigrationBuilder.cs
+++ b/src/EFCore.Relational/Migrations/MigrationBuilder.cs
@@ -436,7 +436,7 @@ public virtual AlterOperationBuilder AlterColumn(
Precision = precision,
Scale = scale,
IsStored = stored,
- OldColumn = new ColumnOperation
+ OldColumn = new AddColumnOperation
{
ClrType = oldClrType ?? typeof(T),
ColumnType = oldType,
@@ -516,7 +516,7 @@ public virtual AlterOperationBuilder AlterSequence(
MinValue = minValue,
MaxValue = maxValue,
IsCyclic = cyclic,
- OldSequence = new SequenceOperation
+ OldSequence = new CreateSequenceOperation
{
IncrementBy = oldIncrementBy,
MinValue = oldMinValue,
@@ -550,7 +550,7 @@ public virtual AlterOperationBuilder AlterTable(
Schema = schema,
Name = name,
Comment = comment,
- OldTable = new TableOperation { Comment = oldComment }
+ OldTable = new CreateTableOperation { Comment = oldComment }
};
Operations.Add(operation);
@@ -695,14 +695,30 @@ public virtual OperationBuilder CreateSequence(
}
///
- /// Builds an to create a new check constraint.
+ /// Builds an to create a new check constraint.
///
/// The check constraint name.
/// The name of the table for the check constraint.
/// The constraint sql for the check constraint.
/// The schema that contains the check constraint, or to use the default schema.
/// A builder to allow annotations to be added to the operation.
- public virtual OperationBuilder CreateCheckConstraint(
+ [Obsolete("Use AddCheckConstraint")]
+ public virtual OperationBuilder CreateCheckConstraint(
+ [NotNull] string name,
+ [NotNull] string table,
+ [NotNull] string sql,
+ [CanBeNull] string schema = null)
+ => AddCheckConstraint(name, table, sql, schema);
+
+ ///
+ /// Builds an to add a new check constraint to a table.
+ ///
+ /// The check constraint name.
+ /// The name of the table for the check constraint.
+ /// The constraint sql for the check constraint.
+ /// The schema that contains the check constraint, or to use the default schema.
+ /// A builder to allow annotations to be added to the operation.
+ public virtual OperationBuilder AddCheckConstraint(
[NotNull] string name,
[NotNull] string table,
[NotNull] string sql,
@@ -710,7 +726,7 @@ public virtual OperationBuilder CreateCheckConst
{
Check.NotEmpty(name, nameof(name));
- var operation = new CreateCheckConstraintOperation
+ var operation = new AddCheckConstraintOperation
{
Schema = schema,
Name = name,
@@ -719,7 +735,7 @@ public virtual OperationBuilder CreateCheckConst
};
Operations.Add(operation);
- return new OperationBuilder(operation);
+ return new OperationBuilder(operation);
}
///
diff --git a/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs b/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs
index f205f71a1c5..85359353f60 100644
--- a/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs
+++ b/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs
@@ -48,7 +48,7 @@ private static readonly
{ typeof(AlterDatabaseOperation), (g, o, m, b) => g.Generate((AlterDatabaseOperation)o, m, b) },
{ typeof(AlterSequenceOperation), (g, o, m, b) => g.Generate((AlterSequenceOperation)o, m, b) },
{ typeof(AlterTableOperation), (g, o, m, b) => g.Generate((AlterTableOperation)o, m, b) },
- { typeof(CreateCheckConstraintOperation), (g, o, m, b) => g.Generate((CreateCheckConstraintOperation)o, m, b) },
+ { typeof(AddCheckConstraintOperation), (g, o, m, b) => g.Generate((AddCheckConstraintOperation)o, m, b) },
{ typeof(CreateIndexOperation), (g, o, m, b) => g.Generate((CreateIndexOperation)o, m, b) },
{ typeof(CreateSequenceOperation), (g, o, m, b) => g.Generate((CreateSequenceOperation)o, m, b) },
{ typeof(CreateTableOperation), (g, o, m, b) => g.Generate((CreateTableOperation)o, m, b) },
@@ -277,14 +277,14 @@ protected virtual void Generate(
}
///
- /// Builds commands for the given by making calls on the given
+ /// Builds commands for the given by making calls on the given
/// , and then terminates the final command.
///
/// The operation.
/// The target model which may be if the operations exist without a model.
/// The command builder to use to build the commands.
protected virtual void Generate(
- [NotNull] CreateCheckConstraintOperation operation,
+ [NotNull] AddCheckConstraintOperation operation,
[CanBeNull] IModel model,
[NotNull] MigrationCommandListBuilder builder)
{
@@ -1710,13 +1710,13 @@ protected virtual void CreateTableCheckConstraints(
}
///
- /// Generates a SQL fragment for a check constraint of an .
+ /// Generates a SQL fragment for a check constraint of an .
///
/// The operation.
/// The target model which may be if the operations exist without a model.
/// The command builder to use to add the SQL fragment.
protected virtual void CheckConstraint(
- [NotNull] CreateCheckConstraintOperation operation,
+ [NotNull] AddCheckConstraintOperation operation,
[CanBeNull] IModel model,
[NotNull] MigrationCommandListBuilder builder)
{
diff --git a/src/EFCore.Relational/Migrations/Operations/CreateCheckConstraintOperation.cs b/src/EFCore.Relational/Migrations/Operations/AddCheckConstraintOperation.cs
similarity index 95%
rename from src/EFCore.Relational/Migrations/Operations/CreateCheckConstraintOperation.cs
rename to src/EFCore.Relational/Migrations/Operations/AddCheckConstraintOperation.cs
index ad314a4d7f2..86b31d6599a 100644
--- a/src/EFCore.Relational/Migrations/Operations/CreateCheckConstraintOperation.cs
+++ b/src/EFCore.Relational/Migrations/Operations/AddCheckConstraintOperation.cs
@@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Operations
/// A for creating a new check constraint.
///
[DebuggerDisplay("ALTER TABLE {Table} ADD CONSTRAINT {Name} CHECK")]
- public class CreateCheckConstraintOperation : MigrationOperation
+ public class AddCheckConstraintOperation : MigrationOperation
{
///
/// The name of the check constraint.
diff --git a/src/EFCore.Relational/Migrations/Operations/AddColumnOperation.cs b/src/EFCore.Relational/Migrations/Operations/AddColumnOperation.cs
index 440a52d142e..c2da21f1c72 100644
--- a/src/EFCore.Relational/Migrations/Operations/AddColumnOperation.cs
+++ b/src/EFCore.Relational/Migrations/Operations/AddColumnOperation.cs
@@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics;
-using JetBrains.Annotations;
namespace Microsoft.EntityFrameworkCore.Migrations.Operations
{
@@ -12,19 +11,5 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Operations
[DebuggerDisplay("ALTER TABLE {Table} ADD {Name}")]
public class AddColumnOperation : ColumnOperation
{
- ///
- /// The column name.
- ///
- public virtual string Name { get; [param: NotNull] set; }
-
- ///
- /// The schema that contains the table, or if the default schema should be used.
- ///
- public virtual string Schema { get; [param: CanBeNull] set; }
-
- ///
- /// The table to which the column will be added.
- ///
- public virtual string Table { get; [param: NotNull] set; }
}
}
diff --git a/src/EFCore.Relational/Migrations/Operations/AlterColumnOperation.cs b/src/EFCore.Relational/Migrations/Operations/AlterColumnOperation.cs
index febad02fc3a..17e53901c51 100644
--- a/src/EFCore.Relational/Migrations/Operations/AlterColumnOperation.cs
+++ b/src/EFCore.Relational/Migrations/Operations/AlterColumnOperation.cs
@@ -13,25 +13,10 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Operations
[DebuggerDisplay("ALTER TABLE {Table} ALTER COLUMN {Name}")]
public class AlterColumnOperation : ColumnOperation, IAlterMigrationOperation
{
- ///
- /// The name of the column.
- ///
- public virtual string Name { get; [param: NotNull] set; }
-
- ///
- /// The schema that contains the table, or if the default schema should be used.
- ///
- public virtual string Schema { get; [param: CanBeNull] set; }
-
- ///
- /// The table which contains the column.
- ///
- public virtual string Table { get; [param: NotNull] set; }
-
///
/// An operation representing the column as it was before being altered.
///
- public virtual ColumnOperation OldColumn { get; [param: NotNull] set; } = new ColumnOperation();
+ public virtual ColumnOperation OldColumn { get; [param: NotNull] set; } = new AddColumnOperation();
///
IMutableAnnotatable IAlterMigrationOperation.OldAnnotations => OldColumn;
diff --git a/src/EFCore.Relational/Migrations/Operations/AlterDatabaseOperation.cs b/src/EFCore.Relational/Migrations/Operations/AlterDatabaseOperation.cs
index 530eaa706ec..0504c4fc8f1 100644
--- a/src/EFCore.Relational/Migrations/Operations/AlterDatabaseOperation.cs
+++ b/src/EFCore.Relational/Migrations/Operations/AlterDatabaseOperation.cs
@@ -15,9 +15,13 @@ public class AlterDatabaseOperation : DatabaseOperation, IAlterMigrationOperatio
///
/// An operation representing the database as it was before being altered.
///
- public virtual DatabaseOperation OldDatabase { get; } = new DatabaseOperation();
+ public virtual DatabaseOperation OldDatabase { get; } = new CreateDatabaseOperation();
///
IMutableAnnotatable IAlterMigrationOperation.OldAnnotations => OldDatabase;
+
+ private sealed class CreateDatabaseOperation : DatabaseOperation
+ {
+ }
}
}
diff --git a/src/EFCore.Relational/Migrations/Operations/AlterSequenceOperation.cs b/src/EFCore.Relational/Migrations/Operations/AlterSequenceOperation.cs
index 7f5f9ff43f4..d12d3ad6534 100644
--- a/src/EFCore.Relational/Migrations/Operations/AlterSequenceOperation.cs
+++ b/src/EFCore.Relational/Migrations/Operations/AlterSequenceOperation.cs
@@ -26,7 +26,7 @@ public class AlterSequenceOperation : SequenceOperation, IAlterMigrationOperatio
///
/// An operation representing the sequence as it was before being altered.
///
- public virtual SequenceOperation OldSequence { get; [param: NotNull] set; } = new SequenceOperation();
+ public virtual SequenceOperation OldSequence { get; [param: NotNull] set; } = new CreateSequenceOperation();
///
IMutableAnnotatable IAlterMigrationOperation.OldAnnotations => OldSequence;
diff --git a/src/EFCore.Relational/Migrations/Operations/AlterTableOperation.cs b/src/EFCore.Relational/Migrations/Operations/AlterTableOperation.cs
index df7fd8404e8..4561d18ec1f 100644
--- a/src/EFCore.Relational/Migrations/Operations/AlterTableOperation.cs
+++ b/src/EFCore.Relational/Migrations/Operations/AlterTableOperation.cs
@@ -13,20 +13,10 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Operations
[DebuggerDisplay("ALTER TABLE {Name}")]
public class AlterTableOperation : TableOperation, IAlterMigrationOperation
{
- ///
- /// The name of the table.
- ///
- public virtual string Name { get; [param: NotNull] set; }
-
- ///
- /// The schema that contains the table, or if the default schema should be used.
- ///
- public virtual string Schema { get; [param: CanBeNull] set; }
-
///
/// An operation representing the table as it was before being altered.
///
- public virtual TableOperation OldTable { get; [param: NotNull] set; } = new TableOperation();
+ public virtual TableOperation OldTable { get; [param: NotNull] set; } = new CreateTableOperation();
///
IMutableAnnotatable IAlterMigrationOperation.OldAnnotations => OldTable;
diff --git a/src/EFCore.Relational/Migrations/Operations/Builders/CreateTableBuilder.cs b/src/EFCore.Relational/Migrations/Operations/Builders/CreateTableBuilder.cs
index a224ce12af0..d4e3cd61626 100644
--- a/src/EFCore.Relational/Migrations/Operations/Builders/CreateTableBuilder.cs
+++ b/src/EFCore.Relational/Migrations/Operations/Builders/CreateTableBuilder.cs
@@ -162,14 +162,14 @@ public virtual OperationBuilder UniqueConstraint(
/// The constraint name.
/// The sql expression used in the CHECK constraint.
/// The same builder so that multiple calls can be chained.
- public virtual OperationBuilder CheckConstraint(
+ public virtual OperationBuilder CheckConstraint(
[NotNull] string name,
[NotNull] string sql)
{
Check.NotEmpty(name, nameof(name));
Check.NotNull(sql, nameof(sql));
- var operation = new CreateCheckConstraintOperation
+ var operation = new AddCheckConstraintOperation
{
Schema = Operation.Schema,
Table = Operation.Name,
@@ -178,7 +178,7 @@ public virtual OperationBuilder CheckConstraint(
};
Operation.CheckConstraints.Add(operation);
- return new OperationBuilder(operation);
+ return new OperationBuilder(operation);
}
///
diff --git a/src/EFCore.Relational/Migrations/Operations/ColumnOperation.cs b/src/EFCore.Relational/Migrations/Operations/ColumnOperation.cs
index 544be8cc234..b434d3dfb05 100644
--- a/src/EFCore.Relational/Migrations/Operations/ColumnOperation.cs
+++ b/src/EFCore.Relational/Migrations/Operations/ColumnOperation.cs
@@ -3,7 +3,6 @@
using System;
using JetBrains.Annotations;
-using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace Microsoft.EntityFrameworkCore.Migrations.Operations
{
@@ -11,8 +10,23 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Operations
/// A for operations on columns.
/// See also and .
///
- public class ColumnOperation : MigrationOperation
+ public abstract class ColumnOperation : MigrationOperation
{
+ ///
+ /// The name of the column.
+ ///
+ public virtual string Name { get; [param: NotNull] set; }
+
+ ///
+ /// The schema that contains the table, or if the default schema should be used.
+ ///
+ public virtual string Schema { get; [param: CanBeNull] set; }
+
+ ///
+ /// The table which contains the column.
+ ///
+ public virtual string Table { get; [param: NotNull] set; }
+
///
/// The CLR of the property or properties mapped to the column.
///
diff --git a/src/EFCore.Relational/Migrations/Operations/CreateIndexOperation.cs b/src/EFCore.Relational/Migrations/Operations/CreateIndexOperation.cs
index 211f2aede7f..639b4937bea 100644
--- a/src/EFCore.Relational/Migrations/Operations/CreateIndexOperation.cs
+++ b/src/EFCore.Relational/Migrations/Operations/CreateIndexOperation.cs
@@ -3,6 +3,10 @@
using System.Diagnostics;
using JetBrains.Annotations;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Utilities;
+using System;
+using System.Linq;
namespace Microsoft.EntityFrameworkCore.Migrations.Operations
{
@@ -41,5 +45,28 @@ public class CreateIndexOperation : MigrationOperation
/// An expression to use as the index filter.
///
public virtual string Filter { get; [param: CanBeNull] set; }
+
+ ///
+ /// Creates a new for the specified index.
+ ///
+ /// The index.
+ /// The operation.
+ public static CreateIndexOperation For([NotNull] ITableIndex index)
+ {
+ Check.NotNull(index, nameof(index));
+
+ var operation = new CreateIndexOperation
+ {
+ IsUnique = index.IsUnique,
+ Name = index.Name,
+ Schema = index.Table.Schema,
+ Table = index.Table.Name,
+ Columns = index.Columns.Select(p => p.Name).ToArray(),
+ Filter = index.Filter
+ };
+ operation.AddAnnotations(index.GetAnnotations());
+
+ return operation;
+ }
}
}
diff --git a/src/EFCore.Relational/Migrations/Operations/CreateTableOperation.cs b/src/EFCore.Relational/Migrations/Operations/CreateTableOperation.cs
index 8cdb05f7456..af8c9d8674b 100644
--- a/src/EFCore.Relational/Migrations/Operations/CreateTableOperation.cs
+++ b/src/EFCore.Relational/Migrations/Operations/CreateTableOperation.cs
@@ -13,16 +13,6 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Operations
[DebuggerDisplay("CREATE TABLE {Name}")]
public class CreateTableOperation : TableOperation
{
- ///
- /// The name of the table.
- ///
- public virtual string Name { get; [param: NotNull] set; }
-
- ///
- /// The schema that contains the table, or if the default schema should be used.
- ///
- public virtual string Schema { get; [param: CanBeNull] set; }
-
///
/// The representing the creation of the primary key for the table.
///
@@ -44,8 +34,8 @@ public class CreateTableOperation : TableOperation
public virtual List UniqueConstraints { get; } = new List();
///
- /// A list of for creating check constraints in the table.
+ /// A list of for creating check constraints in the table.
///
- public virtual List CheckConstraints { get; } = new List();
+ public virtual List CheckConstraints { get; } = new List();
}
}
diff --git a/src/EFCore.Relational/Migrations/Operations/DatabaseOperation.cs b/src/EFCore.Relational/Migrations/Operations/DatabaseOperation.cs
index d5d0e0841b5..2e873777d6f 100644
--- a/src/EFCore.Relational/Migrations/Operations/DatabaseOperation.cs
+++ b/src/EFCore.Relational/Migrations/Operations/DatabaseOperation.cs
@@ -9,7 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Operations
/// A for operations on databases.
/// See also .
///
- public class DatabaseOperation : MigrationOperation
+ public abstract class DatabaseOperation : MigrationOperation
{
///
/// The collation for the database, or to use the default collation of the instance of SQL Server.
diff --git a/src/EFCore.Relational/Migrations/Operations/SequenceOperation.cs b/src/EFCore.Relational/Migrations/Operations/SequenceOperation.cs
index 64bba3ea30a..87747772c08 100644
--- a/src/EFCore.Relational/Migrations/Operations/SequenceOperation.cs
+++ b/src/EFCore.Relational/Migrations/Operations/SequenceOperation.cs
@@ -7,7 +7,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Operations
/// A for operations on sequences.
/// See also and .
///
- public class SequenceOperation : MigrationOperation
+ public abstract class SequenceOperation : MigrationOperation
{
///
/// The amount to increment by when generating the next value in the sequence, defaulting to 1.
diff --git a/src/EFCore.Relational/Migrations/Operations/TableOperation.cs b/src/EFCore.Relational/Migrations/Operations/TableOperation.cs
index ed672d2264e..2f865a7ef61 100644
--- a/src/EFCore.Relational/Migrations/Operations/TableOperation.cs
+++ b/src/EFCore.Relational/Migrations/Operations/TableOperation.cs
@@ -9,8 +9,18 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Operations
/// A for operations on tables.
/// See also and .
///
- public class TableOperation : MigrationOperation
+ public abstract class TableOperation : MigrationOperation
{
+ ///
+ /// The name of the table.
+ ///
+ public virtual string Name { get; [param: NotNull] set; }
+
+ ///
+ /// The schema that contains the table, or if the default schema should be used.
+ ///
+ public virtual string Schema { get; [param: CanBeNull] set; }
+
///
/// Comment for this table
///
diff --git a/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs b/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs
index 5f242a3d31c..8a9c7b415ae 100644
--- a/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs
+++ b/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs
@@ -11,7 +11,6 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
-using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Migrations.Operations;
using Microsoft.EntityFrameworkCore.SqlServer.Internal;
using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal;
@@ -1738,19 +1737,7 @@ protected virtual void CreateIndexes(
foreach (var index in indexes)
{
- var table = index.Table;
- var operation = new CreateIndexOperation
- {
- IsUnique = index.IsUnique,
- Name = index.Name,
- Schema = table.Schema,
- Table = table.Name,
- Columns = index.Columns.Select(c => c.Name).ToArray(),
- Filter = index.Filter
- };
- operation.AddAnnotations(index.GetAnnotations());
-
- Generate(operation, table.Model.Model, builder, terminate: false);
+ Generate(CreateIndexOperation.For(index), index.Table.Model.Model, builder, terminate: false);
builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);
}
}
diff --git a/src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs b/src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs
index 3fb5b93d7c0..968f67ff19b 100644
--- a/src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs
+++ b/src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs
@@ -239,21 +239,10 @@ protected override void Generate(RenameIndexOperation operation, IModel model, M
};
dropOperation.AddAnnotations(index.GetAnnotations());
- var createOperation = new CreateIndexOperation
- {
- IsUnique = index.IsUnique,
- Name = operation.NewName,
- Schema = operation.Schema,
- Table = operation.Table,
- Columns = index.Columns.Select(p => p.Name).ToArray(),
- Filter = index.Filter
- };
- createOperation.AddAnnotations(index.GetAnnotations());
-
Generate(dropOperation, model, builder, terminate: false);
builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);
- Generate(createOperation, model, builder);
+ Generate(CreateIndexOperation.For(index), model, builder);
}
///
@@ -509,7 +498,7 @@ protected override void Generate(AddUniqueConstraintOperation operation, IModel
/// The operation.
/// The target model which may be if the operations exist without a model.
/// The command builder to use to build the commands.
- protected override void Generate(CreateCheckConstraintOperation operation, IModel model, MigrationCommandListBuilder builder)
+ protected override void Generate(AddCheckConstraintOperation operation, IModel model, MigrationCommandListBuilder builder)
=> throw new NotSupportedException(
SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName()));
diff --git a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationOperationGeneratorTest.cs b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationOperationGeneratorTest.cs
index 18e5d0ac386..69f3aec1c59 100644
--- a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationOperationGeneratorTest.cs
+++ b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationOperationGeneratorTest.cs
@@ -457,16 +457,16 @@ public void AddUniqueConstraint_composite()
}
[ConditionalFact]
- public void CreateCheckConstraint_required_args()
+ public void AddCheckConstraint_required_args()
{
Test(
- new CreateCheckConstraintOperation
+ new AddCheckConstraintOperation
{
Name = "CK_Post_AltId1_AltId2",
Table = "Post",
Sql = "AltId1 > AltId2"
},
- "mb.CreateCheckConstraint("
+ "mb.AddCheckConstraint("
+ _eol
+ " name: \"CK_Post_AltId1_AltId2\","
+ _eol
@@ -482,17 +482,17 @@ public void CreateCheckConstraint_required_args()
}
[ConditionalFact]
- public void CreateCheckConstraint_all_args()
+ public void AddCheckConstraint_all_args()
{
Test(
- new CreateCheckConstraintOperation
+ new AddCheckConstraintOperation
{
Name = "CK_Post_AltId1_AltId2",
Schema = "dbo",
Table = "Post",
Sql = "AltId1 > AltId2"
},
- "mb.CreateCheckConstraint("
+ "mb.AddCheckConstraint("
+ _eol
+ " name: \"CK_Post_AltId1_AltId2\","
+ _eol
@@ -1856,7 +1856,7 @@ public void CreateTableOperation_CheckConstraints_required_args()
},
CheckConstraints =
{
- new CreateCheckConstraintOperation
+ new AddCheckConstraintOperation
{
Name = "CK_Post_AltId1_AltId2",
Table = "Post",
@@ -1910,7 +1910,7 @@ public void CreateTableOperation_ChecksConstraints_all_args()
},
CheckConstraints =
{
- new CreateCheckConstraintOperation
+ new AddCheckConstraintOperation
{
Name = "CK_Post_AltId1_AltId2",
Schema = "dbo",
@@ -2539,7 +2539,10 @@ public void SqlOperation_required_args()
};
private static readonly MultiPoint _multiPoint = new MultiPoint(
- new[] { new Point(1.1, 2.2), new Point(2.2, 2.2), new Point(2.2, 1.1) }) { SRID = 4326 };
+ new[] { new Point(1.1, 2.2), new Point(2.2, 2.2), new Point(2.2, 1.1) })
+ {
+ SRID = 4326
+ };
private static readonly Polygon _polygon1 = new Polygon(
new LinearRing(
@@ -2558,10 +2561,16 @@ public void SqlOperation_required_args()
private static readonly Point _point1 = new Point(1.1, 2.2, 3.3) { SRID = 4326 };
private static readonly MultiLineString _multiLineString = new MultiLineString(
- new[] { _lineString1, _lineString2 }) { SRID = 4326 };
+ new[] { _lineString1, _lineString2 })
+ {
+ SRID = 4326
+ };
private static readonly MultiPolygon _multiPolygon = new MultiPolygon(
- new[] { _polygon2, _polygon1 }) { SRID = 4326 };
+ new[] { _polygon2, _polygon1 })
+ {
+ SRID = 4326
+ };
private static readonly GeometryCollection _geometryCollection = new GeometryCollection(
new Geometry[] { _lineString1, _lineString2, _multiPoint, _polygon1, _polygon2, _point1, _multiLineString, _multiPolygon })
diff --git a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.cs b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.cs
index dfe0caf56a1..b0bf9799d82 100644
--- a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.cs
+++ b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.cs
@@ -418,7 +418,7 @@ public void Migrations_compile()
Name = "C2",
Table = "T1",
ClrType = typeof(Database),
- OldColumn = new ColumnOperation { ClrType = typeof(Property) }
+ OldColumn = new AddColumnOperation { ClrType = typeof(Property) }
},
new AddColumnOperation
{
diff --git a/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs b/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs
index fd749653b3b..f0d3dc4b26c 100644
--- a/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs
+++ b/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs
@@ -2582,7 +2582,7 @@ public void Add_check_constraint()
{
Assert.Equal(1, operations.Count);
- var operation = Assert.IsType(operations[0]);
+ var operation = Assert.IsType(operations[0]);
Assert.Equal("dbo", operation.Schema);
Assert.Equal("Flamingo", operation.Table);
Assert.Equal("CK_Flamingo_AlternateId", operation.Name);
@@ -2653,7 +2653,7 @@ public void Rename_check_constraint()
Assert.Equal("Pelican", dropOperation.Table);
Assert.Equal("CK_Flamingo_AlternateId", dropOperation.Name);
- var createOperation = Assert.IsType(operations[1]);
+ var createOperation = Assert.IsType(operations[1]);
Assert.Equal("dbo", createOperation.Schema);
Assert.Equal("Pelican", createOperation.Table);
Assert.Equal("CK_Flamingo", createOperation.Name);
@@ -2692,7 +2692,7 @@ public void Alter_check_constraint_expression()
Assert.Equal("Rook", dropOperation.Table);
Assert.Equal("CK_Flamingo_AlternateId", dropOperation.Name);
- var createOperation = Assert.IsType(operations[1]);
+ var createOperation = Assert.IsType(operations[1]);
Assert.Equal("dbo", createOperation.Schema);
Assert.Equal("Rook", createOperation.Table);
Assert.Equal("CK_Flamingo_AlternateId", createOperation.Name);
diff --git a/test/EFCore.SqlServer.Tests/Migrations/SqlServerMigrationsSqlGeneratorTest.cs b/test/EFCore.SqlServer.Tests/Migrations/SqlServerMigrationsSqlGeneratorTest.cs
index 4db7c6baf15..0ba28260964 100644
--- a/test/EFCore.SqlServer.Tests/Migrations/SqlServerMigrationsSqlGeneratorTest.cs
+++ b/test/EFCore.SqlServer.Tests/Migrations/SqlServerMigrationsSqlGeneratorTest.cs
@@ -214,7 +214,7 @@ public virtual void AlterColumnOperation_with_index_no_oldColumn()
ClrType = typeof(string),
MaxLength = 30,
IsNullable = true,
- OldColumn = new ColumnOperation()
+ OldColumn = new AddColumnOperation()
});
AssertSql(
@@ -247,7 +247,7 @@ public virtual void AlterColumnOperation_with_added_index()
ClrType = typeof(string),
MaxLength = 30,
IsNullable = true,
- OldColumn = new ColumnOperation { ClrType = typeof(string), IsNullable = true }
+ OldColumn = new AddColumnOperation { ClrType = typeof(string), IsNullable = true }
},
new CreateIndexOperation
{
@@ -281,7 +281,7 @@ public virtual void AlterColumnOperation_identity_legacy()
Name = "Id",
ClrType = typeof(long),
[SqlServerAnnotationNames.ValueGenerationStrategy] = SqlServerValueGenerationStrategy.IdentityColumn,
- OldColumn = new ColumnOperation
+ OldColumn = new AddColumnOperation
{
ClrType = typeof(int),
[SqlServerAnnotationNames.ValueGenerationStrategy] = SqlServerValueGenerationStrategy.IdentityColumn
@@ -311,7 +311,7 @@ public virtual void AlterColumnOperation_add_identity_legacy()
Name = "Id",
ClrType = typeof(int),
[SqlServerAnnotationNames.ValueGenerationStrategy] = SqlServerValueGenerationStrategy.IdentityColumn,
- OldColumn = new ColumnOperation { ClrType = typeof(int) }
+ OldColumn = new AddColumnOperation { ClrType = typeof(int) }
}));
Assert.Equal(SqlServerStrings.AlterIdentityColumn, ex.Message);
@@ -328,7 +328,7 @@ public virtual void AlterColumnOperation_remove_identity_legacy()
Table = "Person",
Name = "Id",
ClrType = typeof(int),
- OldColumn = new ColumnOperation
+ OldColumn = new AddColumnOperation
{
ClrType = typeof(int),
[SqlServerAnnotationNames.ValueGenerationStrategy] = SqlServerValueGenerationStrategy.IdentityColumn
diff --git a/test/EFCore.Sqlite.FunctionalTests/MigrationsSqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/MigrationsSqliteTest.cs
index 15be4ae5de0..adab1afd1c6 100644
--- a/test/EFCore.Sqlite.FunctionalTests/MigrationsSqliteTest.cs
+++ b/test/EFCore.Sqlite.FunctionalTests/MigrationsSqliteTest.cs
@@ -328,7 +328,7 @@ await Test(
[ConditionalFact]
public override Task Add_column_with_check_constraint()
- => AssertNotSupportedAsync(base.Add_column_with_check_constraint, SqliteStrings.InvalidMigrationOperation("CreateCheckConstraintOperation"));
+ => AssertNotSupportedAsync(base.Add_column_with_check_constraint, SqliteStrings.InvalidMigrationOperation("AddCheckConstraintOperation"));
public override Task Alter_column_make_required()
=> AssertNotSupportedAsync(base.Alter_column_make_required, SqliteStrings.InvalidMigrationOperation("AlterColumnOperation"));
@@ -456,7 +456,7 @@ public override Task Drop_unique_constraint()
public override Task Add_check_constraint_with_name()
=> AssertNotSupportedAsync(
- base.Add_check_constraint_with_name, SqliteStrings.InvalidMigrationOperation("CreateCheckConstraintOperation"));
+ base.Add_check_constraint_with_name, SqliteStrings.InvalidMigrationOperation("AddCheckConstraintOperation"));
public override Task Alter_check_constraint()
=> AssertNotSupportedAsync(