0

I'm trying to add some custom logic to one of my tables on Hasura Postgre.

id : PK user_id : FK tag_id : FK is_active : bool
1 abc xyz true
2 abc xyz false
3 abc xyz false

Allow only one row with same pair of FK's but column is_active == true;

Allow multiple rows with same pair of FK's but column is_active == false;

...

How can I set Hasura up to in case of an insert or update, Hasura would update the old value with is_active = false and keep only the new one with is_active = true automatically.

Thanks!!!

Marcus Rohden
  • 113
  • 1
  • 10
  • 1
    In the same GraphQL transaction you can change all the old rows `is_active = false` https://hasura.io/docs/latest/mutations/postgres/update/#update-objects-based-on-their-fields then insert a new row with `is_active = true` https://hasura.io/docs/latest/mutations/postgres/multiple-mutations/ – Arjun Yelamanchili Aug 30 '22 at 14:33
  • 1
    There's no way to do this "automatically" through Hasura but you could implement it inside of Postgres with constraints on the table + database triggers – Jesse Carter Aug 31 '22 at 15:36

1 Answers1

0

thanks for the comments. ended up solving with an event trigger to my backend and managing everything from there.

Marcus Rohden
  • 113
  • 1
  • 10