Deployment: Vercel & Supabase
Relevant source files
The following files were used as context for generating this wiki page:
Deployment of the Kuest prediction market platform is designed for rapid setup, leveraging Vercel for frontend hosting and Supabase for backend database and scheduling services. This architecture allows operators to launch a white-label market with shared liquidity in approximately 15 minutes by connecting a GitHub repository to Vercel and providing the necessary Supabase environment variables.
The deployment process integrates database migrations, RLS (Row Level Security) policies, and automated cron jobs directly into the build pipeline. This ensures that the infrastructure is synchronized with the application code upon every push to the main branch.
Sources: README.md:68-75, vercel.json:1-12
Vercel Integration
Vercel serves as the primary deployment target for the Next.js application. The configuration focuses on automating the build process and managing deployment triggers.
Build and Deployment Configuration
The build process is automated via vercel.json, which executes a two-step command: pushing database migrations followed by the standard Next.js build.
{
"buildCommand": "pnpm db:push && next build",
"git": {
"deploymentEnabled": {
"main": true,
"*": false
}
}
}
Sources: vercel.json:3-10, package.json:20
Environment Variables
The application requires specific environment variables to function correctly on Vercel, particularly for database connectivity and storage.
| Variable | Description |
|---|---|
POSTGRES_URL | Primary connection string for the PostgreSQL database. |
POSTGRES_URL_NON_POOLING | Direct connection string used for migrations to avoid pgbouncer issues. |
SUPABASE_URL | The API URL for the Supabase project. |
SUPABASE_SERVICE_ROLE_KEY | High-privilege key for administrative database operations. |
CRON_SECRET | Secret used to authorize internal API calls from the Supabase scheduler. |
Sources: scripts/migrate.ts:413-418, infra/terraform/modules/target-digital-ocean/variables.tf:98-111
Supabase Backend & Database
Supabase provides the PostgreSQL database and an automated scheduling system. The project uses a custom migration script to prepare the database environment.
Database Migrations
Migrations are managed through a Node.js script (scripts/migrate.ts). This script performs several critical tasks:
- Advisory Locking: Prevents concurrent migration runs using
pg_advisory_lock(Namespace: 20817, Key: 1). - RLS Policy Setup: Creates a
migrationstracking table and enables Row Level Security, granting access to theservice_role. - Compatibility Rewrites: In Supabase mode, the script ensures SQL statements targeting roles use
service_roleinstead of the default user.
Sources: scripts/migrate.ts:3-10, scripts/migrate.ts:161-224
Automated Scheduling (pg_cron & pg_net)
When SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY are detected, the system attempts to configure the Supabase scheduler using the pg_cron and pg_net extensions.
The diagram shows the logic flow for registering automated tasks within Supabase during the deployment build.
Sources: scripts/migrate.ts:384-411
Scheduled Tasks
The following table details the cron jobs registered in Supabase:
| Job Name | Schedule | Endpoint Path |
|---|---|---|
sync-events | 2,11,20,... * * * * | /api/sync/events |
sync-volume | */5 * * * * | /api/sync/volume |
sync-resolution | 5-55/10 * * * * | /api/sync/resolution |
clean-jobs | 15 * * * * | Internal SQL |
Sources: scripts/migrate.ts:286-372
Storage Configuration
The system supports a dual storage strategy, prioritizing Supabase Storage when configured, but falling back to S3-compatible storage if necessary.
Asset URL Resolution
The application dynamically builds public asset URLs based on the detected environment variables. If Supabase is active, it uses the /storage/v1/object/public/kuest-assets/ path.
Deployment Summary
The deployment architecture combines Vercel's edge hosting with Supabase's managed Postgres features to create a serverless-style prediction market infrastructure. By executing pnpm db:push during the Vercel build phase, the platform ensures that database schemas, RLS policies, and background synchronization jobs are always in sync with the application code. This automation is critical for supporting shared liquidity and real-time market updates across decentralized frontends.
Sources: vercel.json:3, README.md:43-48, scripts/migrate.ts:420-440