This section covers everything you need to set up and configure PostgreSQL with pgvector for local development and .
We use Drizzle ORM for database access for several important reasons:
pgvector, which is crucial for applications that need vector similarity search and AI/ML featuresThese features make Drizzle the ideal choice for our use case, providing both type safety and the flexibility needed for complex database operations.
Drizzle uses migrations to manage database schema changes. Migrations are managed in the packages/db package and automatically applied during Vercel builds.
After making changes to your schema files in packages/db/src/schema/, generate migration files:
cd packages/db
npm run db:generate
# or
set -a && source ../../../.env.local && npm run db:generate
This command:
packages/db/drizzle/Important: Migration SQL files are committed to git so they can be applied during production deployments.
For local development, apply migrations manually:
cd packages/db
npm run db:migrate:deploy
# or
set -a && source ../../../.env.local && npm run db:migrate:deploy
This will:
drizzle.__drizzle_migrations tableMigrations are automatically applied during the build process on Vercel. The build script in apps/zooly-app runs migrations before building the Next.js app:
# This happens automatically during `npm run build` in zooly-app
node ../../packages/db/dist/migrate.js && next build
No manual migration step is needed for production deployments - just commit your migration files and push to trigger a new build.
For rapid development, you can push schema changes directly without generating migration files:
cd packages/db
npm run db:push
Important: db:push should only be used in development. In production, always use db:generate followed by committing the migration files. Migrations will be automatically applied during the Vercel build process.
Critical: Never develop against the remote server database. Running db:generate or db:migrate against a remote production or shared database can break it for other developers or users.
Always use a local database instance for development. See the installation guides below for instructions on setting up a local database.
If you're new to PostgreSQL setup, start with installation for your platform and follow the guides in order.
Choose the installation method for your platform: