DT
Drizzle Team•14mo ago
ippo

TRIGGERS in Drizzle

Is there a way to define/implement TRIGGERs in Drizzle? An example would be great!
8 Replies
ippo
ippoOP•14mo ago
I guess I have to use db.execute() in my migration.ts file?
Angelelz
Angelelz•14mo ago
Nope you can use the migrate function provided by Drizzle This would be the process: 1.- Make changes to your schema.ts file 2.- Run the generate command to generate the migration file in SQL 3.- Edit the *.sql file that was generated and add the trigger that you need. 4.- Run the migration as you normally would do it, maybe with the helper migrate function provided by drizzle 5.- profit
ippo
ippoOP•14mo ago
🤔 I will give it a try
Angelelz
Angelelz•14mo ago
That's mi opinion. I don't know if it's the best way It feels like is the best option
Blume
Blume•14mo ago
Have you been able to do it? I have no Idea how I would do this in the schema file... And how would drizzle-kit know how to write the migration when using plain SQL? A drizzle-native way to add triggers would be really cool
ippo
ippoOP•14mo ago
yep, just insert the SQL in the generated SQL that drizzle is giving you
Blume
Blume•14mo ago
Hmm I see, I'm not yet using migration files (Early project) but maybe I can use a custom migration file for stuff like that Thanks!
focused_morning
focused_morning•13mo ago
What if you are using planetscale and are letting planetscale handle migrations?
Want results from more Discord servers?
Add your server