Team Ai
Apppublic

Multimedika/Bot_Development

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
env.py87 linesDownload Raw Back to alembic
1from logging.config import fileConfig2 3from sqlalchemy import engine_from_config4from sqlalchemy import pool5from dotenv import load_dotenv6from alembic import context7from db.models import Base8 9import os10 11load_dotenv()12 13# this is the Alembic Config object, which provides14# access to the values within the .ini file in use.15config = context.config16 17# Interpret the config file for Python logging.18# This line sets up loggers basically.19if config.config_file_name is not None:20    fileConfig(config.config_file_name)21 22config.set_main_option(23    "sqlalchemy.url", os.getenv("DB_URI_SQL_ALCHEMY")24)25# add your model's MetaData object here26# for 'autogenerate' support27# from myapp import mymodel28# target_metadata = mymodel.Base.metadata29target_metadata = Base.metadata30 31# other values from the config, defined by the needs of env.py,32# can be acquired:33# my_important_option = config.get_main_option("my_important_option")34# ... etc.35 36 37def run_migrations_offline() -> None:38    """Run migrations in 'offline' mode.39 40    This configures the context with just a URL41    and not an Engine, though an Engine is acceptable42    here as well.  By skipping the Engine creation43    we don't even need a DBAPI to be available.44 45    Calls to context.execute() here emit the given string to the46    script output.47 48    """49    url = config.get_main_option("sqlalchemy.url")50    context.configure(51        url=url,52        target_metadata=target_metadata,53        literal_binds=True,54        dialect_opts={"paramstyle": "named"},55    )56 57    with context.begin_transaction():58        context.run_migrations()59 60 61def run_migrations_online() -> None:62    """Run migrations in 'online' mode.63 64    In this scenario we need to create an Engine65    and associate a connection with the context.66 67    """68    connectable = engine_from_config(69        config.get_section(config.config_ini_section, {}),70        prefix="sqlalchemy.",71        poolclass=pool.NullPool,72    )73 74    with connectable.connect() as connection:75        context.configure(76            connection=connection, target_metadata=target_metadata77        )78 79        with context.begin_transaction():80            context.run_migrations()81 82 83if context.is_offline_mode():84    run_migrations_offline()85else:86    run_migrations_online()87