Skip to content

Commit b3df4ef

Browse files
amtiYoclaude
andcommitted
docs: reflect shared core-postgres migration (v1.0.2)
Update README, docs/architecture.md, AGENTS.md, and .env.example comments so they describe the post-consolidation database topology: Branchy stores its durable state in a `branchy` schema and delegates Telegram identity/presence to a shared `core` schema (`core.person`/`core.chat`) via `core.touch`. In production this lives in the shared `core-postgres`, reached on a single pool with `search_path=branchy`; local `docker compose` seeds a minimal `core` schema (deploy/core-init.sql) so migrations boot. The durable Postgres outbox messaging is unchanged (the outbox is a `branchy` table). Docs-only; no code changes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GAeQtwgsRecG7D3Lc6RVuV
1 parent b3db838 commit b3df4ef

4 files changed

Lines changed: 46 additions & 7 deletions

File tree

‎.env.example‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# SPDX-License-Identifier: Apache-2.0
22
HTTP_ADDR=:8080
3+
# Branchy's own tables live in a `branchy` schema and reference a shared `core`
4+
# schema (core.person/core.chat, upserted via core.touch). `docker compose` runs
5+
# a bundled Postgres, seeds a minimal `core` schema (deploy/core-init.sql), and
6+
# adds `options=-csearch_path%3Dbranchy` to this URL. Against a shared or
7+
# standalone database, append `?options=-csearch_path%3Dbranchy` (in production
8+
# this points at the shared core-postgres).
39
DATABASE_URL=postgres://branchy:branchy@localhost:5432/branchy?sslmode=disable
410
MIGRATIONS_DIR=migrations
511
AUTO_MIGRATE=true

‎AGENTS.md‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ This file is for coding agents working on Branchy. Keep the project minimal, sec
55
## Project Shape
66

77
- Branchy is one Go service.
8-
- PostgreSQL is the only durable store.
8+
- PostgreSQL is the only durable store. Branchy's tables live in a `branchy`
9+
schema; Telegram identity/presence is delegated to a shared `core` schema
10+
(`core.person`, `core.chat`) upserted via `core.touch`. In production this is
11+
the shared `core-postgres`, reached on a single pool with `search_path=branchy`
12+
(the retired standalone `branchy-postgres` is gone).
913
- Telegram uses long polling in the MVP.
1014
- GitHub OAuth callbacks and repository webhooks are served by the same HTTP process.
1115
- Notification delivery uses the durable PostgreSQL outbox, not direct sending inside the webhook handler.
@@ -59,6 +63,11 @@ Temporary Telegram/GitHub failures should retry with `retry_at` and `attempts`.
5963

6064
- Add new SQL migrations under `migrations/` with the next numeric prefix.
6165
- Migrations must be safe to run once and tracked by `schema_migrations`.
66+
- Migrations run against the `branchy` schema (`search_path=branchy`) and may FK
67+
into `core.person`/`core.chat` or call `core.touch`; those live in the shared
68+
`core-postgres` in production and are seeded locally by `deploy/core-init.sql`
69+
so `docker-compose up` boots. Do not recreate the dropped local
70+
`telegram_users`/`telegram_chats` tables.
6271
- Do not edit old migrations after they may have been applied, unless the repo is still explicitly pre-release and the user asks for it.
6372
- Keep `AUTO_MIGRATE=true` useful for local development.
6473

‎README.md‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ Branchy runs startup migrations from `migrations/` and records completed
119119
versions in `schema_migrations`. Keep `AUTO_MIGRATE=true` for local
120120
development.
121121

122+
The bundled `docker compose` runs a local PostgreSQL and seeds a minimal shared
123+
`core` schema (`deploy/core-init.sql`) so migrations that reference
124+
`core.person` / `core.chat` boot cleanly. In the shared production deployment
125+
Branchy instead connects to the existing `core-postgres`.
126+
122127
---
123128

