Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pydbml/definitions/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
pp.ParserElement.set_default_whitespace_chars(' \t\r')

index_type = pp.CaselessLiteral("type:").suppress() + _ - (
pp.CaselessLiteral("btree")('type') | pp.CaselessLiteral("hash")('type')
pp.CaselessLiteral("brin")('type') |
pp.CaselessLiteral("btree")('type') |
pp.CaselessLiteral("gin")('type') |
pp.CaselessLiteral("gist")('type') |
pp.CaselessLiteral("hash")('type') |
pp.CaselessLiteral("spgist")('type')
)
index_setting = _ + (
unique('unique')
Expand Down
12 changes: 11 additions & 1 deletion pydbml/parser/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,17 @@ class IndexBlueprint(Blueprint):
subject_names: List[Union[str, ExpressionBlueprint]]
name: Optional[str] = None
unique: bool = False
type: Optional[Literal['hash', 'btree']] = None
type: Optional[
Literal[
# https://www.postgresql.org/docs/current/indexes-types.html
"brin",
"btree",
"gin",
"gist",
"hash",
"spgist",
]
] = None
pk: bool = False
note: Optional[NoteBlueprint] = None
comment: Optional[str] = None
Expand Down
16 changes: 10 additions & 6 deletions test/test_definitions/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@

class TestIndexType(TestCase):
def test_correct(self) -> None:
val = 'Type: BTREE'
res = index_type.parse_string(val, parseAll=True)
self.assertEqual(res['type'], 'btree')
val2 = 'type:\nhash'
res2 = index_type.parse_string(val2, parseAll=True)
self.assertEqual(res2['type'], 'hash')
for val, expected in [
("Type: BTREE", "btree"),
("type: hash", "hash"),
("type: gist", "gist"),
("TYPE:SPGiST", "spgist"),
("type: GIN", "gin"),
("Type:\tbRiN", "brin"),
]:
res = index_type.parse_string(val, parseAll=True)
self.assertEqual(res["type"], expected)

def test_incorrect(self) -> None:
val = 'type: wrong'
Expand Down