Schema and migrations
Configure Drizzle Kit
Point Drizzle Kit at the schema, migration directory, SQLite dialect, and database without leaking credentials into version control.
8 minute lesson
Drizzle ORM runs application queries. Drizzle Kit compares schemas and manages migration files. They solve different jobs.
Create drizzle.config.ts at the project root. Load the same environment value as the application, then declare the schema path, output folder, dialect, and database URL. Commit the config but not the local database or secrets.
import 'dotenv/config'
import { defineConfig } from 'drizzle-kit'
export default defineConfig({
schema: './src/db/schema.ts',
out: './drizzle',
dialect: 'sqlite',
dbCredentials: {
url: process.env.DB_FILE_NAME!,
},
})
The non-null assertion keeps the example small, but configuration should still fail clearly when the variable is absent. You can validate before exporting the config when several environments share the project.
For PostgreSQL the dialect and credentials change. The application schema also uses pgTable and PostgreSQL column builders. Drizzle makes the workflow familiar, not identical across databases.
Run a Drizzle Kit command with the correct environment, then rename the schema path and database variable one at a time. Save both failures so you can distinguish a missing schema from a missing connection.
Lesson completed