TRIGGERS in Drizzle

Is there a way to define/implement TRIGGERs in Drizzle? An example would be great!
I
ippo231d ago
I guess I have to use db.execute() in my migration.ts file?
A
Angelelz231d 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
I
ippo231d ago
🤔 I will give it a try
A
Angelelz231d ago
That's mi opinion. I don't know if it's the best way It feels like is the best option
B
Blume206d 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
I
ippo206d ago
yep, just insert the SQL in the generated SQL that drizzle is giving you
B
Blume206d 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!
F
focused_morning178d ago
What if you are using planetscale and are letting planetscale handle migrations?
Want results from more Discord servers?
Add your server
More Posts
Migrating from Prisma SchemaI want to migrate away from Prisma, but I can't seem to find a good way to get the schema right: - [HELP]: I'm trying to re-create a CTE-insert in drizzle, having some difficulties```sql with cart_products as ( select * from cart_product where cart_id = ${cartId} ) insert into Add drizzle-kit check as a pre-commit hookIs there a way to add drizzle-kit check as a pre-commit hook with husky that would actually prevent Planetscale swapped the order of Primary Key RelationHey, running into this weird issue when using Drizzle push on a staging branch of Planetscale, tryinPostgres functions in the ORM?Hello everyone, I'm learning typescript and SQL (with drizzle) and I'm trying to make an api endpoinInferModelFromColumns with columns defined with sql``Let's say I have a select list that looks like this ```ts const defaultBookFields = { id: books.Issue with drizzle-zod?Schema ``` export const testinArray = pgTable("testing_array", { id: varchar("id", { length: 14 Optional One-to-One RelationCurrently it's possible to define only a One-to-One relation (https://orm.drizzle.team/docs/rqb#one-Having Issues Pushing Database SchemaHi I am getting this issue whenever I am trying to push the database schema. Any help would be greatmigration failedcode: ```js const migrationClient = postgres("postgresql://jer:admin@localhost:5432/test", { max: 1TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys')I am attempting to run db push, but I am getting this error above^^ does anyone know what might be Nesting sqlite drizzle into a deeper location in my ts app, difficulties with src/ vs dist/Hey! I'm very new to drizzle and trying to set up a very small drizzle instance for a service that rsyntax highlighting not workingI reinstalled the node_modules multiple times and it didnt fix my problem. This isnt suposed to lookPrepare raw sql query (Postgres)Hi, I need to do a recursive query, so I think I need to use the magic sql operator to build it. Is packing migration files with the libraryhey there, I'm trying to use `migrate` inside from a library consumer (i.e I have a `@mycompany/db-lAny way to invoke a SQL function?For ex: lets say I declare a SQL function `CREATE OR REPLACE FUNCTION do_something()` how do i invoHow to include array literals in raw sql?I have an input array used for an order by using the array_position function - rather than passing tMySQL Table SchemasI need to generate the following structure of tables: `1. Sales 2.Sales ....` Currently if I use wany way to automatically cast numeric types on retrieval?I have a numeric field in a video table: ``` export const VideoTable = pgTable('videos', { id: uuiQuery in drizzle doesn't work## Error: ```console DrizzleError: No fields selected for table "usersToGroups" ("users_groups") ``