Application-owned connections and code-first sync by code
Status
Section titled “Status”Accepted.
2026-09-21.
Context
Section titled “Context”A subscription needs a connection (the target endpoint and credentials). Applications want to declare both in code and sync them at deploy time, as they already do for roles and event types. That failed for two reasons. The sync required a target that the SDK never sent. And it named the connection by an id that differs in every environment, so the same code could not run unchanged in development, staging and production.
Connection and subscription codes were unique per client, so two applications sharing a client could not both use a natural code such as default.
Decision
Section titled “Decision”Connections gain an owner, and subscriptions refer to connections by code.
- Two independent axes: global (no client) versus client-scoped, and shared (no application) versus application-owned.
- Connections gain
application_code(nullable) andsource(CODE,APIorUI, defaultUI). Codes are unique per application and client:UNIQUE (COALESCE(application_code,''), COALESCE(client_id,''), code)on connections and subscriptions. This also fixes the old index, which never rejected two rows with the same code and a null client. - The migration pre-checks for collisions and refuses to apply, naming the colliding groups.
POST/PUT /api/connectionsaccept an optionalapplicationCode(must exist and be accessible to the caller; set-if-provided, never cleared).- A new sync endpoint,
POST /api/applications/{appCode}/connections/sync?removeUnlisted=<bool>, upserts connections by code. Subscription sync refers to a connection byconnectionCode, resolved within the application’s scope, so one definition works in every environment. - Rows keep a
sourceso the console can show what is owned by code and an unlisted-removal pass only touches rows it owns.
Consequences
Section titled “Consequences”Good:
- A subscription defined in code is portable across environments.
- Ownership makes the sync safe: it can remove what the application previously declared without touching hand-made rows.
- Per-application code uniqueness removes cross-application collisions.
Bad:
- Lookups must use the three-part key with null-as-a-value semantics, which is easy to get wrong in new queries.
- Any second implementation sharing the database must not recreate the old two-part unique indexes, or per-client uniqueness silently returns.
- Existing data with duplicate codes must be cleaned up before the migration applies.
Alternatives considered
Section titled “Alternatives considered”| Alternative | Why not |
|---|---|
| Keep id-based references and map ids per environment | Pushes environment mapping into every application’s deploy tooling. |
| Make codes globally unique | Forces awkward prefixes and breaks existing data. |
| Inline connection settings in the subscription | Duplicates credentials and endpoints across subscriptions. |