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
44 changes: 44 additions & 0 deletions docs/adr/0032-collection-type-discriminator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ADR-0032: Explicit `collections.type` discriminator

**Date**: 2026-09-29
**Status**: proposed
**Deciders**: Joana Maia

## Context

Collections are either curated (created by CDP admins) or community (owned by an Insights SSO user). There is no explicit type: "curated" is inferred from `ssoUserId IS NULL` in Tinybird pipes (`collections_oss_index`, `collections_filtered`, `categories_oss_index`, `category_groups_oss_index`, `collection_buckets`, `activityRelations_collection_bucket_MV_*`, and search via `collections_filtered`) and in the Insights repo. Open Source stacks introduce a third kind, owned by an organization, with no `ssoUserId`. Under the current inference every stack row would be treated as curated and leak into curated surfaces.

## Decision

We add `collections.type` (`curated | community | stack`), backfilled from `ssoUserId`, and switch every curated/community check in Tinybird and Insights to `type` before the first stack row is written. New collection kinds extend the enum instead of adding nullable-column inference.

## Alternatives Considered

### Alternative 1: Keep inference, add a stack-specific exclusion

- **Pros**: no backfill; smaller diff.
- **Cons**: every curated filter becomes `isNull(ssoUserId) AND isNull(ownerAccountId)`; each new kind adds another clause; a missed filter silently leaks rows.
- **Why not**: the failure mode is silent and grows with each new kind.

### Alternative 2: Separate `stacks` table

- **Pros**: no change to existing collection queries.
- **Cons**: duplicates collection pages, search, project links and Tinybird replication for a near-identical entity.
- **Why not**: a stack is a collection with an org owner; splitting it doubles the read path.

## Consequences

### Positive

- Collection kind is explicit and indexable; filters are self-describing.
- Adding a future kind is an enum value plus the surfaces that should show it.

### Negative

- One-off backfill migration and a coordinated change across several Tinybird pipes and the Insights repo.
- Tinybird `collections` datasource schema change.

### Risks

- A stack row written before every filter is migrated leaks into curated surfaces. Mitigated by shipping the `type` column and filter swap first, and gating the stack write API behind that release.
- Backfill mismatch between Postgres and Tinybird. Mitigated by replicating `type` via CDC and verifying counts per type in both stores before enabling stacks.
54 changes: 54 additions & 0 deletions docs/adr/0033-salesforce-org-slugs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# ADR-0033: Salesforce account slugs for Insights org pages

**Date**: 2026-10-01
**Status**: proposed
**Deciders**: Joana Maia

## Context

Insights org pages live at `/organization/<slug>`. Slugs were generated from the org name because neither CDP nor Insights had an org slug to use, and they were always meant to switch to the Salesforce slug once Salesforce data was integrated. The slug exists only in Tinybird: `organizations_populate_slug.pipe` rebuilds it every hour from `displayName`, and when two orgs share a name the one with more contributions gets the bare slug. A rename or a shift in contribution counts changes the slug, and the old URL returns 404 because nothing records past slugs. Salesforce accounts already have a slug (`Account.Slug__c`, `account_slug` in lf-dbt) that Org Lens uses in `/org/<slug>`. It does not change on rename. With `organizationAccounts` (Open Source Stacks, C1) CDP knows which orgs match a Salesforce account.

## Decision

For a CDP org matched to a Salesforce account with a valid slug, the Insights org slug is the Salesforce slug. Other orgs keep the name-based slug, and a name-based slug that collides with a Salesforce slug gets the `--N` suffix. Every slug an org has held is kept in Tinybird, and Insights answers an old slug with a 301 to the current one.

## Alternatives Considered

### Alternative 1: Keep name-based slugs for every org

- **Pros**: no change, no URL moves.
- **Cons**: slugs keep changing on rename and on contribution shifts; Insights and Org Lens use different addresses for the same company.
- **Why not**: the instability already produces 404s, and it leaves Insights with a second slug for the same company.

### Alternative 2: Switch to Salesforce slugs without redirect history

- **Pros**: smaller change; no new datasource or middleware.
- **Cons**: every matched org's current URL breaks at once, including search engine results and links shared outside Insights.
- **Why not**: the breakage is large and permanent, and the history also fixes the existing rename 404s.

### Alternative 3: Store the slug in Postgres `organizations`

- **Pros**: one stable value per org, readable by every service.
- **Cons**: collision handling and the hourly contribution ranking move into a write path; the merge and enrichment flows would all have to maintain it.
- **Why not**: slugs are only used by Insights, which already reads them from Tinybird; keeping them there limits the change to one pipe.

## Consequences

### Positive

- Matched orgs get a slug that survives renames and contribution shifts.
- Insights and Org Lens use the same slug for matched orgs, so links between them can reuse it.
Comment on lines +39 to +40
- Old org URLs redirect instead of returning 404, for renames as well as this switch.

### Negative

- About every matched org's URL changes once; the old URL becomes a redirect.
- New lf-dbt column on `_SILVER_DIM_CDEV_ORG_TO_ACCOUNT`, so the dbt model is no longer untouched by Open Source Stacks.
- New Tinybird datasource, pipe and Insights middleware to maintain.

