-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Register PG extensions in the model by convention (#2161)
By scanning property types in the model. Closes #2137
- Loading branch information
Showing
15 changed files
with
205 additions
and
27 deletions.
There are no files selected for viewing
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
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
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
16 changes: 16 additions & 0 deletions
16
src/EFCore.PG.NTS/Internal/NpgsqlNetTopologySuiteConventionSetPlugin.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,16 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Npgsql.EntityFrameworkCore.PostgreSQL.Internal; | ||
|
||
public class NpgsqlNetTopologySuiteConventionSetPlugin : IConventionSetPlugin | ||
{ | ||
public virtual ConventionSet ModifyConventions(ConventionSet conventionSet) | ||
{ | ||
conventionSet.ModelFinalizingConventions.Add(new NpgsqlNetTopologySuiteExtensionAddingConvention()); | ||
|
||
return conventionSet; | ||
} | ||
} | ||
|
12 changes: 12 additions & 0 deletions
12
src/EFCore.PG.NTS/Internal/NpgsqlNetTopologySuiteExtensionAddingConvention.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,12 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Npgsql.EntityFrameworkCore.PostgreSQL.Internal; | ||
|
||
public class NpgsqlNetTopologySuiteExtensionAddingConvention : IModelFinalizingConvention | ||
{ | ||
/// <inheritdoc /> | ||
public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context) | ||
=> modelBuilder.HasPostgresExtension("postgis"); | ||
} |
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
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
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
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
47 changes: 47 additions & 0 deletions
47
src/EFCore.PG/Metadata/Conventions/NpgsqlPostgresExtensionDiscoveryConvention.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,47 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Npgsql.EntityFrameworkCore.PostgreSQL.Metadata.Conventions; | ||
|
||
public class NpgsqlPostgresExtensionDiscoveryConvention : IModelFinalizingConvention | ||
{ | ||
private readonly IRelationalTypeMappingSource _typeMappingSource; | ||
|
||
public NpgsqlPostgresExtensionDiscoveryConvention(IRelationalTypeMappingSource typeMappingSource) | ||
{ | ||
_typeMappingSource = typeMappingSource; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context) | ||
{ | ||
foreach (var entityType in modelBuilder.Metadata.GetEntityTypes()) | ||
{ | ||
foreach (var property in entityType.GetDeclaredProperties()) | ||
{ | ||
var typeMapping = (RelationalTypeMapping?)property.FindTypeMapping() | ||
?? _typeMappingSource.FindMapping((IProperty)property); | ||
|
||
if (typeMapping is null) | ||
{ | ||
continue; | ||
} | ||
|
||
switch (typeMapping.StoreType) | ||
{ | ||
case "hstore": | ||
modelBuilder.HasPostgresExtension("hstore"); | ||
continue; | ||
case "citext": | ||
modelBuilder.HasPostgresExtension("citext"); | ||
continue; | ||
case "ltree": | ||
case "lquery": | ||
case "ltxtquery": | ||
modelBuilder.HasPostgresExtension("ltree"); | ||
continue; | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
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