Skip to content

Commit befbb8d

Browse files
changed to _ seperator for names
1 parent 7d38cc1 commit befbb8d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

backend/app/utils/migrations.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88
def _table_name_for_classification(c: Classification) -> str:
99
"""
1010
Deterministic mapping from classification name to SQL table name.
11-
Removes spaces and special characters, keeps only alphanumeric.
12-
Example: "Product Brochure/Leaflet" -> "productbrochureleaflet"
13-
Example: "Robot Specifications" -> "robotspecifications"
11+
Converts spaces and special characters to underscores, keeps only alphanumeric and underscores.
12+
Example: "Product Brochure/Leaflet" -> "product_brochure_leaflet"
13+
Example: "Robot Specifications" -> "robot_specifications"
1414
"""
15-
# Remove spaces and convert to lowercase
15+
# Convert to lowercase
1616
name = c.name.lower()
17-
# Keep only alphanumeric characters
18-
name = "".join(char if char.isalnum() else "" for char in name)
17+
# Replace non-alphanumeric characters with underscores
18+
name = "".join(char if char.isalnum() else "_" for char in name)
19+
# Remove consecutive underscores and strip leading/trailing underscores
20+
while "__" in name:
21+
name = name.replace("__", "_")
22+
name = name.strip("_")
1923

2024
# Ensure it starts with a letter (not a number)
2125
if name and name[0].isdigit():

0 commit comments

Comments
 (0)