-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Summary
The database table name used for a model should be configurable. If not explicitly defined, Ferro should continue to use the current sensible default (class name lowercased, e.g. User → user).
Proposed API
Follow a pattern similar to Pydantic's ConfigDict: allow a table_config attribute on any model class.
from ferro import Model
from pydantic import ConfigDict
class User(Model):
model_config = ConfigDict(...) # Pydantic-related model config
table_config = TableConfig(name="users", ...) # Ferro table-related configurationtable_configshould be turned into a class variable automatically by the metaclass (so users define it as a normal attribute; the metaclass ensures it is treated as configuration).- Default: When
table_configis omitted orTableConfig.nameis not set, use the current behavior: table name =cls.__name__.lower().
Implementation notes
- Python: Introduce a
TableConfigtype (e.g. inbaseor a dedicated config module) with at least aname: str | None(or similar) for the table name. Metaclass should readtable_configfrom the class namespace and pass the resolved table name into schema generation/registration. - Rust: The core already receives a "name" when registering the schema (
register_model_schema(name, ...)). That name is lowercased and used as the table name everywhere. So the Python side only needs to pass the configured table name (or the defaultcls.__name__.lower()) as the registered name; the Rust API can remain name-based. - Migrations / relations: Any code that derives table name from the model (e.g.
model_name.lower()in migrations,to_tablein relations) should use the same resolved table name fromtable_config(or default) for consistency.
Acceptance criteria
-
TableConfig(or equivalent) exists with anameattribute for the table name. - Models can set
table_config = TableConfig(name="users")and the table name used in SQL/migrations is the configured value. - When
table_configis omitted ornameis not set, behavior is unchanged (table name = class name lowercased). -
table_configis established as a class variable by the metaclass so it is not treated as a field. - Docs and any relevant examples updated to show optional table name configuration.
Reactions are currently unavailable