-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add EF extension to have an ColumnStoreIndex
- Loading branch information
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...ctionHandling.Runner/MigrationExtensions/ExtendedSqlServerMigrationsAnnotationProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Be.Vlaanderen.Basisregisters.ProjectionHandling.Runner.MigrationExtensions | ||
{ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
using Microsoft.EntityFrameworkCore.SqlServer.Migrations.Internal; | ||
|
||
public class ExtendedSqlServerMigrationsAnnotationProvider : SqlServerMigrationsAnnotationProvider | ||
{ | ||
public ExtendedSqlServerMigrationsAnnotationProvider(MigrationsAnnotationProviderDependencies dependencies) : base(dependencies) | ||
{ } | ||
|
||
public override IEnumerable<IAnnotation> For(IIndex index) | ||
{ | ||
var baseAnnotations = base.For(index); | ||
var customAnnotations = index.GetAnnotations().Where(a => a.Name == IndexExtensions.ColumnStoreIndexAnnotationName); | ||
|
||
return baseAnnotations.Concat(customAnnotations); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
....ProjectionHandling.Runner/MigrationExtensions/ExtendedSqlServerMigrationsSqlGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace Be.Vlaanderen.Basisregisters.ProjectionHandling.Runner.MigrationExtensions | ||
{ | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
using Microsoft.EntityFrameworkCore.Migrations.Operations; | ||
|
||
public class ExtendedSqlServerMigrationsSqlGenerator : SqlServerMigrationsSqlGenerator | ||
{ | ||
public ExtendedSqlServerMigrationsSqlGenerator(MigrationsSqlGeneratorDependencies dependencies, IMigrationsAnnotationProvider migrationsAnnotations) : | ||
base(dependencies, migrationsAnnotations) | ||
{ } | ||
|
||
protected override void IndexTraits(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder) | ||
{ | ||
base.IndexTraits(operation, model, builder); | ||
|
||
var includeIndexAnnotation = operation.FindAnnotation(IndexExtensions.ColumnStoreIndexAnnotationName); | ||
if (includeIndexAnnotation != null) | ||
{ | ||
builder.Append("COLUMNSTORE "); | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...laanderen.Basisregisters.ProjectionHandling.Runner/MigrationExtensions/IndexExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace Be.Vlaanderen.Basisregisters.ProjectionHandling.Runner.MigrationExtensions | ||
{ | ||
using System.Text; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
public static class IndexExtensions | ||
{ | ||
public static string ColumnStoreIndexAnnotationName = "SqlServer:ColumnStoreIndex"; | ||
|
||
public static IndexBuilder IsColumnStore(this IndexBuilder indexBuilder, string name) | ||
{ | ||
var includeStatement = new StringBuilder(); | ||
|
||
indexBuilder.HasAnnotation(ColumnStoreIndexAnnotationName, includeStatement.ToString()); | ||
indexBuilder.HasName(name); | ||
|
||
return indexBuilder; | ||
} | ||
} | ||
} |