Adopt an existing database
An existing database is the source of truth and the application needs a typed Drizzle schema.
Drizzle ORM · Command
drizzle-kit pull introspects an existing database and generates a Drizzle schema.ts file in the configured output directory. It supports database-first migrations and can mark the result as the initial migration with --init.
Run this command to introspect an existing database, generate a Drizzle schema file, and place the generated output in the configured directory. Use --init when the pulled schema should become the baseline for later migration diffs.
npx drizzle-kit pull [options]| Name | Type | Description |
|---|---|---|
dialect | required option | Database dialect, such as postgresql, mysql, sqlite, turso, singlestore, mssql, or cockroach. |
url | connection option | Database connection string; alternatively provide user, password, host, port, and database. |
out | option | Directory for generated output; defaults to ./drizzle. |
--init | flag | Marks the pulled schema as an applied initial migration. |
tablesFilter | option | Filters the tables included during introspection. |
A generated schema.ts file and migration-related output in the configured out directory; with --init, the pulled schema is recorded as the applied baseline.
npx drizzle-kit pull --dialect=postgresql --url=postgresql://user:password@host:port/dbname
npx drizzle-kit pull --initIntrospects the PostgreSQL database and then marks the pulled schema as the initial applied migration.
An existing database is the source of truth and the application needs a typed Drizzle schema.
A team wants future migration diffs to start from the current production schema.
A CI/CD job needs to run introspection with an explicit database configuration.
It introspects the existing database schema and generates a schema.ts Drizzle schema file. The generated file is saved in the configured out directory.
Follow-up: How do you establish that introspected structure as the migration baseline? Use the --init flag, which marks the pulled schema as an applied migration.
The command requires a dialect plus either a database URL or separate connection parameters. These values can be configured in drizzle.config.ts or passed as CLI options.
Follow-up: What is a practical reason to pass configuration through CLI options? Separate configuration files or CLI arguments can be useful in CI/CD workflows.
By default, pull introspects the database schema and writes the generated Drizzle output to the out directory, whose default is ./drizzle. The output directory can be configured.
Follow-up: How can the set of introspected tables be restricted? Configure tablesFilter in the Drizzle Kit configuration.
drizzle-kit generatedrizzle-kit migratedrizzle-kit pushdrizzle.config.tstablesFilter