Skip to content

Commit

Permalink
allow an optional USING btree for EXCLUDE constraints
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jeyj0 committed Mar 10, 2022
1 parent 85c31ed commit 7645ed0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions IHP/IDE/SchemaDesigner/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ parseCheckConstraint name = do

parseExcludeConstraint name = do
lexeme "EXCLUDE"
optional $ lexeme "USING btree"
excludeElements <- between (char '(' >> space) (char ')' >> space) $ excludeElement `sepBy` (char ',' >> space)
predicate <- optional do
lexeme "WHERE"
Expand Down
15 changes: 15 additions & 0 deletions Test/IDE/SchemaDesigner/ParserSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,21 @@ tests = do
, deferrableType = Nothing
}

it "should parse ALTER TABLE .. ADD CONSTRAINT .. EXCLUDE USING btree .." do
parseSql "ALTER TABLE posts ADD CONSTRAINT unique_title_by_author EXCLUDE USING btree (title WITH =, author WITH =);" `shouldBe` AddConstraint
{ tableName = "posts"
, constraint = ExcludeConstraint
{ name = "unique_title_by_author"
, excludeElements =
[ ExcludeConstraintElement { element = "title", operator = "=" }
, ExcludeConstraintElement { element = "author", operator = "=" }
]
, predicate = Nothing
}
, deferrable = Nothing
, deferrableType = Nothing
}

it "should parse ALTER TABLE .. ADD CONSTRAINT .. EXCLUDE .. WHERE .." do
parseSql "ALTER TABLE posts ADD CONSTRAINT unique_title_by_author EXCLUDE (title WITH =, author WITH =) WHERE (title = 'why');" `shouldBe` AddConstraint
{ tableName = "posts"
Expand Down

0 comments on commit 7645ed0

Please sign in to comment.