Overview
Codapult uses Turso (LibSQL) as the default database and supports PostgreSQL via DB_PROVIDER=postgres. Drizzle ORM provides type-safe queries for both providers. No raw SQL is needed for normal application code.
The application uses Drizzle ORM for type-safe queries across both database providers.
Choosing Turso or PostgreSQL
Codapult is intentionally Turso-first, but not Turso-only. Use this table when deciding what to keep for your product:
| Choice | Best for | Trade-offs |
|---|---|---|
| Turso / LibSQL (default) | Fast local setup, simple SaaS apps, edge-friendly reads, small operational footprint | Less familiar to some teams than PostgreSQL; some third-party tools assume Postgres |
Local SQLite file (file:local.db) | Development, demos, tests, trying the template without a cloud account | Not a production deployment model by itself |
PostgreSQL (DB_PROVIDER=postgres) | Teams that expect Postgres, enterprise buyers, broad hosting/tooling ecosystem, Postgres-specific features | Heavier local setup; keep schema-pg.ts aligned when changing tables |
If you are unsure, start with file:local.db locally and choose Turso or PostgreSQL before production. The application imports db from @/lib/db, so most feature code does not change when switching providers.
After changing a table or column, verify both schema files with npx @codapult/cli db schema-diff. Missing tables or columns are reported as errors; provider-specific type representations are normalized where possible, while incompatible types are reported as warnings. npx @codapult/cli doctor runs the same parity check automatically.
Extending the schema and queries
When adding tables or changing query logic, keep provider schemas aligned and use bounded list queries.
Setup & Commands
Local Development Setup
# Set your database URL in .env.local
TURSO_DATABASE_URL="file:local.db" # local development
# TURSO_DATABASE_URL="libsql://your-db.turso.io" # production
# Create tables in a fresh or disposable local database
pnpm db:push
# Add sample data for development
pnpm db:seed
Schema Management
The Drizzle schemas in src/lib/db/schema.ts and schema-pg.ts define the
database structure. DB_PROVIDER selects Turso/SQLite or PostgreSQL. Use
pnpm db:push to apply the schema to a fresh or disposable database. To use a
project-owned migration history, run
pnpm db:generate, review the generated SQL, and apply it with
pnpm db:migrate. Start a migration-managed database from an empty database;
db:push does not mark migrations as applied. Do not apply an initial
generated migration to a database that already has the schema from db:push.
For an existing database with data to preserve, verify a baseline before
switching to migration tracking.
Command Reference
| Command | Description |
|---|---|
pnpm db:push | Apply schema directly to database |
pnpm db:generate | Generate migration SQL and snapshots |
pnpm db:migrate | Apply pending project migrations |
pnpm db:seed | Seed sample data |
The database scripts load .env.local when present; no manual export is
needed for local commands.
Local Development
For local development, use an SQLite file instead of a remote Turso database:
TURSO_DATABASE_URL="file:local.db"
This creates a local.db file in the project root. No Turso account required.
Multi-Region Replication
Turso supports read replicas in multiple regions for low-latency reads worldwide. Configure replicas through the Turso dashboard or the turso db replicate CLI command.
The Codapult database client supports automatic routing — reads go to the nearest replica, writes go to the primary. To enable replication management from the admin panel, set:
TURSO_API_TOKEN="your-platform-api-token"
TURSO_ORG_SLUG="your-org-slug"
PostgreSQL Support
Codapult also supports PostgreSQL via the DB_PROVIDER env var:
DB_PROVIDER="postgres"
DATABASE_URL="postgresql://user:password@host:5432/dbname?sslmode=require"
When using Postgres, the provider-specific adapter keeps the same typed query surface, so feature logic does not need to change when switching providers.
Supabase, Neon, RDS, Railway, and other managed PostgreSQL hosts work through the same DATABASE_URL path. Codapult does not ship Prisma as a second ORM because that would duplicate schema definitions, migrations, adapters, and plugin table contracts; if your team prefers Prisma, treat it as a deliberate project-level migration rather than a runtime provider switch.
Troubleshooting
| Issue | Solution |
|---|---|
SQLITE_BUSY errors | Use file:local.db?mode=wal to enable WAL mode for concurrent reads |
db:push hangs | Check that TURSO_DATABASE_URL is reachable; for cloud Turso, verify the auth token |
Next Steps
- Authentication — user accounts and sessions stored in the database
- Teams & Organizations — multi-tenant data model
- Modules — each module's tables can be removed independently