How to define multiple, useful mixin classes, including messing with __table_args__
?
#582
Unanswered
jfb-workhelix
asked this question in
Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
I'm trying to perform some cleanup on our models, and one of the things I'd like to do is to remove boilerplate, of which there is a lot. I've pared this down as much as possible for the example, but briefly; I have a fair number (~100) tables, and I'd really really really like to lift some boilerplate out of the model definitions. I thought, ok, I'll define a number of mixins, and I'll be good to go.
First, we heavily use PostgreSQL schemata, so I want to add first-class support for specifying the schema; something like,
The only way I could see to get this to work was by playing horrible games with the
__table_args__
variable (see above). OK, horrible games are fine, if they're documented, good, that works. And it does! But then:Second, there are a subset of tables that need to have certain columns defined on them: the standard
updated_at/created_at
pair, as well as ones that are used in ourdataset
abstraction (it's a way of grouping read-only data together for purposes of data lineage/auditing/&c., by joining subsidiary tables into adataset
entity). IOW, with the definitions above, you'd get:However, I'm stymied at the first, because if I do use one of these Mixins, I get:
If I add the
__config__ = None
intoDatasetable
, ok, it works? Kind of? But when I runalembic
, I can see that I do not get thedataset_id
field in the DDL definition. At this point, magic stuff is happening that exceeds my Python understanding, so I thought I'd throw myself on the tender mercies of the internet.Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.8
Python Version
3.11.2
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions