feat: Implement SQLAlchemy enum helper and normalize enum values in database initialization
This commit is contained in:
@@ -60,7 +60,7 @@ class FakeConnection:
|
||||
sql = str(statement).strip()
|
||||
lower_sql = sql.lower()
|
||||
|
||||
if lower_sql.startswith("do $$ begin"):
|
||||
if lower_sql.startswith("do $$"):
|
||||
match = re.search(r"create type\s+(\w+)\s+as enum", lower_sql)
|
||||
if match:
|
||||
self.state.enums.add(match.group(1))
|
||||
@@ -194,6 +194,18 @@ class FakeConnection:
|
||||
self.state.financial_inputs[key] = record
|
||||
return FakeResult([])
|
||||
|
||||
if "from pg_enum" in lower_sql and "enumlabel" in lower_sql:
|
||||
type_name_param = params.get("type_name")
|
||||
if type_name_param is None:
|
||||
return FakeResult([])
|
||||
type_name = str(type_name_param)
|
||||
values = init_db.ENUM_DEFINITIONS.get(type_name, [])
|
||||
rows = [SimpleNamespace(enumlabel=value) for value in values]
|
||||
return FakeResult(rows)
|
||||
|
||||
if lower_sql.startswith("alter type") and "rename value" in lower_sql:
|
||||
return FakeResult([])
|
||||
|
||||
raise NotImplementedError(
|
||||
f"Unhandled SQL during test execution: {sql}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user