Spaces:
Runtime error
Runtime error
Download services/api/alembic/env.py from Oheha/cybully-api: direct link, hf CLI and curl.
- Browser
- Download file 2 kB
-
https://huggingface.co/spaces/Oheha/cybully-api/resolve/main/services/api/alembic/env.py
- Command line
-
hf download hf://spaces/Oheha/cybully-api/services/api/alembic/env.py
-
curl -L -o env.py https://huggingface.co/spaces/Oheha/cybully-api/resolve/main/services/api/alembic/env.py
2 kB
| from __future__ import annotations | |
| import socket | |
| # Save the original getaddrinfo | |
| _original_getaddrinfo = socket.getaddrinfo | |
| def _patched_getaddrinfo(*args, **kwargs): | |
| # Determine the family requested | |
| family = socket.AF_UNSPEC | |
| if 'family' in kwargs: | |
| family = kwargs['family'] | |
| elif len(args) > 2: | |
| family = args[2] | |
| responses = _original_getaddrinfo(*args, **kwargs) | |
| # If the user asked for AF_UNSPEC, filter out AF_INET6 | |
| if family == socket.AF_UNSPEC: | |
| return [r for r in responses if r[0] != socket.AF_INET6] | |
| return responses | |
| socket.getaddrinfo = _patched_getaddrinfo | |
| from logging.config import fileConfig | |
| from alembic import context | |
| from sqlalchemy import engine_from_config, pool | |
| from app.core.config import get_settings | |
| from app.core.database_url import sync_database_url | |
| from app.models import Base | |
| config = context.config | |
| if config.config_file_name is not None: | |
| fileConfig(config.config_file_name) | |
| target_metadata = Base.metadata | |
| def _sync_database_url() -> str: | |
| return sync_database_url(get_settings().database_url) | |
| def run_migrations_offline() -> None: | |
| context.configure( | |
| url=_sync_database_url(), | |
| target_metadata=target_metadata, | |
| literal_binds=True, | |
| dialect_opts={"paramstyle": "named"}, | |
| ) | |
| with context.begin_transaction(): | |
| context.run_migrations() | |
| def run_migrations_online() -> None: | |
| configuration = config.get_section(config.config_ini_section, {}) | |
| configuration["sqlalchemy.url"] = _sync_database_url() | |
| connectable = engine_from_config( | |
| configuration, | |
| prefix="sqlalchemy.", | |
| poolclass=pool.NullPool, | |
| ) | |
| with connectable.connect() as connection: | |
| context.configure(connection=connection, target_metadata=target_metadata) | |
| with context.begin_transaction(): | |
| context.run_migrations() | |
| if context.is_offline_mode(): | |
| run_migrations_offline() | |
| else: | |
| run_migrations_online() | |