-
Notifications
You must be signed in to change notification settings - Fork 256
Implement support for PG18 WITHOUT OVERLAPS #3709
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
89 changes: 89 additions & 0 deletions
89
src/EFCore.PG/Extensions/BuilderExtensions/NpgsqlKeyBuilderExtensions.cs
This file contains hidden or 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,89 @@ | ||
| using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata.Internal; | ||
|
|
||
| // ReSharper disable once CheckNamespace | ||
| namespace Microsoft.EntityFrameworkCore; | ||
|
|
||
| /// <summary> | ||
| /// Npgsql specific extension methods for <see cref="KeyBuilder" />. | ||
| /// </summary> | ||
| public static class NpgsqlKeyBuilderExtensions | ||
| { | ||
| #region WithoutOverlaps | ||
|
|
||
| /// <summary> | ||
| /// Configures the key to use the PostgreSQL WITHOUT OVERLAPS feature. | ||
| /// The last property in the key must be a PostgreSQL range type. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// See https://www.postgresql.org/docs/current/sql-createtable.html for more information. | ||
| /// </remarks> | ||
| /// <param name="keyBuilder">The builder for the key being configured.</param> | ||
| /// <param name="withoutOverlaps">A value indicating whether to use WITHOUT OVERLAPS.</param> | ||
| /// <returns>A builder to further configure the key.</returns> | ||
| public static KeyBuilder WithoutOverlaps(this KeyBuilder keyBuilder, bool withoutOverlaps = true) | ||
| { | ||
| Check.NotNull(keyBuilder, nameof(keyBuilder)); | ||
|
|
||
| keyBuilder.Metadata.SetWithoutOverlaps(withoutOverlaps); | ||
|
|
||
| return keyBuilder; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Configures the key to use the PostgreSQL WITHOUT OVERLAPS feature. | ||
| /// The last property in the key must be a PostgreSQL range type. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// See https://www.postgresql.org/docs/current/sql-createtable.html for more information. | ||
| /// </remarks> | ||
| /// <param name="keyBuilder">The builder for the key being configured.</param> | ||
| /// <param name="withoutOverlaps">A value indicating whether to use WITHOUT OVERLAPS.</param> | ||
| /// <returns>A builder to further configure the key.</returns> | ||
| public static KeyBuilder<TEntity> WithoutOverlaps<TEntity>(this KeyBuilder<TEntity> keyBuilder, bool withoutOverlaps = true) | ||
| => (KeyBuilder<TEntity>)WithoutOverlaps((KeyBuilder)keyBuilder, withoutOverlaps); | ||
|
|
||
| /// <summary> | ||
| /// Configures the key to use the PostgreSQL WITHOUT OVERLAPS feature. | ||
| /// The last property in the key must be a PostgreSQL range type. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// See https://www.postgresql.org/docs/current/sql-createtable.html for more information. | ||
| /// </remarks> | ||
| /// <param name="keyBuilder">The builder for the key being configured.</param> | ||
| /// <param name="withoutOverlaps">A value indicating whether to use WITHOUT OVERLAPS.</param> | ||
| /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param> | ||
| /// <returns>A builder to further configure the key.</returns> | ||
| public static IConventionKeyBuilder? WithoutOverlaps( | ||
| this IConventionKeyBuilder keyBuilder, | ||
| bool? withoutOverlaps = true, | ||
| bool fromDataAnnotation = false) | ||
| { | ||
| if (keyBuilder.CanSetWithoutOverlaps(withoutOverlaps, fromDataAnnotation)) | ||
| { | ||
| keyBuilder.Metadata.SetWithoutOverlaps(withoutOverlaps, fromDataAnnotation); | ||
|
|
||
| return keyBuilder; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns a value indicating whether WITHOUT OVERLAPS can be configured. | ||
| /// </summary> | ||
| /// <param name="keyBuilder">The builder for the key being configured.</param> | ||
| /// <param name="withoutOverlaps">A value indicating whether to use WITHOUT OVERLAPS.</param> | ||
| /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param> | ||
| /// <returns><see langword="true" /> if the key can be configured with WITHOUT OVERLAPS.</returns> | ||
| public static bool CanSetWithoutOverlaps( | ||
| this IConventionKeyBuilder keyBuilder, | ||
| bool? withoutOverlaps = true, | ||
| bool fromDataAnnotation = false) | ||
| { | ||
| Check.NotNull(keyBuilder, nameof(keyBuilder)); | ||
|
|
||
| return keyBuilder.CanSetAnnotation(NpgsqlAnnotationNames.WithoutOverlaps, withoutOverlaps, fromDataAnnotation); | ||
| } | ||
|
|
||
| #endregion WithoutOverlaps | ||
| } |
61 changes: 61 additions & 0 deletions
61
src/EFCore.PG/Extensions/MetadataExtensions/NpgsqlKeyExtensions.cs
This file contains hidden or 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,61 @@ | ||
| using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata.Internal; | ||
|
|
||
| // ReSharper disable once CheckNamespace | ||
| namespace Microsoft.EntityFrameworkCore; | ||
|
|
||
| /// <summary> | ||
| /// Extension methods for <see cref="IKey" /> for Npgsql-specific metadata. | ||
| /// </summary> | ||
| public static class NpgsqlKeyExtensions | ||
| { | ||
| #region WithoutOverlaps | ||
|
|
||
| /// <summary> | ||
| /// Returns a value indicating whether the key uses the PostgreSQL WITHOUT OVERLAPS feature. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// See https://www.postgresql.org/docs/current/sql-createtable.html for more information. | ||
| /// </remarks> | ||
| /// <param name="key">The key.</param> | ||
| /// <returns><see langword="true" /> if the key uses WITHOUT OVERLAPS.</returns> | ||
| public static bool? GetWithoutOverlaps(this IReadOnlyKey key) | ||
| => (bool?)key[NpgsqlAnnotationNames.WithoutOverlaps]; | ||
|
|
||
| /// <summary> | ||
| /// Sets a value indicating whether the key uses the PostgreSQL WITHOUT OVERLAPS feature. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// See https://www.postgresql.org/docs/current/sql-createtable.html for more information. | ||
| /// </remarks> | ||
| /// <param name="key">The key.</param> | ||
| /// <param name="withoutOverlaps">The value to set.</param> | ||
| public static void SetWithoutOverlaps(this IMutableKey key, bool? withoutOverlaps) | ||
| => key.SetOrRemoveAnnotation(NpgsqlAnnotationNames.WithoutOverlaps, withoutOverlaps); | ||
|
|
||
| /// <summary> | ||
| /// Sets a value indicating whether the key uses the PostgreSQL WITHOUT OVERLAPS feature. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// See https://www.postgresql.org/docs/current/sql-createtable.html for more information. | ||
| /// </remarks> | ||
| /// <param name="key">The key.</param> | ||
| /// <param name="withoutOverlaps">The value to set.</param> | ||
| /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param> | ||
| /// <returns>The configured value.</returns> | ||
| public static bool? SetWithoutOverlaps(this IConventionKey key, bool? withoutOverlaps, bool fromDataAnnotation = false) | ||
| { | ||
| key.SetOrRemoveAnnotation(NpgsqlAnnotationNames.WithoutOverlaps, withoutOverlaps, fromDataAnnotation); | ||
|
|
||
| return withoutOverlaps; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns the <see cref="ConfigurationSource" /> for whether the key uses WITHOUT OVERLAPS. | ||
| /// </summary> | ||
| /// <param name="key">The key.</param> | ||
| /// <returns>The <see cref="ConfigurationSource" />.</returns> | ||
| public static ConfigurationSource? GetWithoutOverlapsConfigurationSource(this IConventionKey key) | ||
| => key.FindAnnotation(NpgsqlAnnotationNames.WithoutOverlaps)?.GetConfigurationSource(); | ||
|
|
||
| #endregion WithoutOverlaps | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.