Migration fails to create permission if permission already exists
Author: godotgelertCreated Jul 31, 2020Updated Sep 22, 2026
Labelsk/question
Scenario:
- Developer A adds a SELECT permission for a role as part of a larger update of many migrations being squashed
- In the meantime, Developer B adds a SELECT permission for the same role and pushes the migration to the repo
- Developer A merges Developer B's migration and runs "hasura migrate apply"
- Developer A's migration fails to apply even though the exact same permission is supplied
- Developer A now cannot apply the previous migration, and has to manually remove the new permission from the squashed migration due to be pushed and remove things manually from the database until the migration completes
Example output:
FATA[0001] apply failed: [unexpected] database query error ($.args[4].args)
File: '1595512518782_permissions/up.yaml'
{
"permission": {
"allow_aggregations": false,
"backend_only": false,
"columns": [
"name",
"phone",
"id",
"org_id",
"country_code",
"type"
],
"computed_fields": [],
"filter": {
{
"id": {
"_eq": "X-Hasura-User-Id"
}
},
},
"limit": null
},
"role": "developers",
"table": {
"name": "organisation_contacts",
"schema": "public"
}
}
[23505] FatalError: duplicate key value violates unique constraint "hdb_permission_pkey"
Description: Key (table_schema, table_name, role_name, perm_type)=(public, organisation_contacts, developers, select) already exists. Expected Behaviour:
The system should be able to read the permissions that already exist, generate a diff and apply the diff, or drop and create the new permission set depending on CLI arguments
Source: hasura/graphql-engine