Scope monitoring PF objects to Telegram-linked users
This commit is contained in:
16
app/db.py
16
app/db.py
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy import create_engine, inspect, text
|
||||
from sqlalchemy.orm import DeclarativeBase, sessionmaker
|
||||
|
||||
from app.config import settings
|
||||
@@ -29,3 +29,17 @@ def init_db():
|
||||
from app import models # noqa: F401 — registers models on Base
|
||||
|
||||
Base.metadata.create_all(bind=engine)
|
||||
_migrate_employees_portal_user_id()
|
||||
|
||||
|
||||
def _migrate_employees_portal_user_id() -> None:
|
||||
inspector = inspect(engine)
|
||||
if "employees" not in inspector.get_table_names():
|
||||
return
|
||||
columns = {col["name"] for col in inspector.get_columns("employees")}
|
||||
with engine.begin() as conn:
|
||||
if "portal_user_id" not in columns:
|
||||
conn.execute(text("ALTER TABLE employees ADD COLUMN portal_user_id VARCHAR(100)"))
|
||||
conn.execute(
|
||||
text("CREATE UNIQUE INDEX IF NOT EXISTS ix_employees_portal_user_id ON employees (portal_user_id)")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user