Using Postgres with Supersaas

Although I love using NuxtHub, I understand its not for everyone, you might want to use your own database and file storage and host supersaas yourself.
This guide will help do just that
Prerequisites
- A Supersaas instance
- A Postgres database URL
- A S3 compatible file storage provider
Step 1: Checkout the postgres branch
Everything is already setup for you in the postgres
branch, just switch to it.
git checkout postgres
Step 2: Create a Postgres database
Create a Postgres database and get the connection string and paste in in the .env
file
POSTGRES_URL="postgresql://postgres@127.0.0.1:5432/your-database-name"
Customer have successfully used Supersaas with
- Neon
- Supabase
- Vercel Postgres
Step 3: Create a file storage provider
We now need to set up S3 storage and Supersaas uses Unjs Unstorage as a unified storage layer with the S3 driver for file operations.
The configuration is already handled for you once these environment variables are set.
S3_ACCESS_KEY_ID=XXXXXXXXX
S3_SECRET_ACCESS_KEY=XXXXXXXXXX
S3_BUCKET=your-bucket-name
S3_REGION=your-region
S3_ENDPOINT=your-endpoint
S3_PUBLIC_ENDPOINT=your-public-endpoint
This works with any S3 compatible storage service.
Step 4: Generating Migrations
You need to generate a migration file, when you make changes or add new tables to your database (also the first time you setup the database). Run the following command to generate a migration file:
pnpm db:generate
This will generate the required sql files in the server/database/migrations
directory.
Step 5: Apply migrations
Apply the migrations to your database by running the following command:
These files are not applied automatically, you need to apply them manually.
"db:migrate": "drizzle-kit migrate",
"db:push": "drizzle-kit push",
Think of it like git commits, you need to commit the changes to your database.
That's it, you're all set.