hyperswitch
05adaef1 - feat(db): add Google Spanner compatibility behind a `spanner` feature flag

Commit
69 days ago
feat(db): add Google Spanner compatibility behind a `spanner` feature flag Hyperswitch talks to Spanner through PGAdapter, which speaks the Postgres wire protocol but exposes Spanner's PostgreSQL dialect. Three of the dialect's gaps break diesel's binary encoding, so each is bridged behind a cargo feature that is off by default -- a build without `--features spanner` is byte-for-byte the PostgreSQL build it was before. Custom enum types Spanner has no `CREATE TYPE ... AS ENUM`. The `db_enum` and `text` arms of the diesel derive macro already emit identical ToSql/FromSql bodies and differ only in how they resolve the type OID, so under the feature the derive pins OID 25/1009 (text) instead of looking the type up by name. All 68 enums move to text on the wire with no change to schema.rs or to any model struct. Timestamp and JSON types Spanner rejects `timestamp without time zone` and `json`. `spanner_types` exposes `HsTimestamp`/`HsJson`, aliased per-feature to Timestamp/Json or Timestamptz/Jsonb, and every `table!` block imports them under the stock names so the generated schema is unchanged in shape. `diesel.toml` carries the same aliases, so `diesel print-schema` still reproduces schema.rs exactly. A const assertion pins the spanner aliases to their intended types, so a bad edit fails to compile rather than silently falling back through the `sql_types::*` glob. Narrow integers Spanner has one integer width: int64. `smallint`/`integer` are accepted at DDL time but stored as int64, which desynchronises diesel's binary decoder. Rather than alias these too -- which would need newtypes that pin `sql_type = Integer` and fight the numeric ops `table!` generates -- the columns are widened to bigint on both sides. This keeps one type per column across both backends and needs no per-call-site conversion. Values cross to connectors and to FRM through checked conversions at those boundaries, so the narrow trait signatures there are untouched. Also adds the schema translator (pg_dump -> Spanner DDL, with SERIAL mapped to bit-reversed identity to avoid split hotspots), a dialect probe recording what the emulator does and does not accept, a local emulator compose file, and the integer-widening migration in `migrations_manual/` with an online variant that backfills in batches behind a sync trigger. Verified end to end against the Spanner emulator: a payment is created, sent to a connector, captured and settled, with payment_intent and payment_attempt written and read back correctly. The workspace compiles clean both with and without the feature. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016b1aLNoCcoZCpytTmSSVSk
Author
Parents
Loading