drizzle-kit pull lets you literally pull(introspect) your existing database schema and generate schema.ts drizzle schema file,
it is designed to cover database first approach of Drizzle migrations.
How it works under the hood?
When you run Drizzle Kit pull command it will:
Pull database schema(DDL) from your existing database
Generate schema.ts drizzle schema file and save it to out folder
It is a great approach if you need to manage database schema outside of your TypeScript project or
youβre using database, which is managed by somebody else.
drizzle-kit pull requires you to specify dialect and either
database connection url or user:password@host:port/db params, you can provide them
either via drizzle.config.ts config file or via CLI options:
With config file
With CLI options
Multiple configuration files in one project
You can have multiple config files in the project, itβs very useful when you have multiple database stages or multiple databases or different databases on the same project:
npm
yarn
pnpm
bun
Specifying database driver
IMPORTANT
Expo SQLite and OP SQLite are on-device(per-user) databases, thereβs no way to pull database schema from there.
For embedded databases Drizzle provides embedded migrations - check out our get started guide.
Drizzle Kit does not come with a pre-bundled database driver,
it will automatically pick available database driver from your current project based on the dialect - see discussion.
Mostly all drivers of the same dialect share the same set of connection params,
as for exceptions like aws-data-api, pglight and d1-http - you will have to explicitely specify driver param.
AWS Data API
PGLite
Cloudflare D1 HTTP
Including tables, schemas and extensions
drizzle-kit push will by default manage all tables in public schema.
You can configure list of tables, schemas and extensions via tablesFilters, schemaFilter and extensionFilters options.
tablesFilter
glob based table names filter, e.g. ["users", "user_info"] or "user*". Default is "*"
schemaFilter
Schema names filter, e.g. ["public", "drizzle"]. Default is ["public"]
extensionsFilters
List of installed database extensions, e.g. ["postgis"]. Default is []
Letβs configure drizzle-kit to only operate with all tables in public schema
and let drizzle-kit know that thereβs a postgis extension installed,
which creates itβs own tables in public schema, so drizzle can ignore them.
Extended list of configurations
We recommend configuring drizzle-kit through drizzle.config.ts file,
yet you can provide all configuration options through CLI if necessary, e.g. in CI/CD pipelines, etc.
dialect
required
Database dialect, one of postgresqlmysqlsqliteturso
driver
Drivers exceptions aws-data-apid1-httppglight
out
Migrations output folder path, default is ./drizzle
url
Database connection string
user
Database user
password
Database password
host
Host
port
Port
database
Database name
config
Config file path, default is drizzle.config.ts
introspect-casing
Strategy for JS keys creation in columns, tables, etc. preservecamel