Skip to content

Commit 5f850ac

Browse files
committed
Fix enum collision
Adds a reference DBML file from the core implementation, I was trying to use this dbml to validate my own project and ran accross the enum collision bug
1 parent 3c3dda4 commit 5f850ac

3 files changed

Lines changed: 75 additions & 2 deletions

File tree

pydbml/database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ def add_enum(self, obj: Enum) -> Enum:
118118
if obj in self.enums:
119119
raise DatabaseValidationError(f'{obj} is already in the database.')
120120
for enum in self.enums:
121-
if enum.name == obj.name:
122-
raise DatabaseValidationError(f'Enum {obj.name} is already in the database.')
121+
if enum.name == obj.name and enum.schema == obj.schema:
122+
raise DatabaseValidationError(f'Enum {obj.schema}.{obj.name} is already in the database.')
123123

124124
self._set_database(obj)
125125
self.enums.append(obj)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Table "ecommerce"."users" as EU {
2+
id int [pk]
3+
name varchar
4+
ejs job_status
5+
ejs2 public.job_status
6+
eg schemaB.gender
7+
eg2 gender
8+
}
9+
10+
Table public.users {
11+
id int [pk]
12+
name varchar
13+
pjs job_status
14+
pjs2 public.job_status
15+
pg schemaB.gender
16+
pg2 gender
17+
}
18+
19+
Table products {
20+
id int [pk]
21+
name varchar
22+
}
23+
24+
Table schemaA.products as A {
25+
id int [pk]
26+
name varchar [ref: > EU.id]
27+
}
28+
29+
Table schemaA.locations {
30+
id int [pk]
31+
name varchar [ref: > users.id ]
32+
}
33+
34+
Ref: "public".users.id < EU.id
35+
36+
Ref name_optional {
37+
users.name < ecommerce.users.id
38+
}
39+
40+
TableGroup tablegroup_name { // tablegroup is case-insensitive.
41+
public.products
42+
users
43+
ecommerce.users
44+
A
45+
}
46+
47+
enum job_status {
48+
created2 [note: 'abcdef']
49+
running2
50+
done2
51+
failure2
52+
}
53+
54+
enum schemaB.gender {
55+
man
56+
woman
57+
nonbinary
58+
}
59+
60+
enum gender {
61+
man2
62+
woman2
63+
nonbinary2
64+
}

test/test_parser.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ def test_composite_references(self):
106106
self.assertEqual(rs[1].col2, [reviews2['post_id'], reviews2['tag']])
107107

108108

109+
class TestDBMLReferenceDef(TestCase):
110+
def test_dbml_reference_def(self):
111+
results = PyDBML.parse_file(TEST_DATA_PATH / 'dbml_schema_def.dbml')
112+
self.assertEqual(len(results.aliases), 1)
113+
self.assertEqual(len(results.tables), 5)
114+
self.assertEqual(len(results.table_groups), 1)
115+
self.assertEqual(len(results.enums), 3)
116+
117+
109118
class TestFaulty(TestCase):
110119
def test_bad_reference(self) -> None:
111120
with self.assertRaises(TableNotFoundError):

0 commit comments

Comments
 (0)