Tobias Moe Thorstensen
Tobias Moe Thorstensen

Reputation: 8981

Using MartenDB for Eventsourcing with Azure Postgres database

We're trying to configure Marten as our EventStore using a Postgres database in Azure. We've provisioned a Azure Database for PostgreSQL single server in Azure.

Ideally we would like Marten to create the database if it not exists. Our problem is that CreateDatabasesForTenants never gets called during services.AddMarten. This is our code:

services.AddMarten(options =>
{
    var connection =
        @"Server=databaseServerName.postgres.database.azure.com;Database=myDatabase;Port=5432;User Id=admin@databaseServerName;Password=apassword;Ssl Mode=VerifyCA;";

    var maintenanceconnectionString = @"Server=databaseServerName.postgres.database.azure.com;Database=postgres;Port=5432;User Id=admin@databaseServerName;Password=apassword;Ssl Mode=VerifyCA;";
    
    options.Connection(connection);
    options.CreateDatabasesForTenants(options =>
    {
        options.MaintenanceDatabase(maintenanceconnectionString);
        
        options.ForTenant()
            .CheckAgainstPgDatabase()
            .WithOwner("postgres")
            .WithEncoding("UTF-8")
            .ConnectionLimit(-1)
            .OnDatabaseCreated(_ =>
            {
              
            });
    });
});

Everytime we access the IDocumentStore we get the following message:

Npgsql.PostgresException (0x80004005): 3D000: database "myDatabase" does not exist

Obviously, it doesn't exist, but why is the CreateDatabaseForTenants never called? What am I missing here?

Upvotes: 1

Views: 265

Answers (0)

Related Questions