dak.c2s/backend/scripts/init_db.py
CCS Admin 4649f7a082 feat: Alembic migrations, initial schema
- Initialize Alembic with MySQL/MariaDB-targeted configuration
- Configure env.py to read DB URL from app.config.get_settings()
- Create initial migration (062ccae5457b) for all 11 tables:
  users, refresh_tokens, invitation_links, allowed_domains,
  cases, case_icd_codes, weekly_reports, yearly_summary,
  import_log, audit_log, notifications
- Include all indexes, foreign keys, check constraints, and
  MySQL text prefix index (icd(20))
- Add seed script (scripts/init_db.py) for dak.de domain whitelist
- DB apply deferred: MariaDB on Hetzner 1 not reachable from dev

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 07:33:27 +00:00

27 lines
684 B
Python

"""Seed initial data into the database."""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from app.database import SessionLocal
from app.models.user import AllowedDomain
def seed() -> None:
db = SessionLocal()
try:
existing = db.query(AllowedDomain).filter_by(domain="dak.de").first()
if not existing:
db.add(AllowedDomain(domain="dak.de", role="dak_mitarbeiter"))
db.commit()
print("Seeded: dak.de domain whitelist")
else:
print("Already exists: dak.de domain whitelist")
finally:
db.close()
if __name__ == "__main__":
seed()