Adding custom constraints to tables
According to the docs, Hasura supports Check Constraints for tables but not other types like unique or exclusion.
I've tried adding an exclusion constraint like this:
ALTER TABLE <table> ADD CONSTRAINT <my_constraint> EXCLUDE (<column_a> WITH =) WHERE (<column_b> = <value>);
It works when I add rows manually but the GraphQL API is not updated properly. The <table>_constraints enum does not include <my_constraint> value, so it cannot be used in insert_table_one(..., on_conflict: { constraint: ... }).
I've checked the existing constraints in information_schema.table_constraints but it does not list <my_constraint>. It is listed, however, in pg_catalog.pg_constraint.
Any known workaround? Thanks!
-- Edit
Something similar happens when adding a custom index:
CREATE UNIQUE INDEX <my_index> ON <table> (<column_a>) WHERE <column_b> = <value>;
With this, it shows <my_index> in <table>_constraint enum for on_conflict, but it returns this error when doing a mutation:
{
"extensions": {
"path": "$.selectionSet.insert_<table>_one.args.object[0]",
"code": "constraint-error"
},
"message": "constraint \"<my_index>\" for table \"<table>\" does not exist"
}
same problem here
Same issue, was there an update in the meantime?