Buckets:

download
raw
2.35 kB
"""
Alembic Environment Configuration
This file configures the Alembic migration environment.
It connects to the database and sets up the migration context.
"""
import os
import sys
from logging.config import fileConfig
from sqlalchemy import engine_from_config, pool
from alembic import context
# Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
# Import database models
from database.models import DATABASE_URL, Base
# this is the Alembic Config object
config = context.config
# Set the database URL from environment or use the one from models
config.set_main_option("sqlalchemy.url", DATABASE_URL)
# Interpret the config file for Python logging
if config.config_file_name is not None:
fileConfig(config.config_file_name)
# add your model's MetaData object here for 'autogenerate' support
target_metadata = Base.metadata
def run_migrations_offline() -> None:
"""
Run migrations in 'offline' mode.
This configures the context with just a URL and not an Engine.
Calls to context.execute() here emit the given string to the script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online() -> None:
"""
Run migrations in 'online' mode.
In this scenario we need to create an Engine and associate a connection
with the context.
"""
# Override the URL if in environment
db_url = os.getenv("DATABASE_URL", DATABASE_URL)
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
url=db_url,
)
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
compare_type=True, # Detect column type changes
compare_server_default=True, # Detect default value changes
)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

Xet Storage Details

Size:
2.35 kB
·
Xet hash:
031901104230ca8eb1421d706a180f8b2b51815d6c19cd61dfd7ac6e7cc34870

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.