Skip to content

Database

The Supabase Database module connects your EF Core DbContext to Supabase's managed PostgreSQL. It automatically builds connection strings for all three Supabase connection modes.

Overview

services.AddDeepstaging(options => options
    .AddSupabaseDatabase<AppRuntime, AppDbContext>());

This registers AppDbContext with a connection string derived from your Supabase project URL and database credentials.

Configuration

appsettings.json
{
  "Deepstaging": {
    "Supabase": {
      "ProjectUrl": "https://your-project.supabase.co",
      "Database": {
        "PoolerMode": "Transaction",
        "Region": "us-east-1"
      }
    }
  }
}
User secrets (production credentials)
dotnet user-secrets set "Deepstaging:Supabase:Database:Password" "your-db-password"

Options

Property Type Default Description
Password string Database password (from Supabase dashboard → Settings → Database)
PoolerMode SupabasePoolerMode Transaction Connection mode: Direct, Session, or Transaction
Region string AWS region for pooled connections (e.g., us-east-1)
Database string "postgres" Target database name
ConnectionString string Raw connection string override (bypasses all other settings)

Connection Modes

Supabase offers three ways to connect to your database:

Direct

Connects directly to the Postgres instance. Best for migrations, admin tasks, and long-running operations.

Host: db.{project-ref}.supabase.co
Port: 5432
User: postgres
{ "PoolerMode": "Direct" }

Note

Direct connections don't require Region. They're limited to a smaller connection pool — use pooled modes for application traffic.

Session Pooler

Maintains persistent connections through Supavisor. Supports prepared statements and session-level features.

Host: aws-0-{region}.pooler.supabase.com
Port: 5432
User: postgres.{project-ref}
{ "PoolerMode": "Session", "Region": "us-east-1" }

Transaction Pooler

Shares connections across requests at the transaction level. Best for serverless and high-concurrency workloads.

Host: aws-0-{region}.pooler.supabase.com
Port: 6543
User: postgres.{project-ref}
{ "PoolerMode": "Transaction", "Region": "us-east-1" }

Warning

Transaction pooling doesn't support prepared statements. If EF Core uses them, switch to Session mode or configure Npgsql to disable prepared statements.

Raw Connection String

To bypass the connection string builder entirely, provide a raw connection string:

{
  "Deepstaging": {
    "Supabase": {
      "Database": {
        "ConnectionString": "Host=db.xyz.supabase.co;Port=5432;Database=postgres;Username=postgres;Password=secret;SSL Mode=Require"
      }
    }
  }
}

This takes precedence over all other database configuration.

Bridging to Other Providers

Use AddSupabaseDatabaseConnectionString to feed the Supabase connection string into other Deepstaging infrastructure services:

services.AddDeepstaging(options => options
    .AddSupabaseDatabaseConnectionString<AppRuntime, DeepstagingPostgresOptions>(
        (pgOpts, cs) => pgOpts.ConnectionString = cs)
    .AddPostgresAuditStore()
    .AddPostgresDataStore<AppRuntime, Article>());

This lets you use Supabase's managed Postgres as the backing store for Audit Trail, Data Store, Notifications, and Background Jobs — without those modules knowing anything about Supabase.