Skip to content

Commit ae85c4b

Browse files
committed
[release/9.0] Don't execute empty batches (#34870)
Fixes #33337
1 parent d67ca8e commit ae85c4b

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,8 +1426,11 @@ protected override void Generate(SqlOperation operation, IModel? model, Migratio
14261426

14271427
void AppendBatch(string batch)
14281428
{
1429-
builder.Append(batch);
1430-
EndStatement(builder, operation.SuppressTransaction);
1429+
if (!string.IsNullOrWhiteSpace(batch))
1430+
{
1431+
builder.Append(batch);
1432+
EndStatement(builder, operation.SuppressTransaction);
1433+
}
14311434
}
14321435
}
14331436

@@ -2524,7 +2527,7 @@ private IReadOnlyList<MigrationOperation> RewriteOperations(
25242527
{
25252528
// for create table we always generate new temporal information from the operation itself
25262529
// just in case there was a table with that name before that got deleted/renamed
2527-
// this shouldn't happen as we re-use existin tables rather than drop/recreate
2530+
// this shouldn't happen as we re-use existing tables rather than drop/recreate
25282531
// but we are being extra defensive here
25292532
// and also, temporal state (disabled versioning etc.) should always reset when creating a table
25302533
temporalInformation = BuildTemporalInformationFromMigrationOperation(schema, createTableOperation);

test/EFCore.SqlServer.FunctionalTests/Migrations/MigrationsInfrastructureSqlServerTest.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@ SELECT @Counter
152152
SELECT GetDate()
153153
GO
154154
155-
156-
GO
157-
158155
INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
159156
VALUES (N'00000000000004_Migration4', N'7.0.0-test');
160157
GO
@@ -299,9 +296,6 @@ SELECT @Counter
299296
SELECT GetDate()
300297
GO
301298
302-
303-
GO
304-
305299
INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
306300
VALUES (N'00000000000004_Migration4', N'7.0.0-test');
307301
GO

0 commit comments

Comments
 (0)