I'm running Alembic within our application code, where we have already created the sqlalchemy engine. I can pass the engine to the env.py using the tag parameter. However, the definition of the Alembic command I'm calling in our application is (copied from the Alembic python package):
def upgrade(
config: Config,
revision: str,
sql: bool = False,
tag: Optional[str] = None,
) -> None:
I'm wondering why Alembic has the type restriction Optional[str] and not just an arbitrary type for the tag. I'm not enforcing these checks and things seem to work ok when passing the sqlalchemy engine for the tag. Is there a more appropriate way of doing what I want? I'm not sure if these types hints are specified for the EnvironmentContext. Or have I misunderstood these type specifications?
These are
strs since there is another field in theConfignamedattributes, which suffices for more arbitrary custom state. It is documented as: "A Python dictionary for storage of additional state. This is a utility dictionary which can include not just strings but engines, connections, schema objects, or anything else."I've yet to test, but this looks like what I'm looking for. It had initially seemed to me that
Configwas just a wrapper around the config file.