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
import * as p from "drizzle-orm/singlestore-core";export const users = p.singlestoreTable("users", { id: p.int().primaryKey().autoincrement(), name: p.varchar({ length: 255 }), email: p.varchar({ length: 255 }).unique(),};
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:
Drizzle Kit does not come with a pre-bundled database driver,
it will automatically pick an available SingleStore driver from your current project based on dialect: "singlestore" - see discussion.
SingleStore uses MySQL-compatible connection parameters, so you usually only need to provide dbCredentials.
Initial pull
WARNING
This feature is available on 1.0.0-beta.2 and higher.
npm
yarn
pnpm
bun
npm i drizzle-orm@rcnpm i drizzle-kit@rc -D
yarn add drizzle-orm@rcyarn add drizzle-kit@rc -D
pnpm add drizzle-orm@rcpnpm add drizzle-kit@rc -D
bun add drizzle-orm@rcbun add drizzle-kit@rc -D
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 push --init
Including tables
drizzle-kit pull will introspect all SingleStore tables by default.
You can configure the list of tables via tablesFilter.
tablesFilter
glob based table names filter, e.g. ["users", "user_info"] or "user*". Default is "*"
Letβs configure drizzle-kit to introspect all tables in the connected SingleStore database.
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