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

migrations

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 check basic usage with CLI option

To run drizzle-kit check via CLI without a config file, use the command 'npx drizzle-kit check --dialect=cockroach'.

drizzle-kit check example with custom migrations folder

To run drizzle-kit check with a custom migrations folder, use: 'drizzle-kit check --dialect=cockroach --out=./migrations-folder'.

drizzle-kit export complete example

Example: Create drizzle.config.ts with dialect: 'cockroach' and schema: './src/schema.ts'. Create schema.ts with a users table definition. Run npx drizzle-kit export --config=./configs/drizzle.config.ts. This outputs: CREATE TABLE "users" ("id" int4 PRIMARY KEY, "email" string NOT NULL, "name" string);

drizzle-kit export schema files glob support

The schema configuration option accepts glob patterns to specify paths to schema files. A project can have a single schema.ts file or multiple schema files spread across the project, and the glob pattern will match all of them.

drizzle-kit export basic usage with CLI options

To use drizzle-kit export with CLI options instead of a config file, run: npx drizzle-kit export --dialect=cockroach --schema=./src/schema.ts

drizzle-kit export with custom config file path

To run drizzle-kit export with a custom configuration file location, use the --config flag: npx drizzle-kit export --config=./configs/drizzle.config.ts

Schema snapshot JSON file

The `drizzle-kit generate` command creates a `snapshot.json` file alongside each `migration.sql` file. This snapshot contains a JSON representation of the schema at that point in time, which is used for comparing with future schema versions to detect changes.

ignore-conflicts flag usage

The `--ignore-conflicts` flag allows the `generate` command to skip commutativity checks and bypass validation. Use `drizzle-kit generate --ignore-conflicts`. This should only be used in edge cases where drizzle-kit is not checking migrations correctly, and such cases should be reported as bugs.

drizzle-kit generate config file example

Example drizzle.config.ts for `drizzle-kit generate`: ```typescript import { defineConfig } from "drizzle-kit"; export default defineConfig({ dialect: "cockroach", schema: "./src/schema.ts", }); ``` Then run: `npx drizzle-kit generate`

drizzle-kit generate CLI options example

Example using `drizzle-kit generate` with CLI options: `npx drizzle-kit generate --dialect=cockroach --schema=./src/schema.ts`

Custom migration example with extended config

Example of creating a custom cockroach migration file named `0001_seed-users.sql` with drizzle.config.ts in a `configs` folder: ```typescript import { defineConfig } from "drizzle-kit"; export default defineConfig({ dialect: "cockroach", schema: "./src/schema.ts", out: "./migrations", }); ``` Run: `npx drizzle-kit generate --config=./configs/drizzle.config.ts --name=seed-users --custom` This generates a migration in the `./migrations` folder.

Migration folders output structure

Generated migrations are stored in folders organized by timestamp. For example, a migration generated at 2024-24-09 12:55:10 creates the folder structure: `📂 20242409125510_migration_name` containing `migration.sql` and `snapshot.json` files.

Database first vs codebase first migration approaches

Database first is when your database schema is a source of truth. You manage your database schema either directly on the database or via database migration tools and then pull your database schema to your codebase application level entities. Codebase first is when database schema in your codebase is a source of truth and is under version control. You declare and manage your database schema in JavaScript/TypeScript and then apply that schema to the database itself either with Drizzle, directly or via external migration tools.

PostgreSQL schema updates and migrations

After updating your table schema in Drizzle, you can apply changes to the database using migrations and then query the database with the new fields.

Drizzle automatic migration generation

Drizzle can automatically generate migrations in SQL format from TypeScript schema definitions. Migrations include table creation statements and constraint definitions like foreign keys.

Give your agent this brain