Skip to content

Commit

Permalink
Add type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
lulunac27a committed Jan 5, 2025
1 parent cf7fcd1 commit 67b3ea3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
config: context.Config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
logger = logging.getLogger("alembic.env")
logger: logging.Logger = logging.getLogger("alembic.env")


def get_engine():
Expand All @@ -24,7 +24,7 @@ def get_engine():
return current_app.extensions["migrate"].db.engine


def get_engine_url():
def get_engine_url() -> logging.Any | str:
try:
return get_engine().url.render_as_string(hide_password=False).replace("%", "%%")
except AttributeError:
Expand All @@ -44,13 +44,13 @@ def get_engine_url():
# ... etc.


def get_metadata():
def get_metadata() -> target_db:
if hasattr(target_db, "metadatas"):
return target_db.metadatas[None]
return target_db.metadata


def run_migrations_offline():
def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
This configures the context with just a URL
Expand All @@ -70,7 +70,7 @@ def run_migrations_offline():
context.run_migrations()


def run_migrations_online():
def run_migrations_online() -> None:
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
Expand All @@ -81,7 +81,7 @@ def run_migrations_online():
# this callback is used to prevent an auto-migration from being generated
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
def process_revision_directives(context, revision, directives) -> None:
if getattr(config.cmd_opts, "autogenerate", False):
script = directives[0]
if script.upgrade_ops.is_empty():
Expand Down

0 comments on commit 67b3ea3

Please sign in to comment.