Skip to content

Commit 49d4ac1

Browse files
mpscholtenclaude
andcommitted
Fix non-exhaustive pattern match in normalizeExpression for PostgreSQL 17
Add missing InArrayExpression case to normalizeExpression function. PostgreSQL 17's pg_dump produces tuple literals like ('a', 'b') more frequently, causing the migration generator to crash with "Non-exhaustive patterns in function normalizeExpression". Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cbef0b2 commit 49d4ac1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

ihp-ide/IHP/IDE/CodeGen/MigrationGenerator.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ normalizeExpression (SelectExpression Select { columns, from, whereClause, alias
519519
unqualifiedName name = name
520520
normalizeExpression (DotExpression a b) = DotExpression (normalizeExpression a) b
521521
normalizeExpression (ExistsExpression a) = ExistsExpression (normalizeExpression a)
522+
normalizeExpression (InArrayExpression exprs) = InArrayExpression (map normalizeExpression exprs)
522523

523524
-- | Replaces @table.field@ with just @field@
524525
--

ihp-ide/Test/IDE/CodeGeneration/MigrationGenerator.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,25 @@ CREATE POLICY "Users can read and edit their own record" ON public.users USING (
14291429

14301430
diffSchemas targetSchema actualSchema `shouldBe` migration
14311431

1432+
it "should normalize InArrayExpression in check constraints" do
1433+
-- Ensures normalizeExpression handles InArrayExpression (tuple literals like ('a', 'b'))
1434+
-- This pattern appears more frequently in PostgreSQL 17's pg_dump output
1435+
let targetSchema = sql $ cs [plain|
1436+
CREATE TABLE posts (
1437+
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL,
1438+
status TEXT NOT NULL
1439+
);
1440+
ALTER TABLE posts ADD CONSTRAINT posts_status_check CHECK (status IN ('draft', 'published', 'archived'));
1441+
|]
1442+
let actualSchema = sql $ cs [plain|
1443+
CREATE TABLE public.posts (
1444+
id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
1445+
status text NOT NULL,
1446+
CONSTRAINT posts_status_check CHECK ((status IN ('draft', 'published', 'archived')))
1447+
);
1448+
|]
1449+
diffSchemas targetSchema actualSchema `shouldBe` []
1450+
14321451
sql :: Text -> [Statement]
14331452
sql code = case Megaparsec.runParser Parser.parseDDL "" code of
14341453
Left parsingFailed -> error (cs $ Megaparsec.errorBundlePretty parsingFailed)

0 commit comments

Comments
 (0)