mirror of
https://github.com/Hestia-Homes/survey-extraction.git
synced 2026-06-08 11:17:29 +00:00
56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
from logging.config import fileConfig
|
|
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy import pool
|
|
from alembic import context
|
|
from sqlmodel import SQLModel
|
|
|
|
from etl.models.topLevel import *
|
|
from etl.models.preSiteNoteTypes import *
|
|
from etl.models.conditionReport import *
|
|
|
|
import os
|
|
|
|
# this is the Alembic Config object, which provides
|
|
# access to the values within the .ini file in use.
|
|
# Load DB URL from env var
|
|
db_url = os.getenv("DATABASE_URL")
|
|
if not db_url:
|
|
raise RuntimeError("Please set DATABASE_URL")
|
|
|
|
if not db_url:
|
|
raise RuntimeError("Please specify database url via DATABASE_URL in env variable")
|
|
|
|
import logging
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
config = context.config
|
|
target_metadata = SQLModel.metadata
|
|
|
|
def run_migrations_offline() -> None:
|
|
context.configure(
|
|
url=db_url,
|
|
target_metadata=target_metadata,
|
|
literal_binds=True,
|
|
dialect_opts={"paramstyle": "named"},
|
|
)
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
|
|
def run_migrations_online() -> None:
|
|
engine = create_engine(db_url, poolclass=pool.NullPool)
|
|
with engine.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()
|