Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public override MethodCallCodeFragment GenerateFluentApi(IModel model, IAnnotati
Check.NotNull(model, nameof(model));
Check.NotNull(annotation, nameof(annotation));

if (annotation.Name.StartsWith(NpgsqlAnnotationNames.PostgresExtensionPrefix))
if (annotation.Name.StartsWith(NpgsqlAnnotationNames.PostgresExtensionPrefix, StringComparison.Ordinal))
{
var extension = new PostgresExtension(model, annotation.Name);

Expand Down
40 changes: 38 additions & 2 deletions src/EFCore.PG/Extensions/NpgsqlModelBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,53 @@ public static ModelBuilder ForNpgsqlUseIdentityColumns(

#region Extensions

/// <summary>
/// Registers a PostgreSQL extension in the model.
/// </summary>
/// <param name="modelBuilder">The model builder in which to define the extension.</param>
/// <param name="schema">The schema in which to create the extension.</param>
/// <param name="name">The name of the extension to create.</param>
/// <param name="version">The version of the extension.</param>
/// <returns>
/// The updated <see cref="ModelBuilder"/>.
/// </returns>
/// <remarks>
/// See: https://www.postgresql.org/docs/current/external-extensions.html
/// </remarks>
/// <exception cref="ArgumentNullException"><paramref name="modelBuilder"/></exception>
[NotNull]
public static ModelBuilder HasPostgresExtension(
[NotNull] this ModelBuilder modelBuilder,
[NotNull] string name)
[CanBeNull] string schema,
[NotNull] string name,
[CanBeNull] string version)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
Check.NullButNotEmpty(schema, nameof(schema));
Check.NotEmpty(name, nameof(name));

modelBuilder.Model.Npgsql().GetOrAddPostgresExtension(name);
modelBuilder.Model.Npgsql().GetOrAddPostgresExtension(schema, name, version);
return modelBuilder;
}

/// <summary>
/// Registers a PostgreSQL extension in the model.
/// </summary>
/// <param name="modelBuilder">The model builder in which to define the extension.</param>
/// <param name="name">The name of the extension to create.</param>
/// <returns>
/// The updated <see cref="ModelBuilder"/>.
/// </returns>
/// <remarks>
/// See: https://www.postgresql.org/docs/current/external-extensions.html
/// </remarks>
/// <exception cref="ArgumentNullException"><paramref name="modelBuilder"/></exception>
[NotNull]
public static ModelBuilder HasPostgresExtension(
[NotNull] this ModelBuilder modelBuilder,
[NotNull] string name)
=> modelBuilder.HasPostgresExtension(null, name, null);

#endregion

#region Enums
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.PG/Metadata/INpgsqlModelAnnotations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface INpgsqlModelAnnotations : IRelationalModelAnnotations

[NotNull]
[ItemNotNull]
IReadOnlyList<IPostgresExtension> PostgresExtensions { get; }
IReadOnlyList<PostgresExtension> PostgresExtensions { get; }

[NotNull]
[ItemNotNull]
Expand Down
12 changes: 0 additions & 12 deletions src/EFCore.PG/Metadata/IPostgresExtension.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public class NpgsqlAlterDatabaseOperationAnnotations : RelationalAnnotations

[NotNull]
[ItemNotNull]
public virtual IReadOnlyList<IPostgresExtension> PostgresExtensions
public virtual IReadOnlyList<PostgresExtension> PostgresExtensions
=> PostgresExtension.GetPostgresExtensions(Metadata).ToArray();

[NotNull]
[ItemNotNull]
public virtual IReadOnlyList<IPostgresExtension> OldPostgresExtensions
public virtual IReadOnlyList<PostgresExtension> OldPostgresExtensions
=> PostgresExtension.GetPostgresExtensions(_oldDatabase).ToArray();

[NotNull]
Expand All @@ -48,5 +48,12 @@ public virtual IReadOnlyList<PostgresRange> OldPostgresRanges
public NpgsqlAlterDatabaseOperationAnnotations([NotNull] AlterDatabaseOperation operation)
: base(operation)
=> _oldDatabase = operation.OldDatabase;

[NotNull]
public virtual PostgresExtension GetOrAddPostgresExtension(
[CanBeNull] string schema,
[NotNull] string name,
[CanBeNull] string version)
=> PostgresExtension.GetOrAddPostgresExtension((IMutableAnnotatable)Metadata, schema, name, version);
}
}
9 changes: 8 additions & 1 deletion src/EFCore.PG/Metadata/NpgsqlDatabaseModelAnnotations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class NpgsqlDatabaseModelAnnotations : RelationalAnnotations
{
[NotNull]
[ItemNotNull]
public virtual IReadOnlyList<IPostgresExtension> PostgresExtensions
public virtual IReadOnlyList<PostgresExtension> PostgresExtensions
=> PostgresExtension.GetPostgresExtensions(Metadata).ToArray();

[NotNull]
Expand All @@ -25,5 +25,12 @@ public virtual IReadOnlyList<PostgresRange> PostgresRanges

/// <inheritdoc />
public NpgsqlDatabaseModelAnnotations([NotNull] DatabaseModel model) : base(model) {}

[NotNull]
public virtual PostgresExtension GetOrAddPostgresExtension(
[CanBeNull] string schema,
[NotNull] string name,
[CanBeNull] string version)
=> PostgresExtension.GetOrAddPostgresExtension((IMutableAnnotatable)Metadata, schema, name, version);
}
}
10 changes: 7 additions & 3 deletions src/EFCore.PG/Metadata/NpgsqlModelAnnotations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ protected virtual bool SetValueGenerationStrategy(NpgsqlValueGenerationStrategy?

#region PostgreSQL Extensions

public virtual PostgresExtension GetOrAddPostgresExtension([NotNull] string name)
=> PostgresExtension.GetOrAddPostgresExtension((IMutableModel)Model, name);
[NotNull]
public virtual PostgresExtension GetOrAddPostgresExtension(
[CanBeNull] string schema,
[NotNull] string name,
[CanBeNull] string version)
=> PostgresExtension.GetOrAddPostgresExtension((IMutableAnnotatable)Model, schema, name, version);

public virtual IReadOnlyList<IPostgresExtension> PostgresExtensions
public virtual IReadOnlyList<PostgresExtension> PostgresExtensions
=> PostgresExtension.GetPostgresExtensions(Model).ToArray();

#endregion
Expand Down
Loading