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-orm/migrations

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

Database migrations fundamentals

SQL databases require you to specify a strict schema upfront. When you need to change the shape of entities, you must do it via schema migrations. Drizzle is designed to work with multiple production-grade migration management approaches.

Database-first approach

Database-first is when your database schema is the source of truth. You manage your database schema directly on the database or via database migration tools, then pull your database schema to your codebase application-level entities using drizzle-kit pull.

Codebase-first approach

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

Using migrate() function to apply migrations on application startup

The migrate() function from drizzle-orm/node-postgres/migrator reads SQL files from a migrations directory and applies any unapplied migrations to the database. It is safe to run on every startup because already-applied migrations are skipped. Example: await migrate(db, { migrationsFolder: "./migrations" })

Migrate function for Node.js applications

Import migrate from drizzle-orm/node-postgres/migrator and call it with the database connection and migrations folder: await migrate(db, { migrationsFolder: "./migrations" }); This reads SQL files from the migrations directory and applies unapplied migrations to the database. It is safe to run on every startup.

Give your agent this brain