124129
## Using Branchy
@@ -141,7 +146,13 @@ delivery is enabled, Branchy verifies that the Telegram user is a group
141146

142147
## How It Works
143148

144-
Branchy is one Go service with PostgreSQL as the only durable store.
149+
Branchy is one Go service with PostgreSQL as its only durable store. Branchy's
150+
own tables — subscriptions, the notification outbox, OAuth and runtime state —
151+
live in a `branchy` schema. Telegram identity and presence (users and chats) are
152+
delegated to a shared `core` schema (`core.person`, `core.chat`), which Branchy
153+
upserts via `core.touch` before any dependent write. In production that schema
154+
lives in the shared `core-postgres` database; local `docker compose` seeds a
155+
minimal `core` schema so development boots the same way.
145156

146157
```text
147158
telegram poller -> inline-button UI
@@ -184,7 +195,7 @@ Permanent delivery failures are marked `failed`.
184195

185196
| Variable | Required | Default | Description |
186197
|:--|:--:|:--|:--|
187-
| `DATABASE_URL` | yes | - | PostgreSQL connection string |
198+
| `DATABASE_URL` | yes | - | PostgreSQL connection string; Branchy's tables live in the `branchy` schema, so a shared database needs `search_path=branchy` (append `options=-csearch_path%3Dbranchy`) |
188199
| `PUBLIC_BASE_URL` | yes | - | Public HTTPS base URL |
189200
| `TELEGRAM_BOT_TOKEN` | yes | - | Bot token from BotFather |
190201
| `GITHUB_CLIENT_ID` | yes | - | GitHub OAuth App client ID |

‎docs/architecture.md‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ Branchy is one Go service with three runtime surfaces:
66
- HTTP routes for GitHub OAuth and GitHub repository webhooks.
77
- A notification outbox worker that sends queued Telegram messages.
88

9-
The service stores all durable state in PostgreSQL. GitHub webhook handlers do
10-
not send Telegram messages directly; they create durable `notification_jobs`
11-
rows and return quickly. The worker polls pending jobs with `FOR UPDATE SKIP
12-
LOCKED`, sends Telegram messages, and updates job status.
9+
The service stores its durable state in PostgreSQL. Branchy's own tables live in
10+
a `branchy` schema (subscriptions, repositories, hooks, the notification outbox,
11+
OAuth and runtime state), and Telegram identity/presence is delegated to a shared
12+
`core` schema (`core.person`, `core.chat`) that Branchy upserts through the
13+
`SECURITY DEFINER` `core.touch` function before any dependent write. In production
14+
this is the shared `core-postgres` database; local `docker compose` seeds a
15+
minimal `core` schema (`deploy/core-init.sql`) so migrations boot. GitHub webhook
16+
handlers do not send Telegram messages directly; they create durable
17+
`notification_jobs` rows and return quickly. The worker polls pending jobs with
18+
`FOR UPDATE SKIP LOCKED`, sends Telegram messages, and updates job status.
1319

1420
## Packages
1521

@@ -49,6 +55,13 @@ LOCKED`, sends Telegram messages, and updates job status.
4955
webhook routes.
5056
- One service keeps the codebase small. The durable outbox lives in PostgreSQL
5157
instead of adding separate queue infrastructure.
58+
- Branchy owns the `branchy` schema and, in production, connects to the shared
59+
`core-postgres` as a dedicated least-privilege role (`branchy_core`) with
60+
`search_path=branchy` on a single pool. Domain tables reference shared identity
61+
in the `core` schema by natural key (Telegram id) and call `core.touch`
62+
schema-qualified on that same pool — there is no separate `core` connection.
63+
The old standalone `branchy-postgres` container is retired (its volume kept for
64+
rollback).
5265
- GitHub webhooks are owned per repository, not per subscription. Active
5366
subscription events are unioned into the repository hook configuration. When
5467
the active event union becomes empty, Branchy deletes its matching hook.

0 commit comments

Comments
 (0)