Skip to content

Work logs: add a real team_id instead of encoding [team:slug] in the description #425

Closed

Description

@thinkclay

Today, team association on a work log is encoded as a [team:slug] prefix jammed into the free-text description (a documented workaround in the dogfood script), rather than a real column. That makes team reporting/filtering unreliable — it depends on nobody editing the description and can't be indexed or joined cleanly.

Add a team_id (or join table) to core.work_logs, backfill existing rows by parsing the [team:slug] prefix, and add a real team selector/filter to the Logs UI. This is called out directly in the Phase 3 backlog and blocks accurate per-team reporting.

Activity

  1. added
    enhancement
    on Jul 27, 2026
  2. thinkclay commented on Jul 30, 2026

    @thinkclay
    ContributorAuthor

    Done in 2f975434a (migration 339), deployed to production.

    Column: core.work_logs.team_id, nullable FK to core.teams with ON DELETE SET NULL so removing a team can't destroy work history, plus a partial index on (team_id, log_date DESC) — the query the prefix could never serve.

    Backfill resolves each encoded slug within the log's own organization, which needed two things worth recording:

    • work_logs.project_id references core.construction_projects, not core.projects, despite the column name. Joining the obvious table returned zero matches.
    • Team slugs are org-namespaced, so the short frontend in a description maps to unicorn-frontend. Deriving the prefix from the organization rather than hardcoding unicorn- keeps it correct for any org.

    Verified before writing: all 54 prefixed rows in local resolve to a team, none orphan. Production work_logs is empty, so nothing to backfill there. The prefix is only stripped from rows where a team was actually captured — an unresolvable one stays visible rather than being silently discarded, since it's the only remaining record of intent.

    teamId flows through create, update, and a list filter. Placing that filter surfaced a latent bug: the org-admin branch rebuilds the query with the service client, discarding anything applied earlier. projectId was applied early, so it was silently ignored whenever organizationId was also supplied. Both now sit in the block already labelled "common filters (apply to both user-scope and org-scope queries)".

    Verified end to end against the local API:

    log written by dogfood-log.ts -> team_id = unicorn-infra, description clean
    ?teamId=unicorn-infra  ->  10 logs   distinct team_id: 1  ✓
    no filter              ->  28 logs   distinct team_id: 4
    

    Callers updated. dogfood-log.ts resolves the team by slug instead of prepending. phase2-seed.ts drops the team prefix but keeps [phase2:key=…] — that's its idempotency marker, matched with a %…% wildcard so position doesn't matter — and resolves team ids by slug rather than hardcoding, since seed team ids are random per reset unlike the project ids.

    One piece needs a separate PR: the SDK gained teamId on create/update/list params and team_id on the returned row. It's a git submodule, so that half needs its own PR in Scaffald/sdk plus a pointer bump here. The dist is rebuilt locally so this repo type-checks and runs today.

    DOGFOODING.md's Phase 3 backlog entry is struck through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions