Skip to content

Creating a "shortcut" base #1455

Discussion options

You must be logged in to vote

That would work but it is not seamless for users.
What I did in the end is to create a decorator:

import logging
from functools import wraps

from alembic import context


def run_only_if(
    database_protocol_is: str | None = None,
    database_protocol_is_not: str | None = None,
):
    def decorator(func):
        @wraps(func)
        def wrapper():
            sqlalchemy_url = context.config.get_main_option("sqlalchemy.url")

            if ((
                database_protocol_is is not None
                and sqlalchemy_url.startswith(database_protocol_is)
            ) or (
                database_protocol_is_not is not None
                and not sqlalchemy_url.startswith(databa…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@quentin-roche
Comment options

Answer selected by quentin-roche
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants