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
Create index with include columns dont work #1740
Comments
@cpistiner, I'm unable to reproduce this behavior. Could you provide a unit test or an exmaple program that demonstrates the issue? For instance, the following test passes: [Test]
public void CanGenerateIndexWithColumns() {
var expression = new CreateIndexExpression();
expression.Index.Name = "IDX_Test";
expression.Index.TableName = "TestTable";
expression.Index.Columns.Add(new IndexColumnDefinition {
Name = "Column1",
Direction = Direction.Ascending
});
var includes = expression.Index.GetAdditionalFeature(SqlServerExtensions.IncludesList, () => new List<IndexIncludeDefinition>());
includes.Add(new IndexIncludeDefinition { Name = "Id1" });
includes.Add(new IndexIncludeDefinition { Name = "Id2" });
var result = Generator.Generate(expression);
result.ShouldBe("CREATE INDEX [IDX_Test] ON [dbo].[TestTable] ([Column1] ASC) INCLUDE ([Id1], [Id2])");
}
Results in a pass:
> CREATE INDEX [IDX_Test] ON [dbo].[TestTable] ([Column1] ASC) INCLUDE ([Id1], [Id2]) |
There might be a subtle bug introduced in 5.1.0 by my change to make Create.UniqueConstraint API as complete as Create.Index It might also be that it generates the right sql but logs it to the console incorrectly. |
Hi @schambers I'm not sure it's the same scenario. I run a Migration class Up() method in project build events.
|
Hi @jzabroski Expected behavior But the result is: The result is exactly what SQL shows me. I select the index generated and then "View Code" action. |
@cpistiner My test should end up being the same outcome but there's a chance I missed something there. @jzabroski, If you're able to point me in a specific area I can try to identify if there's a bug here. I see some commits from our changes you mentioned in 5.1 but I'm unsure how they would cause this bug |
@schambers I would just put the example code he gave in the Example app in the main branch. You can run it against SQL Server LocalDB on Windows. but with MAC OSX, you will need something like this using a docker container: https://www.marcusturewicz.com/blog/develop-against-sql-server-on-a-mac-with-docker-and-vs-code/ |
@cpistiner Can you confirm you are running both the migrations assembly and the runner with 5.1.0? I was thinking about this on my morning commute and thats the only thing that makes me doubt your report contains everything needed to repro. |
Hi @jzabroski Sorry for the delay in responding. Yes, I confirm. I'm using 5.1.0. This is the command: run Migrate.exe from the 5.1.0 version downloaded from nuget. |
Hi @schambers I'm trying to do a unit test based on your example but i dont know one thing. The class Generator is part of FluentMigrator?
|
@schambers I'm doing a deeper review to understand what is going on here. If you have time to run the below new unit tests and debug them, that would be very helpful. - I am just writing them here directly in the GitHub comments without testing. This test seems to almost directly test your scenario: fluentmigrator/test/FluentMigrator.Tests/Unit/Generators/SqlServer2008/SqlServer2008IndexTests.cs Lines 268 to 275 in ce086ce
The precise regression test should probably be: [Test]
public void CanCreateIndexWithMultipleIncludeColumnStatements()
{
var expression = GeneratorTestHelper.GetCreateIndexExpression();
var x = new CreateIndexExpressionBuilder(expression).Include("TestColumn2").Include("TestColumn3");
var result = _generator.Generate(expression);
result.ShouldBe("CREATE INDEX [TestIndex] ON [dbo].[TestTable1] ([TestColumn1] ASC) INCLUDE ([TestColumn2], [TestColumn3])");
}
[Test]
public void CanCreateIndexWithOneIncludeStatementMultipleColumns()
{
var expression = GeneratorTestHelper.GetCreateIndexExpression();
var x = new CreateIndexExpressionBuilder(expression).Include("TestColumn2", "TestColumn3");
var result = _generator.Generate(expression);
result.ShouldBe("CREATE INDEX [TestIndex] ON [dbo].[TestTable1] ([TestColumn1] ASC) INCLUDE ([TestColumn2], [TestColumn3])");
} Tangential but unrelated: I reviewed a bunch of the tests here this morning to understand if there is any other potential regression. This test assertion surprises me, as I would expect the second test to produce a different output: fluentmigrator/test/FluentMigrator.Tests/Unit/Generators/SqlServer2005/SqlServer2005IndexTests.cs Lines 121 to 139 in ce086ce
It looks like this IndexColumnNullsDistinct feature was introduced in SqlServer2008Generator : fluentmigrator/src/FluentMigrator.Runner.SqlServer/Generators/SqlServer/SqlServer2008Generator.cs Lines 78 to 107 in ce086ce
|
Hi all, I can do the unit test and it's wokrs! But i dont know if the same code to run with Migrate class. Again I tell you how I execute the database update. I have a command to run Migrate.exe when compile the solution. The command is: packages\FluentMigrator.Console.5.1.0\tools\net48\any\Migrate /configPath=Web\Web.config /connectionString=transoftWeb /timeout=600 /db sqlserver2012 /target Infraestructura\bin\Debug\Infraestructura.dll /task=migrate This command execute the migrate class. Migrate class
Unit test
|
@cpistiner The code works fine. See attached PR which I will make part of the core demo. My guess is you accidentally included Postgres extension methods rather than SqlServer. |
Fixes #1740: Example creating index with multiple includes
Describe the bug
Create an index using WithOptions().Include("ColumnName") but don't work. The index is created without INCLUDE clause.
To Reproduce
Create.Index("IX_AvisoDeDeudaDRC").OnTable("DetalleResumenDeCuenta")
.OnColumn("Saldo").Ascending()
.WithOptions().NonClustered()
.Include("IdComprobante").Include("IdResponsable");
Expected behavior
I expected this:
CREATE NONCLUSTERED INDEX [IX_AvisoDeDeudaDRC]
ON [dbo].[DetalleResumenDeCuenta]([Saldo] ASC)
INCLUDE([IdComprobante], [IdResponsable]);
But the result is:
CREATE NONCLUSTERED INDEX [IX_AvisoDeDeudaDRC]
ON [dbo].[DetalleResumenDeCuenta]([Saldo] ASC);
Information (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: