I have some very common columns I’d like to share between different tables, but no special relationships between them. For example “created_at”. I think the right approach is concrete table inheritance but I’m not sure.
The base class would be there only for code-reuse, and will not have its own table.
This is all assuming I’m using the type-annotated sqlalchemy 2.0 approach, e.g. perhaps do something like that (see below). What is the right approach?
class TimestampMixin:
created_at: Mapped[datetime] = mapped_column(nullable=False)
updated_at: Mapped[datetime] = mapped_column(nullable=False)
class TableA(TimestampMixin, Base):
__tablename__ = 'table_a'
id: Mapped[int] = mapped_column(primary_key=True)
# other columns specific to TableA
class TableB(TimestampMixin, Base):
__tablename__ = 'table_b'
id: Mapped[int] = mapped_column(primary_key=True)