Since you already have a [NestJS backend architecture with TypeORM](https://github.com/aj1126/FamilyAccountant), integrating Supabase is incredibly straightforward. Because Supabase is just PostgreSQL under the hood, you don’t need to rewrite your backend codebase to use a custom Supabase SDK. Instead, you can plug your Supabase connection string directly into your existing TypeORM configuration.
Here is the exact step-by-step workflow to connect your project:
1. Retrieve Your Cloud Connection String
Since you are currently inside your [Supabase Settings Panel](https://supabase.com/dashboard/project/eneileezxeuxjbycwwpe/settings/api-keys?new=secret), you will want to grab your direct database URI:
- On the left sidebar of your Supabase dashboard, click on Database (or navigate to Project Settings -> Database).
- Scroll down to the Connection string section.
- Select the URI tab and copy the connection string. It will look like this:
postgresql://postgres.[your-project-id]:[your-password]@aws-0-us-east-1.pooler.supabase.com:6543/postgres
💡 Tip: Use port 6543 (connection pooling via Supavisor) rather than the default 5432. Since NestJS apps open persistent connections, using the pooler prevents your serverless database from running out of available connection slots.
2. Update Your Environment Variables
Never commit raw database strings to Git. Add the copied URI directly to your local backend environment configuration:
Open packages/backend/.env and update or add the DATABASE_URL:
DATABASE_URL="postgresql://postgres.[your-project-id]:[your-password]@aws-0-us-east-1.pooler.supabase.com:6543/postgres"
NODE_ENV="development"
3. Implement Dynamic SSL Handling in TypeORM
Cloud databases like Supabase require encrypted handshakes. To ensure you can toggle between your local machine's Postgres and the cloud database without your code crashing, update your database initialization logic to evaluate connections dynamically.
Update your packages/backend/src/database/data-source.ts file:
import { DataSource } from 'typeorm';
import * as dotenv from 'dotenv';
import * as path from 'path';
dotenv.config({ path: path.join(__dirname, '../../.env') });
const isProduction = process.env.NODE_ENV === 'production';
const dbUrl = process.env.DATABASE_URL;
// Automatically detect if the target database is hosted in the cloud
const hasRemoteConnection = dbUrl && !dbUrl.includes('localhost') && !dbUrl.includes('127.0.0.1');
const shouldEnableSSL = isProduction || hasRemoteConnection;
export const AppDataSource = new DataSource({
type: 'postgres',
url: dbUrl || 'postgres://fa_user:fa_pass@localhost:5432/family_accountant',
// Keep synchronization off for remote cloud databases to protect production tables
synchronize: !hasRemoteConnection,
logging: !isProduction,
entities: [path.join(__dirname, '../**/*.entity{.ts,.js}')],
migrations: [path.join(__dirname, './migrations/*{.ts,.js}')],
subscribers: [],
ssl: shouldEnableSSL
? {
// Required for serverless pooling environments to bypass local root CA certificate lookups
rejectUnauthorized: false,
}
: false,
});
4. Push Your Schema via TypeORM Migrations
Since your project is configured with synchronize: false when connecting to remote instances, you should use migrations to sync your entities (like CategoryEntity, BudgetEntity, and TransactionEntity) up to your Supabase cloud engine.
Run the following commands in your terminal to build your shared components and run outstanding migrations against your live Supabase instance:
# Build shared types required by the backend
pnpm turbo run build --filter=@family-accountant/shared
# Run TypeORM migrations to push schemas to Supabase
pnpm --filter @family-accountant/backend typeorm migration:run -- -d src/database/data-source.ts
Once executed, you can click on the Table Editor on your [Supabase Dashboard](https://supabase.com/dashboard/project/eneileezxeuxjbycwwpe/) to see your columns, relations, and constraints mapped perfectly to the cloud!
Since you already have a [NestJS backend architecture with TypeORM](https://github.com/aj1126/FamilyAccountant), integrating Supabase is incredibly straightforward. Because Supabase is just PostgreSQL under the hood, you don’t need to rewrite your backend codebase to use a custom Supabase SDK. Instead, you can plug your Supabase connection string directly into your existing TypeORM configuration.
Here is the exact step-by-step workflow to connect your project:
1. Retrieve Your Cloud Connection String
Since you are currently inside your [Supabase Settings Panel](https://supabase.com/dashboard/project/eneileezxeuxjbycwwpe/settings/api-keys?new=secret), you will want to grab your direct database URI:
postgresql://postgres.[your-project-id]:[your-password]@aws-0-us-east-1.pooler.supabase.com:6543/postgres2. Update Your Environment Variables
Never commit raw database strings to Git. Add the copied URI directly to your local backend environment configuration:
Open
packages/backend/.envand update or add theDATABASE_URL:3. Implement Dynamic SSL Handling in TypeORM
Cloud databases like Supabase require encrypted handshakes. To ensure you can toggle between your local machine's Postgres and the cloud database without your code crashing, update your database initialization logic to evaluate connections dynamically.
Update your
packages/backend/src/database/data-source.tsfile:4. Push Your Schema via TypeORM Migrations
Since your project is configured with
synchronize: falsewhen connecting to remote instances, you should use migrations to sync your entities (likeCategoryEntity,BudgetEntity, andTransactionEntity) up to your Supabase cloud engine.Run the following commands in your terminal to build your shared components and run outstanding migrations against your live Supabase instance:
Once executed, you can click on the Table Editor on your [Supabase Dashboard](https://supabase.com/dashboard/project/eneileezxeuxjbycwwpe/) to see your columns, relations, and constraints mapped perfectly to the cloud!