Check in current backend
This commit is contained in:
@ -1,11 +1,20 @@
|
||||
import os
|
||||
from logging.config import fileConfig
|
||||
|
||||
from sqlalchemy import engine_from_config
|
||||
from sqlalchemy import pool
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from alembic import context
|
||||
from sshecret_backend.models import *
|
||||
|
||||
def get_database_url() -> str:
|
||||
"""Get database URL."""
|
||||
if db_file := os.getenv("SSHECRET_BACKEND_DB"):
|
||||
return f"sqlite:///{db_file}"
|
||||
return "sqlite:///sshecret.db"
|
||||
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
@ -40,7 +49,7 @@ def run_migrations_offline() -> None:
|
||||
script output.
|
||||
|
||||
"""
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
url = get_database_url()
|
||||
context.configure(
|
||||
url=url,
|
||||
target_metadata=target_metadata,
|
||||
@ -59,11 +68,7 @@ def run_migrations_online() -> None:
|
||||
and associate a connection with the context.
|
||||
|
||||
"""
|
||||
connectable = engine_from_config(
|
||||
config.get_section(config.config_ini_section, {}),
|
||||
prefix="sqlalchemy.",
|
||||
poolclass=pool.NullPool,
|
||||
)
|
||||
connectable = create_engine(get_database_url())
|
||||
|
||||
with connectable.connect() as connection:
|
||||
context.configure(
|
||||
|
||||
Reference in New Issue
Block a user