Skip to content

Commit b3b0bd5

Browse files
authored
fix: Connect seed-dev demo operator seeder to identity database (#2144)
seedDemoOperator used DATABASE_URL directly, which points to meridian_platform. The identity repository needs meridian_identity where the org_<tenant> schemas contain the identity tables. Derive the identity DSN from DATABASE_URL by replacing the database component, matching how the main binary routes per-service connections via ServiceDatabases. Co-authored-by: Ben Coombs <bjcoombs@users.noreply.github.com>
1 parent 98230f2 commit b3b0bd5

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

cmd/seed-dev/cmd/root.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"net/http"
9+
"net/url"
910
"os"
1011
"strings"
1112
"time"
@@ -400,13 +401,22 @@ func seedDemoOperator(ctx context.Context) error {
400401

401402
fmt.Println("\n--- Seed Demo Operator ---")
402403

403-
dsn := os.Getenv("DATABASE_URL")
404-
if dsn == "" {
404+
baseDSN := os.Getenv("DATABASE_URL")
405+
if baseDSN == "" {
405406
return ErrDatabaseURLRequired
406407
}
407408

409+
// DATABASE_URL points to the platform database (meridian_platform).
410+
// The identity repo needs meridian_identity. Derive the DSN by
411+
// replacing the database component, matching how the main binary
412+
// routes per-service connections via ServiceDatabases.
413+
identityDSN, err := replaceDatabase(baseDSN, "meridian_identity")
414+
if err != nil {
415+
return fmt.Errorf("derive identity DSN: %w", err)
416+
}
417+
408418
db, err := bootstrap.NewDatabase(ctx, bootstrap.DatabaseConfig{
409-
DSN: dsn,
419+
DSN: identityDSN,
410420
MaxOpenConns: 2,
411421
MaxIdleConns: 1,
412422
})
@@ -426,3 +436,13 @@ func seedDemoOperator(ctx context.Context) error {
426436

427437
return nil
428438
}
439+
440+
// replaceDatabase swaps the database name in a PostgreSQL DSN URL.
441+
func replaceDatabase(baseDSN, database string) (string, error) {
442+
parsed, err := url.Parse(baseDSN)
443+
if err != nil {
444+
return "", fmt.Errorf("parse DSN: %w", err)
445+
}
446+
parsed.Path = "/" + database
447+
return parsed.String(), nil
448+
}

0 commit comments

Comments
 (0)