From ce47e3f60e915ceb7acc3235be122aeee473a247 Mon Sep 17 00:00:00 2001 From: Brian Wiborg Date: Sat, 11 Oct 2025 13:03:31 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Auto-prefix=20table=5Fnames=20wi?= =?UTF-8?q?th=20"{app=5Flabel}=5F"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no support for auto-prefixing implicit proxy-tables in Tortoise. If you need to prefix a proxy-table, explicitly define the Model for the proxy table. Being an explicit model, it will then be auto-prefixed. --- src/ohmyapi/db/model/model.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ohmyapi/db/model/model.py b/src/ohmyapi/db/model/model.py index 929ff60..7ab918f 100644 --- a/src/ohmyapi/db/model/model.py +++ b/src/ohmyapi/db/model/model.py @@ -31,6 +31,18 @@ UUID.__get_pydantic_core_schema__ = classmethod(__uuid_schema_monkey_patch) class ModelMeta(type(TortoiseModel)): def __new__(mcls, name, bases, attrs): + meta = attrs.get("Meta", None) + if meta is None: + class Meta: + pass + meta = Meta + attrs["Meta"] = meta + + if not hasattr(meta, "table"): + # Use first part of module as app_label + app_label = attrs.get("__module__", "").replace("ohmyapi.builtin.", "ohmyapi_").split(".")[0] + setattr(meta, "table", f"{app_label}_{name.lower()}") + # Grab the Schema class for further processing. schema_opts = attrs.get("Schema", None)