Skip to content
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

SQL Server migration SQL is incorrect for INDEX creation where OPTIONS are present along with a "legacy filter" #24640

Closed
reskusic opened this issue Apr 12, 2021 · 4 comments · Fixed by #24643
Assignees
Labels
area-migrations area-sqlserver closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@reskusic
Copy link

During migration SQL generation for SQL Server the following test (which can be added to SqlServerMigrationSqlGeneratorTest.cs) will unexpectedly fail:

        [ConditionalFact]
        public void CreateIndexOperation_unique_online()
        {
            Generate(
                new CreateIndexOperation
                {
                    Name = "IX_People_Name",
                    Table = "People",
                    Schema = "dbo",
                    Columns = new[] { "FirstName", "LastName" },
                    IsUnique = true,
                    [SqlServerAnnotationNames.CreatedOnline] = true
                });

            AssertSql(
                @"CREATE UNIQUE INDEX [IX_People_Name] ON [dbo].[People] ([FirstName], [LastName]) WHERE [FirstName] IS NOT NULL AND [LastName] IS NOT NULL WITH (ONLINE = ON);
");
        }

The actual generated SQL is as follows:

CREATE UNIQUE INDEX [IX_People_Name] ON [dbo].[People] ([FirstName], [LastName]) WITH (ONLINE = ON) WHERE [FirstName] IS NOT NULL AND [LastName] IS NOT NULL;

This seems to be invalid TSQL, with the WITH and WHERE clauses out of order.

This was found in EF Core 3.1, but the migration generating code seems to still have the issue in "main".

@roji
Copy link
Member

roji commented Apr 13, 2021

Thanks, submitted #24643 as a fix. As noted, this only occurs with "legacy index filters", so only with migrations from before EF Core 2.0.0.

@ErikEJ
Copy link
Contributor

ErikEJ commented Apr 13, 2021

Is EF Core 1 supported?

@roji
Copy link
Member

roji commented Apr 13, 2021

@ErikEJ no, but this is about migrations which were generated in pre-2.0, and which could still be in use in new versions (so not about fixing a runtime issue in pre-2.0). Maybe a bit far-fetched, but...

@reskusic
Copy link
Author

Thanks for the quick turnaround on this issue!

@ajcvickers ajcvickers modified the milestones: 6.0.0, 6.0.0-preview5 Apr 26, 2021
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Apr 28, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-preview5, 6.0.0 Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-migrations area-sqlserver closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants