new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Drizzle ORM · all subjects

drizzle-kit/export

15 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

drizzle-kit export required parameters

The drizzle-kit export command requires two parameters: dialect (database dialect, required) and schema (path to TypeScript schema file(s) or folder(s) with multiple schema files, required). Both can be set via drizzle.config.ts config file or via CLI options.

drizzle-kit export schema file patterns

Schema files can be specified as a single file (schema.ts) or multiple files spread across the project. Drizzle Kit requires paths to be specified as glob patterns via the schema configuration option.

drizzle-kit export CLI-only options

The drizzle-kit export command supports the --sql option to generate SQL representation of Drizzle Schema. By default, Drizzle Kit outputs SQL files.

drizzle-kit export config parameter

The config parameter specifies the configuration file path. It is optional with a default value of drizzle.config.ts.

drizzle-kit export example with SingleStore

Example of drizzle-kit export: Create drizzle.config.ts in the configs folder with dialect set to 'singlestore' and schema pointing to './src/schema.ts'. Define a users table in schema.ts with id, email, and name columns. Run 'npx drizzle-kit export --config=./configs/drizzle.config.ts' to output the SQL representation.

drizzle-kit export example output

Example SQL output from drizzle-kit export: CREATE TABLE "users" ( `id` int auto_increment primary key not null, `email` varchar(255) not null, "name" text );

Migration option 6: Codebase first with drizzle-kit export and Atlas

When you want database schema in your TypeScript codebase and want to output the SQL representation to the console, use drizzle-kit export. This reads your drizzle schema and generates SQL representation of it, which you can then apply to the database via Atlas or other external SQL migration tools.

drizzle-kit export command purpose

The drizzle-kit export command exports the SQL representation of a Drizzle schema and prints the SQL DDL representation to the console. It is designed to cover the codebase first approach of managing Drizzle migrations and allows external tools like Atlas to handle migrations.

drizzle-kit export how it works

The drizzle-kit export command triggers a sequence: (1) It reads through Drizzle schema file(s) and composes a JSON snapshot of the schema, (2) Based on the current JSON snapshot it generates SQL DDL statements, (3) Output SQL DDL statements to console.

drizzle-kit export required options

The drizzle-kit export command requires both dialect and schema path options. These can be set either via the drizzle.config.ts config file or via CLI options.

drizzle-kit export with config file

To use drizzle-kit export with a config file, create a drizzle.config.ts with dialect and schema properties, then run 'npx drizzle-kit export'. Example: defineConfig({ dialect: 'mysql', schema: './src/schema.ts' })

drizzle-kit export with CLI options

To use drizzle-kit export with CLI options directly, run: npx drizzle-kit export --dialect=mysql --schema=./src/schema.ts

drizzle-kit export multiple config files

You can have multiple config files in the project using different names, such as drizzle-dev.config.ts and drizzle-prod.config.ts. Use the --config option to specify which config file to use: npx drizzle-kit export --config=drizzle-dev.config.ts

drizzle-kit export CLI options table

drizzle-kit export supports the following CLI options: dialect (required, database dialect like mysql/postgres/sqlite etc.), schema (required, path to typescript schema file(s) or folder(s)), config (optional, configuration file path, default is drizzle.config.ts), --sql (optional, generating SQL representation of Drizzle Schema, true by default).

drizzle-kit export example with MySQL schema

Example showing drizzle-kit export usage: Create drizzle.config.ts with dialect 'mysql' and schema './src/schema.ts'. Define a schema file with mysqlTable('users', { id: int('id').primaryKey().autoincrement(), email: text('email').notNull(), name: text('name') }). Run 'npx drizzle-kit export --config=./configs/drizzle.config.ts'. Output: CREATE TABLE "users" ( `id` int AUTO_INCREMENT PRIMARY KEY, `email` varchar(255) NOT NULL, "name" text );

Give your agent this brain