Skip to content

Commit 7645ed0

Browse files
committed
allow an optional USING btree for EXCLUDE constraints
pg_dump uses that for the default EXCLUDE constraints. This allows migrations to work again for projects that use EXCLUDE constraints. A more sophisticated fix would allow the different index types here.
1 parent 85c31ed commit 7645ed0

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

IHP/IDE/SchemaDesigner/Parser.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ parseCheckConstraint name = do
189189

190190
parseExcludeConstraint name = do
191191
lexeme "EXCLUDE"
192+
optional $ lexeme "USING btree"
192193
excludeElements <- between (char '(' >> space) (char ')' >> space) $ excludeElement `sepBy` (char ',' >> space)
193194
predicate <- optional do
194195
lexeme "WHERE"

Test/IDE/SchemaDesigner/ParserSpec.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,21 @@ tests = do
348348
, deferrableType = Nothing
349349
}
350350

351+
it "should parse ALTER TABLE .. ADD CONSTRAINT .. EXCLUDE USING btree .." do
352+
parseSql "ALTER TABLE posts ADD CONSTRAINT unique_title_by_author EXCLUDE USING btree (title WITH =, author WITH =);" `shouldBe` AddConstraint
353+
{ tableName = "posts"
354+
, constraint = ExcludeConstraint
355+
{ name = "unique_title_by_author"
356+
, excludeElements =
357+
[ ExcludeConstraintElement { element = "title", operator = "=" }
358+
, ExcludeConstraintElement { element = "author", operator = "=" }
359+
]
360+
, predicate = Nothing
361+
}
362+
, deferrable = Nothing
363+
, deferrableType = Nothing
364+
}
365+
351366
it "should parse ALTER TABLE .. ADD CONSTRAINT .. EXCLUDE .. WHERE .." do
352367
parseSql "ALTER TABLE posts ADD CONSTRAINT unique_title_by_author EXCLUDE (title WITH =, author WITH =) WHERE (title = 'why');" `shouldBe` AddConstraint
353368
{ tableName = "posts"

0 commit comments

Comments
 (0)