Supabase
ShipNowKit supports PostgreSQL as its database system. PostgreSQL is one of the world's leading open-source relational databases, renowned for its robust features and exceptional performance.
To simplify PostgreSQL deployment and management, we recommend using Supabase as the database hosting service. Supabase is an open-source Firebase alternative that provides a complete Backend-as-a-Service (BaaS) solution.
Key benefits of hosting PostgreSQL with Supabase:
- Fully open-source with self-hosting options
- Generous free tier (500MB storage)
- Complete PostgreSQL feature support
- Intuitive management interface
- Robust security and performance
In this project, we primarily use Supabase as a PostgreSQL database host.
1. Create Project
Visit the Supabase Dashboard to sign up or log in, then create a new project:
2. Security Settings
After project creation, you can find the API keys in the settings:
Since we're only using Supabase's database features, it's recommended to disable the Data API for enhanced security:
3. Database User Setup
Execute the following commands in the SQL Editor to create and authorize a database user:
-- Create custom user
create user "prisma" with password 'xxxxxxxxx' bypassrls createdb;
-- Extend prisma's privileges to postgres (necessary to view changes in Dashboard)
grant "prisma" to "postgres";
-- Grant necessary schema permissions
grant usage on schema public to prisma;
grant create on schema public to prisma;
grant all on all tables in schema public to prisma;
grant all on all routines in schema public to prisma;
grant all on all sequences in schema public to prisma;
alter default privileges for role postgres in schema public grant all on tables to prisma;
alter default privileges for role postgres in schema public grant all on routines to prisma;
alter default privileges for role postgres in schema public grant all on sequences to prisma;
4. Connection Configuration
Obtain the database connection information:
Connection string format:
postgres://[DB-USER].[PROJECT-REF]:[PRISMA-PASSWORD]@[HOST]:5432/postgres```
Add the connection string to your environment configuration:
Set DATABASE_URL environment variable in Vercel
DATABASE_URL=postgres://[DB-USER].[PROJECT-REF]:[PRISMA-PASSWORD]@[HOST]:5432/postgres
5. Database Migration
- Run
npm run db:use:postgresql
, which will:
- Copy
db/prisma/variants/postgresql.prisma
todb/prisma/schema.prisma
- Execute
prisma generate
to create PostgreSQL-compatible Prisma Client
- Run
npm run db:migrate
to perform database migration
Note: If your database contains existing data, it's recommended to backup before migration as the process may affect existing data structures.