Skip to content

Commit c0fcc92

Browse files
acmeguyclaude
andauthored
Fix teams_name_unique: replace expression index with plain constraint (#33)
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>
1 parent 530d2e4 commit c0fcc92

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

docker-compose.dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ services:
103103
environment:
104104
ENABLE_TELEMETRY: "false"
105105
CONSOLE_MODE: cli
106+
HASURA_GRAPHQL_MIGRATIONS_SERVER_TIMEOUT: "120"
106107
volumes:
107108
- ./services/hasura/migrations:/hasura/migrations
108109
- ./services/hasura/metadata:/hasura/metadata
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- Revert to expression index (note: this will re-break Hasura on_conflict)
2+
ALTER TABLE public.teams DROP CONSTRAINT IF EXISTS teams_name_unique;
3+
CREATE UNIQUE INDEX teams_name_unique ON public.teams (lower(trim(name)));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Fix: expression index cannot be used as Hasura on_conflict constraint target.
2+
-- The expression index created by 1709836800001 breaks:
3+
-- on_conflict: { constraint: teams_name_unique, update_columns: [] }
4+
-- in the team auto-provisioning mutation (dataSourceHelpers.js).
5+
--
6+
-- Application code (deriveTeamName, findTeamByName) already normalizes
7+
-- names to lower(trim(name)) before insert/lookup, so a plain constraint
8+
-- is sufficient and Hasura-compatible.
9+
10+
-- Normalize any names that slipped through without lowering/trimming
11+
UPDATE public.teams SET name = lower(trim(name)) WHERE name != lower(trim(name));
12+
13+
-- Drop the expression index and replace with a plain unique constraint
14+
DROP INDEX IF EXISTS public.teams_name_unique;
15+
ALTER TABLE public.teams ADD CONSTRAINT teams_name_unique UNIQUE (name);

0 commit comments

Comments
 (0)