Database
Configure PostgreSQL database for your LaunchSaaS application
Database
LaunchSaaS uses PostgreSQL with Drizzle ORM for type-safe database operations. This guide covers database configuration and setup.
Setup
Create a Database
Recommended to use hosted PostgreSQL database services. They provide easy setup and management, and often include free tiers sufficient for getting started.
Neon (Recommended)
Neon is a serverless PostgreSQL service with an excellent developer experience.
Setup Steps:
- Create an account at neon.tech
- Create a new project
- Create a database
- Get your connection string from the dashboard
- Add the connection string to your
.envfile:
DATABASE_URL="postgres://user:[email protected]/database?sslmode=require"Supabase
Supabase provides PostgreSQL databases with additional features like authentication and storage.
Setup Steps:
- Create an account at supabase.com
- Create a new project
- Click on the
Connectbutton - Get your connection string in
Transaction poolersection - Add the connection string to your
.envfile:
DATABASE_URL="postgres://postgres:[email protected]:6543/postgres"Initialize the Database
After configuring your database URL, initialize the database:
npm run initThis command will:
- Generate the Drizzle migrations
- Apply migrations to your database
- Create the admin user
If you are setting up the environment, now you can go back to the Environment Setup guide and continue.
Other Database Options
Self-Hosted
Docker
Run PostgreSQL in a Docker container for local development:
docker run --name launchsaas-postgres -e POSTGRES_PASSWORD=mypassword -d -p 5432:5432 postgresConnection string:
DATABASE_URL="postgres://postgres:mypassword@localhost:5432/postgres"Local Installation
Install PostgreSQL directly on your machine from postgres.org.
Other Hosted Services
Database Commands
| Command | Description |
|---|---|
npm run db:generate | Generate migrations from schema changes |
npm run db:migrate | Apply migrations to database |
npm run db:generate:auth | Regenerate Better Auth schema (after auth config changes) |
npm run init:db | Generate + migrate (combined) |
Schema Organization
Database schemas are located in src/schemas/tables/:
| File | Description |
|---|---|
auth.ts | Authentication tables (auto-generated by Better Auth) |
payment.ts | Payment and subscription tables |
index.ts | Re-exports all schemas |
Don't manually edit auth.ts - it's auto-generated. Run npm run db:generate:auth after changing auth configuration.
FAQ
Connection Issues
If you're having trouble connecting to your database:
- Check that your
DATABASE_URLis correctly formatted - Ensure your IP is allowed in the database's firewall settings
- Verify that the database user has the correct permissions
- Check for any network restrictions
Migration Issues
If you're experiencing issues with database migrations:
- Check your schema definitions for errors
- Ensure your migration scripts are correctly formatted
- Try running migrations manually to see detailed errors
References
- Neon Documentation
- Supabase Documentation
- Drizzle ORM Documentation
- Drizzle with Neon
- Drizzle with Supabase