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:
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:
You can use the --init flag to mark the pulled schema as an applied migration in your database,
so that all subsequent migrations are diffed against the initial one
npx drizzle-kit pull --init
Including tables and schemas
drizzle-kit pull will by default manage all tables in all schemas.
You can configure list of tables and schemas via tablesFilter and schemaFilter options.
tablesFilter
glob based table names filter, e.g. ["users", "user_info"] or "user*". Default is "*"
schemaFilter
glob based schema names filter, e.g. ["dbo", "drizzle"] or "drizzle*". Default is "*"
Let’s configure drizzle-kit to only operate with all tables in dbo schema.
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 postgresqlmysqlsqlitetursosinglestoremssqlcockroach
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
Configuration file path, default is drizzle.config.ts
introspect-casing
Strategy for JS keys creation in columns, tables, etc. preservecamel