drizzle-kit pull table, schema, and extension filters
The `drizzle-kit pull` command has filter options to control which tables and schemas are introspected. `tablesFilter` uses glob-based patterns for table names (default '*'), `schemaFilter` uses glob-based patterns for schema names (default '*'). Example filters: ['users', 'user_info'] or 'user*' for tables, ['public', 'drizzle'] or 'drizzle*' for schemas.
drizzle-kit pull with tablesFilter
You can filter which tables to introspect using the tablesFilter option with glob patterns. Example: `npx drizzle-kit pull --dialect=cockroach --tablesFilter='user*' url=postgresql://user:password@host:port/dbname` will only pull tables matching the 'user*' pattern.
drizzle-kit pull with different drivers
You can specify different database drivers with the --driver flag. Example: `npx drizzle-kit pull --dialect=cockroach --driver=pglite url=database/` for PGLite driver.
drizzle-kit pull with config file
Run `npx drizzle-kit pull` after defining dialect and dbCredentials in drizzle.config.ts. Example: defineConfig({ dialect: 'cockroach', dbCredentials: { url: 'postgresql://user:password@host:port/dbname' } })
drizzle-kit pull with CLI options
Run `npx drizzle-kit pull --dialect=cockroach --url=postgresql://user:password@host:port/dbname` to pull schema directly via command line without a config file.
Introspect PostgreSQL database with Drizzle
After setting up the Drizzle config file with postgresql dialect and DATABASE_URL environment variable, run the introspection step to generate the schema from your existing PostgreSQL database.
Pull Gel schema to Drizzle
Use 'drizzle-kit pull' command to pull your existing Gel database schema and generate Drizzle schema definitions automatically.
Pull Gel schema to Drizzle
Run drizzle-kit pull to pull your Gel database schema and generate Drizzle schema files from the Gel database.
Drizzle-kit pull command introspects database
Running 'npx drizzle-kit pull' introspects a database and generates a schema.ts file containing table definitions, a meta folder with snapshots of the database schema, a SQL file with migrations, and a relations.ts file for relational queries.
Database introspection for Turso with SQLite dialect
When connecting to an existing Turso database, use drizzle-kit to introspect the database schema to automatically generate table schemas matching the existing structure.
Pull Gel auth schema with drizzle-kit
Run drizzle-kit pull to generate TypeScript schema definitions from the Gel database. This will pull all auth tables from ext::auth namespace, not just the Identity table. The generated schema file will contain table definitions for Identity and User with proper types, indexes, and foreign keys.
drizzle-kit pull tablesFilter option
The tablesFilter option uses glob-based patterns to filter which tables to manage. Examples include ["users", "user_info"] for specific tables or "user*" for pattern matching. Default is "*" which includes all tables.
drizzle-kit pull schemaFilter option
The schemaFilter option uses glob-based patterns to filter which schemas to manage. Examples include ["dbo", "drizzle"] for specific schemas or "drizzle*" for pattern matching. Default is "*" which includes all schemas.
Database first approach with drizzle-kit pull
In the database first approach, the database schema is the source of truth. Use drizzle-kit pull to extract the current database schema and generate a TypeScript Drizzle schema file from it. This approach suits teams managing schema directly on the database or via external migration tools.
Example: Database first with drizzle-kit pull output
When using drizzle-kit pull, the generated TypeScript schema uses mssqlTable, int().identity(), varchar with length, primaryKey, and unique constraints. Example: import * as p from "drizzle-orm/mssql-core"; export const users = p.mssqlTable("users", { id: p.int().identity({ seed: 1, increment: 1 }), name: p.varchar({ length: 255 }), email: p.varchar({ length: 255 }), }, (table) => [ p.primaryKey({ columns: [table.id], name: "PK__users__3213E83FFAA14405"}), p.unique("UQ__users__AB6E6164E0557A2A").on(table.email) ]);
drizzle-kit pull tablesFilter example
Example: set tablesFilter to ['*'] in drizzle.config.ts to introspect all tables in the connected SingleStore database, then run 'npx drizzle-kit pull'.
drizzle-kit pull with config file
Example configuration: create a drizzle.config.ts file with dialect set to 'singlestore' and dbCredentials containing the database url in the format 'mysql://user:password@host:3306/dbname'. Then run 'npx drizzle-kit pull'.
drizzle-kit pull with CLI options
Run 'npx drizzle-kit pull --dialect=singlestore --url=mysql://user:password@host:3306/dbname' to specify configuration directly via command line instead of using a config file.
drizzle-kit pull automatic driver detection
Drizzle Kit does not come with a pre-bundled database driver. It automatically picks an available SingleStore driver from the current project based on the dialect specification. SingleStore uses MySQL-compatible connection parameters, so typically only dbCredentials need to be provided.
drizzle-kit pull tablesFilter configuration
The tablesFilter option allows you to specify which tables to introspect. It accepts glob-based table name filters such as ['users', 'user_info'] or 'user*'. The default value is '*', which introspects all tables.
drizzle-kit pull CLI examples
Examples of drizzle-kit pull with CLI options: 'npx drizzle-kit pull --dialect=singlestore --url=mysql://user:password@host:3306/dbname' or 'npx drizzle-kit pull --dialect=singlestore --tablesFilter='user*' url=mysql://user:password@host:3306/dbname'.
drizzle-kit pull command
drizzle-kit pull lets you pull (introspect) database schema, convert it to Drizzle schema and save it to your codebase.
Migration option 1: Database first with drizzle-kit pull
When you manage database schema yourself using external migration tools or by running SQL migrations directly, use drizzle-kit pull to get the current state of the schema from your database and save it as a TypeScript schema file. Your database schema is the source of truth.
drizzle-kit pull generates v2 relations syntax
In v2, drizzle-kit pull can generate relations.ts files in the new v2 syntax. The generated file should be transferred to the location where you specify relations, and imports may need updating if schema tables are in multiple files.
drizzle-kit pull relations feature
In drizzle-kit 0.21.0, relations are now pulled from the database by extracting foreign key information and translating it into a relations object. After introspection is complete, a relations.ts file is generated in the out folder.
Introspecting Nile database with drizzle-kit pull
Run `npx drizzle-kit pull` to introspect a Nile database. Nile databases have built-in tables, most importantly the 'tenants' table used to create and manage tenants. The introspection generates a schema.ts file, meta folder with snapshots, SQL file with migration, and relations.ts file for relational queries.
drizzle-kit pull --init flag
The `drizzle-kit pull --init` flag creates a drizzle migration table in the database and marks the first pulled migration as applied, allowing you to continue iterating from there.
introspect config property for drizzle-kit
The introspect property configures the drizzle-kit pull command behavior. Type: { casing: 'preserve' | 'camel' }. Default: { casing: 'camel' }. Commands: pull. The casing property controls the casing of column keys in the generated code: 'camel' converts column names to camelCase keys, while 'preserve' keeps the exact database column names as keys.
introspect casing camel mode behavior
When introspect.casing is set to 'camel', drizzle-kit pull generates schema keys in camelCase, converting database column names like 'first_name' to camelCase keys like 'firstName'. This normalizes naming conventions across the schema.
introspect casing preserve mode behavior
When introspect.casing is set to 'preserve', drizzle-kit pull preserves the exact database column names as keys, maintaining columns like 'first-name', 'LastName', and 'phone_number' exactly as they appear in the database.
drizzle-kit pull configuration options reference
drizzle-kit pull CLI configuration options: dialect (required, database dialect), out (default ./drizzle, migrations output folder path), url (database connection string), user (database user), password (database password), host (host), port (port), database (database name), config (default drizzle.config.ts, configuration file path), introspect-casing (strategy for JS keys creation in columns and tables, options: preserve or camel), tablesFilter (table name filter).
drizzle-kit pull with config file example
To use drizzle-kit pull with a config file, create drizzle.config.ts with dialect set to mysql and dbCredentials containing the url, then run npx drizzle-kit pull.
drizzle-kit pull CLI example with tablesFilter
Example of drizzle-kit pull with CLI options including tablesFilter: npx drizzle-kit pull --dialect=mysql --tablesFilter='user*' --url=mysql://user:password@host:3306/dbname
drizzle-kit pull with CLI options example
To use drizzle-kit pull via CLI options, run: npx drizzle-kit pull --dialect=mysql --url=mysql://user:password@host:3306/dbname
Multiple configuration files in one project
You can have multiple config files in a single project by specifying the config file path with the --config flag. For example: npx drizzle-kit pull --config=drizzle-dev.config.ts or npx drizzle-kit pull --config=drizzle-prod.config.ts. This is useful for managing multiple database stages or multiple databases.
drizzle-kit pull --init flag
The --init flag marks the pulled schema as an applied migration in the database, so that all subsequent migrations are diffed against the initial one. Run with: npx drizzle-kit pull --init
drizzle-kit pull purpose and database-first approach
drizzle-kit pull introspects an existing database schema and generates a schema.ts Drizzle schema file. It is designed to cover the database-first approach of Drizzle migrations, useful when managing database schema outside a TypeScript project or when the database is managed by someone else.
drizzle-kit pull workflow steps
When you run drizzle-kit pull, it performs two steps: first, it pulls the database schema (DDL) from the existing database; second, it generates a schema.ts Drizzle schema file and saves it to the out folder.
drizzle-kit pull required configuration parameters
drizzle-kit pull requires you to specify dialect and either a database connection url or user:password@host:port/db params. These can be provided via drizzle.config.ts config file or via CLI options.
drizzle-kit pull table filtering with tablesFilter
By default, drizzle-kit pull introspects all MySQL tables. You can configure the list of tables via tablesFilter, which accepts glob-based table names filter, for example ["users", "user_info"] or "user*". The default is "*" which includes all tables.