### Risks

- Salesforce does not enforce slug uniqueness. Two matched accounts with the same slug are ranked by contributions and the second gets `--N`, so neither page is lost.
- A Salesforce slug that is SFID-shaped or has characters outside `[a-z0-9-]` would produce a URL Insights can't route reliably. Such slugs fall back to the name-based slug.
- Switching before the history is seeded breaks URLs for a release. The history datasource and the redirect ship first, seeded with today's slugs, and the slug rule switches after.
- A slug that used to belong to one org can later become another org's current slug. The lookup checks current slugs first, so the current owner wins.
52 changes: 52 additions & 0 deletions docs/adr/0034-snowflake-salesforce-data-through-cdp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# ADR-0034: Salesforce data from Snowflake reaches Insights through CDP

**Date**: 2026-10-01
**Status**: proposed
**Deciders**: Joana Maia

## Context

The [2024-10 Insights target architecture](https://github.com/linuxfoundation/lfx-architecture-scratch/tree/main/2024-10%20Insights%20Architecture#target-architecture) planned a Snowflake → Tinybird connector for data that lives in Snowflake but not in CDP, with Salesforce organization data as the main case. That connector was never built. CDP now needs the same Salesforce data itself: the CDP org ↔ Salesforce account mapping for Open Source Stacks and org slugs (ADR-0033), and LF memberships, which today are loaded by hand from a CSV (`import-lfx-memberships.ts`). CDP already pulls Snowflake data with Temporal workers that export to S3 and consume the files (`pcc_sync_worker`, `snowflake_connectors`), and Sequin already replicates CDP Postgres tables to Tinybird.

## Decision

Salesforce data from Snowflake is ingested into CDP Postgres by a Temporal worker following the [approved `pcc_sync_worker` pattern](https://docs.google.com/document/d/1t6HyZdHGM9TA47fyJ5jRQ96z4O5esmnCDu03yNS4lwI/edit?tab=t.0#heading=h.n2bz17vu9svn), and reaches Tinybird through Sequin like any other CDP table. This replaces the planned Snowflake → Tinybird connector for organization data. A direct connector stays possible for future data that CDP has no use for.

## Alternatives Considered

### Alternative 1: Snowflake → Tinybird connector, as in the 2024-10 target architecture

- **Pros**: no CDP tables; Tinybird reads warehouse models directly.
- **Cons**: CDP still needs the same data for the memberships import, org merges and the stacks API, so it would be loaded twice through two pipelines; the merge workflow could not repoint mappings in Tinybird.
- **Why not**: CDP is a consumer of this data, not only Insights.

### Alternative 2: Both pipelines, Snowflake → CDP and Snowflake → Tinybird

- **Pros**: Tinybird does not depend on CDP for Salesforce data.
- **Cons**: two copies that can disagree, two schedules, and CDP-side fixes (merges, manual overrides) never reach Tinybird.
- **Why not**: Sequin already gives Tinybird a copy of CDP data with seconds of lag.

### Alternative 3: Extend `snowflake_connectors`

- **Pros**: one worker for every Snowflake source.
- **Cons**: its transformers produce activities (`TransformerBase` returns `IActivityData`); accounts and memberships are entities that need upserts.
- **Why not**: `pcc_sync_worker` already handles entity upserts from a Snowflake export.

## Consequences

### Positive

- One copy of Salesforce data, shared by CDP and Insights.
- The LF memberships import can be automated on the same worker instead of a manual CSV run.
- CDP-side changes such as org merges show up in Tinybird through the existing replication.

### Negative

- A new Temporal worker, or new workflows, to run and monitor.
- Every new Salesforce field Insights needs is a CDP migration plus a Sequin publication change, not only a Tinybird datasource.
- Insights depends on CDP Postgres being up to date for Salesforce data.

### Risks

- The warehouse export fails and CDP keeps stale data. Mitigated by `syncedAt` on each row and an alert when the last successful sync is older than the schedule allows.
- LF memberships move from a manual import to a sync, which changes their key from `accountName` to the Salesforce account and project IDs. Mitigated by matching existing rows on account name once and checking per-project counts against the warehouse before switching off the CSV import.
3 changes: 3 additions & 0 deletions docs/adr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ Use the `/adr` skill in Claude Code to record new ADRs or query past decisions.
| [ADR-0029](./0029-typescript-project-references.md) | TypeScript project references | accepted | 2026-09-22 |
| [ADR-0030](./0030-docs-readiness-worker-architecture.md) | Docs readiness worker — architecture | accepted | 2026-09-23 |
| [ADR-0031](./0031-frontend-modernization.md) | Frontend modernization decisions | accepted | 2026-09-29 |
| [ADR-0032](./0032-collection-type-discriminator.md) | Explicit `collections.type` discriminator | proposed | 2026-09-29 |
| [ADR-0033](./0033-salesforce-org-slugs.md) | Salesforce account slugs for Insights org pages | proposed | 2026-10-01 |
| [ADR-0034](./0034-snowflake-salesforce-data-through-cdp.md) | Salesforce data from Snowflake reaches Insights through CDP | proposed | 2026-10-01 |

## Why ADRs?

Expand Down
Loading
Loading