-3

Was trying to create a database (retmarkdb), but only datatabase "postgres" (with password 'retmark123') is created.

// RetmarkApp.AppHost/AppHost.cs

var builder = DistributedApplication.CreateBuilder(args);

// 1. PostgreSQL с фиксированным паролем 
var postgres = builder.AddPostgres("postgresdb")
    .WithEnvironment("POSTGRES_PASSWORD", "retmark123")
    .WithDataVolume()
    .WithPgAdmin(); 

// 2. Создаём базу автоматически через скрипт 
var databaseName = "retmarkdb";

var creationScript = $$"""
                       -- Create the database
                       CREATE DATABASE {{databaseName}};

                       """;
var db = postgres.AddDatabase(databaseName)
    .WithCreationScript(creationScript);

// 3. MongoDB
var mongo = builder.AddMongoDB("mongo")
    .WithDataVolume()
    .WithMongoExpress();

// 4. Ваш сервер
builder.AddProject<Projects.RetmarkApp_Server>("retmark-server")
    .WithReference(db)
    .WithReference(mongo)
    .WithExternalHttpEndpoints()
    .WaitFor(db);             

builder.Build().Run();
2
  • This file doesn't create a database postgres at all. Are you looking at the wrong container? Or a container created by a previous run with different code? What does the generated docker-compose file look like? Commented Nov 17 at 15:01
  • 1
    If you check the AddDatabase docs you'll see that the first string is the name of the resource. The second is the database name. Without an explicit database name, the default postgres is used. Since you haven't provided separate database names, you created the same database under two different resource names, on the server named postgresdb Commented Nov 17 at 15:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.