can anyone help me i have a problem with these migrations its always changing the tables that i didn

No description
4 Replies
Mykhailo
Mykhailo11mo ago
Hello, @Starko00! Could you describe your migration workflow? Do you use the drizzle-kit push:pg command?
Starko00
Starko00OP11mo ago
yup bunx drizzle-kit generate:pg && bunx drizzle-kit push:pg this is a combo comand i use to do it every time i managed to fix a few of them and by inspectin the psql thats generated i can see that its always dropping all foreign keys and using then making them again -> this is not that of a problem as i guess it needs to do it if its gonna drop a table that has ground braking changes, but for other things like time stamps and numerics its ludarics, its actualy writing the same code over and over again @solo
Mykhailo
Mykhailo11mo ago
One minute
Mykhailo
Mykhailo11mo ago
@Starko00 you have to change your migration workflow, because drizzle-kit generate:pg and drizzle-kit push:pg commands are used for different approaches. 1. drizzle-kit generate:pg This command generates SQL migration files representing changes needed to be applied to your schemas in database. To apply these migrations you have to use migrate function. For example, if you use pg driver you can import this function like this:
import { migrate } from 'drizzle-orm/node-postgres/migrator';
import { drizzle } from "drizzle-orm/node-postgres";
import { Client } from "pg";

const client = new Client({
connectionString: "postgres://user:password@host:port/db",
});

await client.connect();
const db = drizzle(client);

await migrate(db, { migrationsFolder: resolve(__dirname, '../migrations') });
import { migrate } from 'drizzle-orm/node-postgres/migrator';
import { drizzle } from "drizzle-orm/node-postgres";
import { Client } from "pg";

const client = new Client({
connectionString: "postgres://user:password@host:port/db",
});

await client.connect();
const db = drizzle(client);

await migrate(db, { migrationsFolder: resolve(__dirname, '../migrations') });
https://orm.drizzle.team/docs/migrations - docs 2. drizzle-kit push:pg This command lets you push your schema changes directly to the database without generating any migrations files and does not require their use. 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. https://orm.drizzle.team/kit-docs/overview#prototyping-with-db-push - docs So you shouldn't use them together in your workflow. Try to generate migrations and then apply them using migrate function.
Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Want results from more Discord servers?
Add your server