railyard/apps/product-analytics/db/migrations/0030_warehouse_destinations.sql
caelum0x 0e611a19a9 feat(product-analytics): ClickHouse and BigQuery warehouse destinations
Exports reached S3 files and webhooks only (recount A22: no warehouse sync).
A project's events can now land as rows in the customer's own warehouse,
delivered by the exports runner like every destination (cursor, retries with
backoff, run log, on/off):

- ClickHouse over its HTTP interface: the table is created when missing as a
  ReplacingMergeTree ordered by the event uuid (a retried batch collapses to
  one row per event), rows go in as JSONEachRow; user in the clear, password
  sealed; database/table names checked.
- BigQuery tabledata.insertAll: the service account key (sealed) signs an
  RS256 JWT assertion exchanged for an access token at Google only (token_uri
  pinned outside tests); insertId = event uuid; a missing table is created
  once with the event schema (JSON properties, day partitions); row errors
  fail the batch.
- Migration 0030 allows the kinds; the console's new-destination form and
  client mapping offer them.

Tests: qy/warehouse (inputs, ClickHouse rows and isolation, BigQuery sign-in
verified with the public key, table created once, insertIds, a wrong password
is a retried delivery with the warehouse's reason) and the console form
mapping. qy + console suites: 41 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 16:47:45 +03:00

9 lines
515 B
SQL

-- Warehouse destinations (A22): ClickHouse and BigQuery tables of the
-- customer's own, next to the S3 file export. The sealed secret holds the
-- ClickHouse password or the BigQuery service account key, with the signing
-- secret. Idempotent.
alter table pa.export_destinations drop constraint if exists export_destinations_kind_check;
alter table pa.export_destinations add constraint export_destinations_kind_check
check (kind in ('webhook', 's3', 'slack', 'discord', 'hubspot', 'clickhouse', 'bigquery'));