When to use what? drizzle-kit push:* Vs. having a file with drizzle migrate client?

Option 1: package.json script drizzle-kit push:pg Option 2: migrate.ts script
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';

const migrationClient = postgres("postgres://postgres:[email protected]:5432/db", { max: 1 });
migrate(drizzle(migrationClient), ...)
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';

const migrationClient = postgres("postgres://postgres:[email protected]:5432/db", { max: 1 });
migrate(drizzle(migrationClient), ...)
3 Replies
Mykhailo
Mykhailo9mo ago
Hello, @Acro! drizzle-kit generate and drizzle-kit push are different approaches for migration process. drizzle-kit generate generate migrations (sql files) and use them to track history of changes, then you should use migrate() function (available for each driver) to run migrations. drizzle-kit push applies changes directly to the database without generating any files. It introspects schema in database and compare it with your actual schema in application. So, drizzle-kit push is designed for rapid prototyping and experimentation. It is good for situations where you need to quickly test new schema designs or changes in a local development environment, allowing for fast iterations without the overhead of managing migration files. drizzle-kit generage is designed for managing schema changes in your project. It is good for situations where you need to manage schema changes in your project and apply them to other environments like production
adrtivv
adrtivv2mo ago
any difference between drizzle kit migrate command and migrate() function if both are executed against the same migration files?
Mykhailo
Mykhailo2mo ago
hey @adrtivv! no, there is no difference between them drizzle-kit migrate use migrate function under the hood
Want results from more Discord servers?
Add your server