From 6d360eda38ddef58e0f305948acf408bb7694cfd Mon Sep 17 00:00:00 2001 From: Darick Tong <132324914+darkgnotic@users.noreply.github.com> Date: Wed, 18 Dec 2024 18:25:45 -0800 Subject: [PATCH] feat(zero-cache): support pg UUIDs, replicated as strings (#3420) --- .../pg/change-source.end-to-mid.pg-test.ts | 20 +++++++++++++++---- packages/zero-cache/src/types/lite.ts | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/zero-cache/src/services/change-streamer/pg/change-source.end-to-mid.pg-test.ts b/packages/zero-cache/src/services/change-streamer/pg/change-source.end-to-mid.pg-test.ts index 8d8d1b23a..690425f67 100644 --- a/packages/zero-cache/src/services/change-streamer/pg/change-source.end-to-mid.pg-test.ts +++ b/packages/zero-cache/src/services/change-streamer/pg/change-source.end-to-mid.pg-test.ts @@ -56,7 +56,8 @@ describe('change-source/pg/end-to-mid-test', () => { time TIME, json JSON, jsonb JSONB, - numz ENUMZ + numz ENUMZ, + uuid UUID ); -- Use the internal zero schema to test tables in a different schema, @@ -753,9 +754,9 @@ describe('change-source/pg/end-to-mid-test', () => { 'data types', ` ALTER PUBLICATION zero_some_public SET TABLE foo ( - id, int, big, flt, bool, timea, date, json, jsonb, numz); + id, int, big, flt, bool, timea, date, json, jsonb, numz, uuid); - INSERT INTO foo (id, int, big, flt, bool, timea, date, json, jsonb, numz) + INSERT INTO foo (id, int, big, flt, bool, timea, date, json, jsonb, numz, uuid) VALUES ( 'abc', -2, @@ -766,7 +767,8 @@ describe('change-source/pg/end-to-mid-test', () => { 'April 12, 2003', '[{"foo":"bar","bar":"foo"},123]', '{"far": 456, "boo" : {"baz": 123}}', - '2' + '2', + 'A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11' ); `, [ @@ -778,6 +780,7 @@ describe('change-source/pg/end-to-mid-test', () => { {tag: 'add-column'}, {tag: 'add-column'}, {tag: 'add-column'}, + {tag: 'add-column'}, { tag: 'insert', new: { @@ -790,6 +793,7 @@ describe('change-source/pg/end-to-mid-test', () => { json: [{foo: 'bar', bar: 'foo'}, 123], jsonb: {boo: {baz: 123}, far: 456}, numz: '2', + uuid: 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', }, }, ], @@ -806,6 +810,7 @@ describe('change-source/pg/end-to-mid-test', () => { json: '[{"foo":"bar","bar":"foo"},123]', jsonb: '{"boo":{"baz":123},"far":456}', numz: '2', // Verifies TEXT affinity + uuid: 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', ['_0_version']: expect.stringMatching(/[a-z0-9]+/), }, ], @@ -884,6 +889,13 @@ describe('change-source/pg/end-to-mid-test', () => { notNull: false, pos: 11, }, + uuid: { + characterMaximumLength: null, + dataType: 'uuid', + dflt: null, + notNull: false, + pos: 12, + }, ['_0_version']: { characterMaximumLength: null, dataType: 'TEXT', diff --git a/packages/zero-cache/src/types/lite.ts b/packages/zero-cache/src/types/lite.ts index d64cddcbc..4afade588 100644 --- a/packages/zero-cache/src/types/lite.ts +++ b/packages/zero-cache/src/types/lite.ts @@ -152,6 +152,7 @@ export function dataTypeToZqlValueType( case 'character': case 'character varying': case 'text': + case 'uuid': case 'varchar': return 'string';