generated from coulomb/repo-seed
feat(api): CUST-WP-0018 — API hardening & code quality
T01: Fix datetime.utcnow() → datetime.now(tz=timezone.utc) in MCP server T02: Wrap _get/_post/_patch/_delete with try/except; return error dicts T03: Log warnings when write_log skips missing project path T04: Add priority + due_date_before filters to GET /tasks/ T05: Add owner + slug filters to GET /workstreams/ T06: Add offset param to GET /progress/ for proper pagination T07: Low-severity bundle: - CORS origins from CORS_ORIGINS env var (TD-017) - seed.py upsert domains+topics on re-run (TD-011) - normalise filter bar CSS → filter-text-input everywhere (TD-016) - add 30.5 avg-days-per-month comment in decisions.md (TD-019) - TD-009, TD-018 already resolved by existing code Closes CUST-WP-0018. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -82,7 +82,7 @@ TOPICS = [
|
||||
|
||||
async def seed() -> None:
|
||||
async with async_session_factory() as session:
|
||||
# ── Insert domains (idempotent) ───────────────────────────────────────
|
||||
# ── Upsert domains ────────────────────────────────────────────────────
|
||||
domain_by_slug: dict[str, Domain] = {}
|
||||
for data in DOMAINS:
|
||||
existing = await session.execute(
|
||||
@@ -90,7 +90,11 @@ async def seed() -> None:
|
||||
)
|
||||
domain = existing.scalar_one_or_none()
|
||||
if domain is not None:
|
||||
print(f" skip domain (exists): {data['slug']}")
|
||||
if domain.name != data["name"]:
|
||||
domain.name = data["name"]
|
||||
print(f" update domain: {data['slug']}")
|
||||
else:
|
||||
print(f" skip domain (no change): {data['slug']}")
|
||||
else:
|
||||
domain = Domain(slug=data["slug"], name=data["name"])
|
||||
session.add(domain)
|
||||
@@ -98,24 +102,35 @@ async def seed() -> None:
|
||||
print(f" insert domain: {data['slug']}")
|
||||
domain_by_slug[data["slug"]] = domain
|
||||
|
||||
# ── Insert topics (idempotent) ─────────────────────────────────────────
|
||||
# ── Upsert topics ─────────────────────────────────────────────────────
|
||||
for data in TOPICS:
|
||||
existing = await session.execute(
|
||||
select(Topic).where(Topic.slug == data["slug"])
|
||||
)
|
||||
if existing.scalar_one_or_none() is not None:
|
||||
print(f" skip topic (exists): {data['slug']}")
|
||||
continue
|
||||
topic = existing.scalar_one_or_none()
|
||||
domain = domain_by_slug[data["domain_slug"]]
|
||||
topic = Topic(
|
||||
slug=data["slug"],
|
||||
title=data["title"],
|
||||
description=data["description"],
|
||||
domain_id=domain.id,
|
||||
status=TopicStatus.active,
|
||||
)
|
||||
session.add(topic)
|
||||
print(f" insert topic: {data['slug']}")
|
||||
if topic is not None:
|
||||
changed = False
|
||||
if topic.title != data["title"]:
|
||||
topic.title = data["title"]
|
||||
changed = True
|
||||
if topic.description != data["description"]:
|
||||
topic.description = data["description"]
|
||||
changed = True
|
||||
if topic.domain_id != domain.id:
|
||||
topic.domain_id = domain.id
|
||||
changed = True
|
||||
print(f" {'update' if changed else 'skip'} topic ({'changed' if changed else 'no change'}): {data['slug']}")
|
||||
else:
|
||||
topic = Topic(
|
||||
slug=data["slug"],
|
||||
title=data["title"],
|
||||
description=data["description"],
|
||||
domain_id=domain.id,
|
||||
status=TopicStatus.active,
|
||||
)
|
||||
session.add(topic)
|
||||
print(f" insert topic: {data['slug']}")
|
||||
|
||||
await session.commit()
|
||||
await engine.dispose()
|
||||
|
||||
Reference in New Issue
Block a user