Will commonly see examples of SQLAlchemy or SQLModel Bases that look like:
class DB1Base(SQLModel, registry=registry()):
There are x10^256 examples of this. And so lets take a step backwards and appreciate the prolific nature of
the guy in charge of random database object names
sqlalchemy docs screams to apply a database object naming convention.
alembic docs has a whole section dedicated it.
So what about SQLModel docs or issues? .... (crickets)
Every example ever lacks applying naming convention to the registry metadata!
from sqlalchemy import MetaData
from sqlalchemy.orm import registry
# copy+paste from the sqlalchemy docs. One case don't wanna be creative.
naming_convention_no_schema = {
"ix": "ix_%(column_0_label)s",
"uq": "uq_%(table_name)s_%(column_0_name)s",
"ck": "ck_%(table_name)s_`%(constraint_name)s`",
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
"pk": "pk_%(table_name)s",
}
metadata = MetaData(
naming_convention=naming_convention_no_schema,
schema=schema,
)
reg = registry(metadata=metadata)
class DB1Base(SQLModel, registry=reg):
Why not to -- job security!
Can only imagine that folks wanting to give every single database object a name manually would do that as a form of job security. If that is the case then carry on.
For those of us who don't want to micro manage the micro manage of micro managers, would highly suggest not manually explicitly naming each and every database object. In each and every database. Not ever, but almost nearly ever.
For example, what if the guy in charge of random database object names gets a girlfriend? It could happen and what a disaster that would be. For him, for her, and for all the people who have to try to track down why a foreign key or unique constraint doesn't exist when it's clear as day in the code that it should be there.
Might have exaggerated, there is no agency of random database object names. But that won't stop the guy in charge of random database object names. Numerically, he can snap his fingers and poof, that agency will exist. Don't underestimate the power and unflinching resolve of the guy in charge of random database object names
The take away
Every single SQLModel Base ever neglects, when creating a registry, to apply database objects naming convention. This includes the SQLModel source code.
So why not submit a PR? SQLModel seems to be unmaintained. There are 69 PRs in the pipeline. So the options are:
-
wait for hell to start selling ice cream
-
poke fun at it
Only have enough coin for the boat man. So that leaves ...
btw my favorite super hero is the mustache guy from Deadpool. All time favorite.
Made a very convincing argument that what the super hero universes need is a guy with a thick mustache who just happened to show up for the interview with that stash.
That's what's been missing from every super hero team.
As far as i can tell the mustache guy seems like a good blook.
I hate good people with their good intentions, mustache guy didn't have good intentions. He just happened to want the job. Which was good enough for Deadpool.
This is why i'm nominating the guy in charge of random database object names to the team.
btw this is not off topic, read the SQLModel docs! All the examples are about super heroes and their teams. None of which i recognize cuz there also seems to be the guy who misspells super heroes and teams names
Which sorta makes sense. Anyone who'd lower case all table names would probably not be above misspelling super heroes and teams names.
Is there anything more sinister than lower casing all table names? And then ... get this ... preventing changing the table naming algo by hiding the implementation within a metaclass. Leaving the only option, to hardcode each and every table name.