Repository navigation
Closed
Labels
Description
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.withTransactionfor the manual transactions), visits and the expiry top-up, pins, moderation, patch quota (a DB count, notlimits); the sweep as a service exposing onesweepjob thatapps/serverschedules. Depends oncontent-store,sql,analytics,api; neverauth— handlers receive the principal from the bearer middleware.- Migrations 3+ rewritten as the baseline with
patches/patch_versionsnaming and integer ids, registered in the migrator record afterauth's. draft → patchrename in tables and code (the wire already renamed in theapiticket). Serving paths (/d/*) do not change: readers' URLs are contract.- Implements the
patchesHttpApi group viaHttpApiBuilder.group; Fastify serves it through the seam untilserving. Row decoding throughSqlSchemain one module;SchemaError→ die. - Tests:
it.layeron a migrated database;HttpApiTest.groups(PatchyApi, ["patches"]);TestClockfor expiry and the sweep (Effect.repeatwithSchedule.spaced("1 hour")advanced by the clock); the upload-contract rollback tested with a failingContentStorelayer. Split the remaining cases out ofapp.postgres.test.tsand deleteupload-contract.test.ts. - Delete everything left in
packages/dbexcept the factory the Fastify app still imports (gone withserving). Deleteexpiry-sweep.ts. - Move patch / visit / expiry / sweep / pin / live / moderation / analytics-event terms to
packages/patches/CONTEXT.md; ADR underpackages/patches/docs/adr/only if a decision meets the tests. Promote the language-service warnings toerror.
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.
Activity