Skip to content

Commit

Permalink
Quote FROM table identifier when rewriting
Browse files Browse the repository at this point in the history
fixes invalid migrations when the table name is a reserved keyword (e.g. 'Group')
  • Loading branch information
CaringDev authored and bricelam committed Dec 10, 2020
1 parent 54903bc commit 9857e68
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ private IReadOnlyList<MigrationOperation> RewriteOperations(
.Append(selectBuilder)
.AppendLine()
.Append("FROM ")
.Append(table.Name)
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(table.Name))
.Append(Dependencies.SqlGenerationHelper.StatementTerminator)
.ToString()
});
Expand Down
66 changes: 33 additions & 33 deletions test/EFCore.Sqlite.FunctionalTests/MigrationsSqliteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public override async Task Alter_table_add_comment()
);",
@"INSERT INTO ""ef_temp_People"" (""Id"")
SELECT ""Id""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -140,7 +140,7 @@ public override async Task Alter_table_add_comment_non_default_schema()
);",
@"INSERT INTO ""ef_temp_People"" (""Id"")
SELECT ""Id""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -159,7 +159,7 @@ public override async Task Alter_table_change_comment()
);",
@"INSERT INTO ""ef_temp_People"" (""Id"")
SELECT ""Id""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -176,7 +176,7 @@ public override async Task Alter_table_remove_comment()
);",
@"INSERT INTO ""ef_temp_People"" (""Id"")
SELECT ""Id""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand Down Expand Up @@ -204,7 +204,7 @@ public override async Task Rename_table_with_primary_key()
//
@"INSERT INTO ""ef_temp_Persons"" (""Id"")
SELECT ""Id""
FROM Persons;",
FROM ""Persons"";",
//
@"PRAGMA foreign_keys = 0;",
//
Expand Down Expand Up @@ -285,7 +285,7 @@ public override async Task Add_column_with_comment()
//
@"INSERT INTO ""ef_temp_People"" (""FullName"", ""Id"")
SELECT ""FullName"", ""Id""
FROM People;",
FROM ""People"";",
//
@"PRAGMA foreign_keys = 0;",
//
Expand Down Expand Up @@ -325,7 +325,7 @@ public override async Task Add_column_with_check_constraint()
);",
@"INSERT INTO ""ef_temp_People"" (""DriverLicense"", ""Id"")
SELECT ""DriverLicense"", ""Id""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -343,7 +343,7 @@ public override async Task Alter_column_make_required()
);",
@"INSERT INTO ""ef_temp_People"" (""Id"", ""SomeColumn"")
SELECT ""Id"", IFNULL(""SomeColumn"", '')
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -361,7 +361,7 @@ public override async Task Alter_column_make_required_with_index()
);",
@"INSERT INTO ""ef_temp_People"" (""Id"", ""SomeColumn"")
SELECT ""Id"", IFNULL(""SomeColumn"", '')
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -381,7 +381,7 @@ public override async Task Alter_column_make_required_with_composite_index()
);",
@"INSERT INTO ""ef_temp_People"" (""FirstName"", ""Id"", ""LastName"")
SELECT IFNULL(""FirstName"", ''), ""Id"", ""LastName""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -404,7 +404,7 @@ public override async Task Alter_column_make_computed(bool? stored)
);",
@"INSERT INTO ""ef_temp_People"" (""Id"", ""X"", ""Y"")
SELECT ""Id"", ""X"", ""Y""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -424,7 +424,7 @@ public override async Task Alter_column_change_computed()
);",
@"INSERT INTO ""ef_temp_People"" (""Id"", ""X"", ""Y"")
SELECT ""Id"", ""X"", ""Y""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -444,7 +444,7 @@ public override async Task Alter_column_change_computed_type()
);",
@"INSERT INTO ""ef_temp_People"" (""Id"", ""X"", ""Y"")
SELECT ""Id"", ""X"", ""Y""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -462,7 +462,7 @@ public override async Task Alter_column_add_comment()
);",
@"INSERT INTO ""ef_temp_People"" (""Id"")
SELECT ""Id""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -480,7 +480,7 @@ public override async Task Alter_column_change_comment()
);",
@"INSERT INTO ""ef_temp_People"" (""Id"")
SELECT ""Id""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -497,7 +497,7 @@ public override async Task Alter_column_remove_comment()
);",
@"INSERT INTO ""ef_temp_People"" (""Id"")
SELECT ""Id""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -514,7 +514,7 @@ public override async Task Alter_column_set_collation()
);",
@"INSERT INTO ""ef_temp_People"" (""Name"")
SELECT ""Name""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -531,7 +531,7 @@ public override async Task Alter_column_reset_collation()
);",
@"INSERT INTO ""ef_temp_People"" (""Name"")
SELECT ""Name""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -548,7 +548,7 @@ public override async Task Drop_column()
);",
@"INSERT INTO ""ef_temp_People"" (""Id"")
SELECT ""Id""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -565,7 +565,7 @@ public override async Task Drop_column_primary_key()
);",
@"INSERT INTO ""ef_temp_People"" (""SomeColumn"")
SELECT ""SomeColumn""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand Down Expand Up @@ -616,7 +616,7 @@ public override async Task Add_primary_key()
);",
@"INSERT INTO ""ef_temp_People"" (""SomeField"")
SELECT ""SomeField""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -633,7 +633,7 @@ public override async Task Add_primary_key_with_name()
);",
@"INSERT INTO ""ef_temp_People"" (""SomeField"")
SELECT ""SomeField""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -652,7 +652,7 @@ public override async Task Add_primary_key_composite_with_name()
);",
@"INSERT INTO ""ef_temp_People"" (""SomeField1"", ""SomeField2"")
SELECT ""SomeField1"", ""SomeField2""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -669,7 +669,7 @@ public override async Task Drop_primary_key()
);",
@"INSERT INTO ""ef_temp_People"" (""SomeField"")
SELECT ""SomeField""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -688,7 +688,7 @@ public override async Task Add_foreign_key()
);",
@"INSERT INTO ""ef_temp_Orders"" (""CustomerId"", ""Id"")
SELECT ""CustomerId"", ""Id""
FROM Orders;",
FROM ""Orders"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""Orders"";",
@"ALTER TABLE ""ef_temp_Orders"" RENAME TO ""Orders"";",
Expand All @@ -707,7 +707,7 @@ public override async Task Add_foreign_key_with_name()
);",
@"INSERT INTO ""ef_temp_Orders"" (""CustomerId"", ""Id"")
SELECT ""CustomerId"", ""Id""
FROM Orders;",
FROM ""Orders"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""Orders"";",
@"ALTER TABLE ""ef_temp_Orders"" RENAME TO ""Orders"";",
Expand All @@ -725,7 +725,7 @@ public override async Task Drop_foreign_key()
);",
@"INSERT INTO ""ef_temp_Orders"" (""CustomerId"", ""Id"")
SELECT ""CustomerId"", ""Id""
FROM Orders;",
FROM ""Orders"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""Orders"";",
@"ALTER TABLE ""ef_temp_Orders"" RENAME TO ""Orders"";",
Expand All @@ -744,7 +744,7 @@ public override async Task Add_unique_constraint()
);",
@"INSERT INTO ""ef_temp_People"" (""AlternateKeyColumn"", ""Id"")
SELECT ""AlternateKeyColumn"", ""Id""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -764,7 +764,7 @@ public override async Task Add_unique_constraint_composite_with_name()
);",
@"INSERT INTO ""ef_temp_People"" (""AlternateKeyColumn1"", ""AlternateKeyColumn2"", ""Id"")
SELECT ""AlternateKeyColumn1"", ""AlternateKeyColumn2"", ""Id""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -782,7 +782,7 @@ public override async Task Drop_unique_constraint()
);",
@"INSERT INTO ""ef_temp_People"" (""AlternateKeyColumn"", ""Id"")
SELECT ""AlternateKeyColumn"", ""Id""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -801,7 +801,7 @@ public override async Task Add_check_constraint_with_name()
);",
@"INSERT INTO ""ef_temp_People"" (""DriverLicense"", ""Id"")
SELECT ""DriverLicense"", ""Id""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -820,7 +820,7 @@ public override async Task Alter_check_constraint()
);",
@"INSERT INTO ""ef_temp_People"" (""DriverLicense"", ""Id"")
SELECT ""DriverLicense"", ""Id""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand All @@ -838,7 +838,7 @@ public override async Task Drop_check_constraint()
);",
@"INSERT INTO ""ef_temp_People"" (""DriverLicense"", ""Id"")
SELECT ""DriverLicense"", ""Id""
FROM People;",
FROM ""People"";",
@"PRAGMA foreign_keys = 0;",
@"DROP TABLE ""People"";",
@"ALTER TABLE ""ef_temp_People"" RENAME TO ""People"";",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ public virtual void DropColumn_defers_subsequent_RenameColumn()
INSERT INTO ""ef_temp_Blog"" (""Name"")
SELECT ""Title""
FROM Blog;
FROM ""Blog"";
GO
PRAGMA foreign_keys = 0;
Expand Down Expand Up @@ -818,7 +818,7 @@ public virtual void Deferred_RenameColumn_defers_subsequent_AddColumn()
INSERT INTO ""ef_temp_Blog"" (""Name"")
SELECT ""Title""
FROM Blog;
FROM ""Blog"";
GO
PRAGMA foreign_keys = 0;
Expand Down Expand Up @@ -871,7 +871,7 @@ public virtual void Deferred_RenameColumn_defers_subsequent_CreateIndex_unique()
INSERT INTO ""ef_temp_Blog"" (""Name"")
SELECT ""Title""
FROM Blog;
FROM ""Blog"";
GO
PRAGMA foreign_keys = 0;
Expand Down Expand Up @@ -919,7 +919,7 @@ public virtual void DropColumn_defers_subsequent_AddColumn_required()
INSERT INTO ""ef_temp_Blog"" (""Id"")
SELECT ""Id""
FROM Blog;
FROM ""Blog"";
GO
PRAGMA foreign_keys = 0;
Expand Down Expand Up @@ -970,7 +970,7 @@ public virtual void Deferred_AddColumn_defers_subsequent_CreateIndex()
INSERT INTO ""ef_temp_Blog"" (""Id"")
SELECT ""Id""
FROM Blog;
FROM ""Blog"";
GO
PRAGMA foreign_keys = 0;
Expand Down Expand Up @@ -1015,7 +1015,7 @@ public virtual void RenameTable_preserves_pending_rebuilds()
INSERT INTO ""ef_temp_Blog"" (""Id"")
SELECT ""Id""
FROM Blog;
FROM ""Blog"";
GO
PRAGMA foreign_keys = 0;
Expand Down

0 comments on commit 9857e68

Please sign in to comment.