Spaces:
Sleeping
Sleeping
File size: 1,374 Bytes
c55abce | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | """Seed the client_domains table from scripts/seed_client_domains.json.
Idempotent — running this multiple times updates existing rows in place
instead of erroring. Safe to run after deploys or whenever you've added
new mappings to the JSON file.
Usage: python -m scripts.seed_client_domains
"""
from __future__ import annotations
import asyncio
import json
import sys
from pathlib import Path
# Make repo root importable when invoked as `python scripts/seed_client_domains.py`
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from app.config import settings
from app.database import get_db
from app.lib.utils.client_routing import add_or_update_client_domain
SEED_FILE = Path(__file__).resolve().parent / "seed_client_domains.json"
async def main() -> None:
data = json.loads(SEED_FILE.read_text())
# Strip the README-style key if present.
data.pop("_README", None)
if not data:
print("Nothing to seed — JSON file has no mappings.")
return
async with get_db(settings.database_path) as conn:
for domain, client_name in data.items():
await add_or_update_client_domain(conn, domain, client_name)
print(f" {domain:40s} → {client_name}")
print(f"\nSeeded {len(data)} domain mapping(s) into {settings.database_path}.")
if __name__ == "__main__":
asyncio.run(main())
|