How to create event triggers before running migrations #10731
-
Hello 👋 We've encountered an issue where Hasura creates event triggers after executing migrations. As a result, any data inserted during the migration process does not trigger the associated events. We were wondering if there would be a way for Hasura to create those triggers before it runs the migrations? We would appreciate any help or insight 🙇 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey there, @Petucci 👋 Good question! By design, Hasura creates Event Triggers after running migrations because the migration process can alter tables, which impacts trigger definitions. This means any data inserted during the migration process won't trigger events because the triggers aren't set up yet. The cleanest solution here is to create the triggers manually using SQL before running the migration. This ensures that the triggers are in place before any data is inserted. You should be able to do this by adding a custom SQL migration that directly creates the triggers using If you make sure this custom migration runs before any data insertion takes place, then this approach should give you full control and ensure your events are always triggered as expected. |
Beta Was this translation helpful? Give feedback.
Hey there, @Petucci 👋
Good question! By design, Hasura creates Event Triggers after running migrations because the migration process can alter tables, which impacts trigger definitions. This means any data inserted during the migration process won't trigger events because the triggers aren't set up yet.
The cleanest solution here is to create the triggers manually using SQL before running the migration. This ensures that the triggers are in place before any data is inserted.
You should be able to do this by adding a custom SQL migration that directly creates the triggers using
CREATE TRIGGER
in SQL.If you make sure this custom migration runs before any data insertion takes place, then th…