Skip to content

Fix teams_name_unique constraint for Hasura on_conflict#33

Merged
acmeguy merged 1 commit intomainfrom
fix/teams-name-unique-constraint
Mar 28, 2026
Merged

Fix teams_name_unique constraint for Hasura on_conflict#33
acmeguy merged 1 commit intomainfrom
fix/teams-name-unique-constraint

Conversation

@acmeguy
Copy link
Copy Markdown

@acmeguy acmeguy commented Mar 28, 2026

Summary

  • Migration 1741520400001: Replaces the expression index lower(trim(name)) on teams with a plain UNIQUE constraint. The expression index (from migration 1709836800001) cannot be used as a Hasura on_conflict target, which broke team auto-provisioning in dataSourceHelpers.js. Application code already normalizes names to lower(trim()) before insert, so a plain constraint is sufficient.
  • docker-compose.dev.yml: Increases hasura_cli migrations server timeout from 30s → 120s to prevent restart loops when applying large migration sets on cold start.

Context

This was discovered as a cluster incident requiring manual DDL fixes. The expression index silently broke the insert_teams_one(..., on_conflict: { constraint: teams_name_unique }) mutation — Hasura requires an actual constraint, not an expression index, for on_conflict targets.

Cluster fixes this prevents from recurring

Fix Addressed
teams DDL (expression index → constraint) ✅ Migration
hasura_cli restart loop ✅ Timeout increase
Pre-aggregation external: true patches ❌ User-defined schemas in DB, not code
Version checksum resets ❌ Operational, by-design cache behavior
Hasura metadata restore after untrack ❌ One-time incident, metadata in repo is correct

Test plan

  • Applied migration locally — verified pg_constraint shows teams_name_unique as type u (unique constraint)
  • Tested Hasura insert_teams_one with on_conflict: { constraint: teams_name_unique } — returns null (no-op) for existing team, no error
  • Verified hasura_cli starts and reaches healthy state with the timeout increase

🤖 Generated with Claude Code

Migration 1709836800001 created an expression index on lower(trim(name))
which cannot be used as a Hasura on_conflict constraint target. This broke
team auto-provisioning (dataSourceHelpers.js) because the insert mutation
uses on_conflict: { constraint: teams_name_unique }. Application code
already normalizes names to lowercase/trimmed before insert, so a plain
unique constraint is sufficient and Hasura-compatible.

Also increases hasura_cli migrations server timeout from 30s to 120s to
prevent restart loops when applying large migration sets on cold start.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@acmeguy acmeguy merged commit c0fcc92 into main Mar 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants