Deployment · By Rivtor · Updated
Deploy Next.js with Drizzle and PostgreSQL migrations
Keep Drizzle database access in Next.js server code, commit the migration history and run reviewed migrations against the selected PostgreSQL database. Build a production artifact, bound connection usage and verify a schema-dependent request after release.
See the Rivtor deployment workflow →
Separate application queries from migration tooling
Drizzle application queries use a database driver; Drizzle Kit manages schema tooling. Choose the driver supported by the actual runtime. A Node.js container using node-postgres has a different boundary from an edge runtime with an HTTP database adapter.
For an illustrative Node server module with drizzle-orm and pg installed:
import 'server-only';
import { Pool } from 'pg';
import { drizzle } from 'drizzle-orm/node-postgres';
const pool = new Pool({ connectionString: process.env.DATABASE_URL, max: 3 });
export const db = drizzle(pool);
Keep this module out of client components. The example omits application schema and deployment-specific connection options; use the project’s selected driver configuration rather than copying a connection string into source.
Commit and review the migration path
Generate migration files during development and inspect their SQL. Include the migration metadata and history required by the pinned Drizzle tooling. On a selected database, a migration command changes schema; test it against disposable data before release.
Do not use a schema-push command as an unreviewed substitute for production migration history. Decide how failed or partially applied changes are detected and how the old and new application versions remain compatible during a release.
Match Next.js build and runtime requirements
Next.js may execute server code during a build when statically rendering routes. Decide which pages require runtime database access and whether build-time credentials are necessary. A secret that should exist only at runtime must not accidentally become a prerequisite for building a static page.
On Rivtor, review Next.js detection and service configuration. Check the emitted output, start command and current runtime support. Keep application connection limits within the total database budget, including overlap during releases.
Verify the schema-dependent journey
After migration and release, create and read a synthetic application record through the intended route. A page render and SELECT 1 check do not establish table compatibility. Restart the application, inspect pool errors under representative concurrency and confirm durable state remains. Use the migration troubleshooting guide when the release stops before serving traffic.