Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .agents/skills/sink-parity/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
name: sink-parity
description: Keep the fs, mongo and postgres sink backends at feature parity when changing any of them
---

Keep the sink backends at feature parity.

Read `AGENTS.md` first. It is the canonical project guide for this repository.

GitProxy persists its state through interchangeable sink backends: `src/db/file` (NeDB), `src/db/mongo`, and `src/db/postgres`. They all implement the `Sink` interface in `src/db/types.ts`, and deployments pick one via the `sink` config. A feature that exists in one backend but not the others is a bug waiting for whichever deployment uses the others.

Use this skill whenever a change touches any of:

- the `Sink` interface or the entity classes (`Repo`, `User`, push types) in `src/db/types.ts`
- any backend adapter under `src/db/file`, `src/db/mongo`, or `src/db/postgres`
- the migration framework (`src/db/migrations`) or the postgres schema

## The contract

- `src/db/types.ts` is the single source of truth. A new `Sink` member or entity field is not done until all three backends implement it in the same change; do not leave a backend behind for a follow-up.
- `npm run check-types:server` enforces the interface structurally, but it cannot see semantic drift. The rest of this checklist exists for what the compiler cannot catch.

## Adding or changing a Sink member

1. Add the member to the `Sink` interface with a doc comment stating its semantics (ordering, case sensitivity, empty-result shape).
2. Implement it in `src/db/file`, `src/db/mongo`, and `src/db/postgres`. Use the mongo implementation as the reference for behaviour unless the doc comment says otherwise.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the assumption here that usually a Mongo implementation will be added first (and the others must be filled in)? I feel this could be misleading if the agent takes it too literally...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering about what the "source of truth" should even be... The Mongo implementation is by default the "official" one, but it doesn't mean it'll always be the one to use as a template, especially if new Postgres functionality is added.

3. Export it from each backend's `index.ts` and wire the dispatcher in `src/db/index.ts`.
4. Add unit tests for every backend, not just the one you started from.

## Adding a field to an entity

1. Update the class in `src/db/types.ts`.
2. fs and mongo store documents whole, so writes usually pass new fields through automatically; verify reads return them.
3. postgres maps fields to columns explicitly, so every layer must be updated by hand:
- schema: add the column (see the migration rules below)
- create: insert the field, applying the same defaults as mongo (for example `dateCreated`/`lastModified` are stamped with the current ISO time on create)
- update: extend the column allowlist; a field missing from the allowlist is dropped silently, and an update reduced to zero columns throws, which has already nearly shipped a startup crash (`populateRepoDates`)
- read: add the column to every select and to the row-to-entity mapping
4. If mongo or fs bump `lastModified` (or similar) on a mutation, every backend must bump it on that mutation.

## Postgres schema changes

- Schema changes are append-only migrations; never edit or reorder an entry that has shipped.
- Cross-backend logical migrations belong in `src/db/migrations` (registered in `registry.ts`) and run through the `Sink` hooks (`getAppliedMigrations`, `recordMigration`, `unrecordMigration`), so they must work against all three backends.
- `deriveCreatedAt` is best-effort by design: mongo derives a timestamp from the ObjectId, fs and postgres return `undefined` and callers fall back. Do not assume it returns a value.

## Semantic parity rules

- Same defaults on create in every backend.
- Same case handling: usernames are lowercased on permission changes; name lookups are case-insensitive where mongo's are.
- Same projections: list endpoints must return the same field set from every backend, or UI behaviour diverges by deployment.
- Same error behaviour for invalid input (missing id, empty update).

## Verify before pushing

```
npm run check-types:server
cross-env NODE_ENV=test npx vitest --run test/db
npm run lint
npm run format:check
```

Postgres integration tests (`npm run test:integration:postgres`) need a reachable PostgreSQL database; CI runs them in the dedicated lane.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be good to add a small testing section too:

  • Explain how units vs integration tests are set up, and tell it to add both types for each adaptor
  • Tell it to make sure the operations performed in each test are identical across sinks (unless N/A)
  • Tell it to make sure the outputs of each test are identical across sinks

5 changes: 5 additions & 0 deletions .opencode/commands/sink-parity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
description: Keep the fs, mongo and postgres sink backends at feature parity
---

Follow @.agents/skills/sink-parity/SKILL.md.
4 changes: 4 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ This file is the canonical project guide. Tool-specific entry points:
- OpenCode: `.opencode/commands/`
- Codex: `AGENTS.md`

### Database changes

The fs, mongo and postgres sink backends must stay at feature parity. Before changing anything under `src/db`, read `.agents/skills/sink-parity/SKILL.md`: apparently simple adaptor changes usually cost more on the postgres side (explicit columns, update allowlists, append-only schema migrations) than on the document stores, and the skill carries the checklist that keeps the backends aligned.

---

## Agent Workflow
Expand Down
Loading