TRIGGERS in Drizzle
Is there a way to define/implement TRIGGERs in Drizzle?
An example would be great!
8 Replies
I guess I have to use
db.execute()
in my migration.ts file?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🤔
I will give it a try
That's mi opinion. I don't know if it's the best way
It feels like is the best option
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
yep, just insert the SQL in the generated SQL that drizzle is giving you
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!
What if you are using planetscale and are letting planetscale handle migrations?