Skip to content
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

Use default postgres public schema when no schema is provided. #1013

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
30 changes: 30 additions & 0 deletions src/Persistence/PostgresqlTests/ConfigureWithDefaultSchema.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using IntegrationTests;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Shouldly;
using Wolverine;
using Wolverine.Postgresql;
using Wolverine.RDBMS.Transport;
using Wolverine.Runtime;

namespace PostgresqlTests;

public class ConfigureWithDefaultSchema
{
[Fact]
public async Task should_use_public_as_default_schema()
{
var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
// no schema provided
opts.UsePostgresqlPersistenceAndTransport(Servers.PostgresConnectionString)
.AutoProvision();
}).StartAsync();

var runtime = host.Services.GetRequiredService<IWolverineRuntime>();

runtime.Options.Transports.OfType<DatabaseControlTransport>().Single()
.Database.Settings.SchemaName.ShouldBe("public");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,19 @@ public static PostgresqlPersistenceExpression UsePostgresqlPersistenceAndTranspo
}
};

if (schema.IsNotEmpty())
{
extension.Settings.SchemaName = schema;
}
else
if (schema.IsEmpty())
{
schema = "public";
}

extension.Settings.SchemaName = schema;
extension.Settings.ScheduledJobLockId = $"{schema}:scheduled-jobs".GetDeterministicHashCode();
options.Include(extension);

options.Include<PostgresqlBackedPersistence>(x =>
{
x.Settings.ConnectionString = connectionString;

if (schema.IsNotEmpty())
{
x.Settings.SchemaName = schema;
}
else
{
schema = "public";

}

x.Settings.SchemaName = schema;
x.Settings.ScheduledJobLockId = $"{schema}:scheduled-jobs".GetDeterministicHashCode();
});

Expand Down
Loading