[main] fix startup when there's no db

This commit is contained in:
2026-07-29 18:37:34 +02:00
parent 7a70b6b1d4
commit a8e80ed19d
4 changed files with 12 additions and 9 deletions

View File

@@ -11,15 +11,16 @@ config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
#if config.config_file_name is not None:
# fileConfig(config.config_file_name, disable_existing_loggers=False)
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from app.model.models import Base
target_metadata = Base.metadata
from app.model import models
target_metadata = models.Base.metadata
# other values from the config, defined by the needs of env.py,
# can be acquired:

View File

@@ -8,4 +8,4 @@ SECRET_KEY="8b14d0b447bff7efa24d5019cc59a999786e31f6f865173bbd642bf18de5ad85"
#Key for oauth
#THESE ARE TESTING KEYS - DO NOT USE IN PROD
SQLALCHEMY_DATABASE_URL="sqlite:///./gatekeeper.db"
SQLALCHEMY_DATABASE_PATH="./gatekeeper.db"

View File

@@ -5,19 +5,21 @@ from sqlmodel import Session, SQLModel, create_engine
logger = logging.getLogger(__name__)
SQLALCHEMY_DATABASE_URL = getenv("SQLALCHEMY_DATABASE_URL", "sqlite:///./gatekeeper.db")
SQLALCHEMY_DATABASE_PATH = getenv("SQLALCHEMY_DATABASE_PATH", "./gatekeeper.db")
SQLALCHEMY_DATABASE_URL = "sqlite:///" + SQLALCHEMY_DATABASE_PATH
engine = create_engine(SQLALCHEMY_DATABASE_URL)
def create_db_and_tables():
if not path.exists(SQLALCHEMY_DATABASE_URL):
if not path.exists(SQLALCHEMY_DATABASE_PATH):
SQLModel.metadata.create_all(engine)
from alembic.config import Config
from alembic import command
alembic_cfg = Config("./alembic.ini")
alembic_cfg.attributes["sqlalchemy.url"] = SQLALCHEMY_DATABASE_URL
command.stamp(alembic_cfg, "head")
logger.info("Database created and tables initialized.")
else:

View File

@@ -11,7 +11,7 @@ def verify_settings():
"MIFARE_ACL_WRITE_BASE_KEY",
]
important_envs = ["SECRET_KEY"]
other_envs = ["SQLALCHEMY_DATABASE_URL"]
other_envs = ["SQLALCHEMY_DATABASE_PATH"]
for setting in card_envs:
if (setting not in os.environ or setting == "") and not os.getenv(
"DISABLE_CARDS"
@@ -26,4 +26,4 @@ def verify_settings():
)
for setting in other_envs:
if setting not in os.environ:
logger.critical(f"Env var {setting} not set. Continuing with defaults.")
logger.warning(f"Env var {setting} not set. Continuing with defaults.")