Skip to content

feat(patches): packages/patches with the sweep and the patch rename #76

Closed

Description

@allisonmahmood

Problem

Draft records, versions, the upload contract, visits, retention, pins, moderation and quota live in packages/db and app.ts, with the expiry sweep in apps/server/src/expiry-sweep.ts. They become the patches capability, which owns the sweep and is the one place that touches bytes.

Do

  • packages/patches: services for records + versions, the upload contract (object put then row insert, object rollback on failure — sql.withTransaction for the manual transactions), visits and the expiry top-up, pins, moderation, patch quota (a DB count, not limits); the sweep as a service exposing one sweep job that apps/server schedules. Depends on content-store, sql, analytics, api; never auth — handlers receive the principal from the bearer middleware.
  • Migrations 3+ rewritten as the baseline with patches / patch_versions naming and integer ids, registered in the migrator record after auth's.
  • draft → patch rename in tables and code (the wire already renamed in the api ticket). Serving paths (/d/*) do not change: readers' URLs are contract.
  • Implements the patches HttpApi group via HttpApiBuilder.group; Fastify serves it through the seam until serving. Row decoding through SqlSchema in one module; SchemaError → die.
  • Tests: it.layer on a migrated database; HttpApiTest.groups(PatchyApi, ["patches"]); TestClock for expiry and the sweep (Effect.repeat with Schedule.spaced("1 hour") advanced by the clock); the upload-contract rollback tested with a failing ContentStore layer. Split the remaining cases out of app.postgres.test.ts and delete upload-contract.test.ts.
  • Delete everything left in packages/db except the factory the Fastify app still imports (gone with serving). Delete expiry-sweep.ts.
  • Move patch / visit / expiry / sweep / pin / live / moderation / analytics-event terms to packages/patches/CONTEXT.md; ADR under packages/patches/docs/adr/ only if a decision meets the tests. Promote the language-service warnings to error.

Done when

pnpm dev serves uploads end to end through patches → content-store; the sweep is driven by TestClock in a test; no draft remains in tables or code.

Decisions implemented

Spec §1, §2, §3, §7, §8; Package decomposition by capability.


Filed from the Effect v4 port spec (#68) by the map task Write the port spec and file the build tickets.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:serverready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions