Skip to content

Commit ac5db39

Browse files
committed
Add test for changing schema
1 parent c3645ff commit ac5db39

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

modules/module-postgres/src/replication/WalStream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ WHERE oid = $1::regclass`,
711711
await batch.drop(result.dropTables);
712712

713713
// Ensure we have a description for custom types referenced in the table.
714-
//await this.connections.types.fetchTypes(referencedTypeIds);
714+
await this.connections.types.fetchTypes(referencedTypeIds);
715715

716716
// Snapshot if:
717717
// 1. Snapshot is requested (false for initial snapshot, since that process handles it elsewhere)

modules/module-postgres/test/src/schema_changes.test.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { compareIds, putOp, reduceBucket, removeOp, test_utils } from '@powersync/service-core-tests';
22
import * as timers from 'timers/promises';
3-
import { describe, expect, test, it } from 'vitest';
3+
import { describe, expect, test } from 'vitest';
44

55
import { storage } from '@powersync/service-core';
66
import { describeWithStorage } from './util.js';
@@ -591,23 +591,35 @@ function defineTests(factory: storage.TestStorageFactory) {
591591
expect(failures).toEqual([]);
592592
});
593593

594-
it.skip('custom types', async () => {
594+
test('custom types', async () => {
595595
await using context = await WalStreamTestContext.open(factory);
596596

597597
await context.updateSyncRules(`
598598
streams:
599599
stream:
600-
query: SELECT id, * FROM "test_data"
600+
query: SELECT * FROM "test_data"
601601
602602
config:
603603
edition: 2
604604
`);
605605

606606
const { pool } = context;
607-
await pool.query(`DROP TABLE IF EXISTS test_data`);
608-
await pool.query(`CREATE TABLE test_data(id text primary key, description composite);`);
609-
await pool.query(`INSERT INTO test_data(id, description) VALUES ('t1', ROW(TRUE, 2)::composite)`);
607+
await pool.query(`CREATE TABLE test_data(id text primary key);`);
608+
await pool.query(`INSERT INTO test_data(id) VALUES ('t1')`);
610609

611610
await context.replicateSnapshot();
611+
context.startStreaming();
612+
613+
await pool.query(
614+
{ statement: `CREATE TYPE composite AS (foo bool, bar int4);` },
615+
{ statement: `ALTER TABLE test_data ADD COLUMN other composite;` },
616+
{ statement: `UPDATE test_data SET other = ROW(TRUE, 2)::composite;` }
617+
);
618+
619+
const data = await context.getBucketData('1#stream|0[]');
620+
expect(data).toMatchObject([
621+
putOp('test_data', { id: 't1' }),
622+
putOp('test_data', { id: 't1', other: '{"foo":1,"bar":2}' })
623+
]);
612624
});
613625
}

modules/module-postgres/test/src/wal_stream.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { METRICS_HELPER, putOp, removeOp } from '@powersync/service-core-tests';
44
import { pgwireRows } from '@powersync/service-jpgwire';
55
import { ReplicationMetric } from '@powersync/service-types';
66
import * as crypto from 'crypto';
7-
import { describe, expect, test, it } from 'vitest';
7+
import { describe, expect, test } from 'vitest';
88
import { describeWithStorage } from './util.js';
99
import { WalStreamTestContext } from './wal_stream_utils.js';
1010

@@ -325,7 +325,7 @@ bucket_definitions:
325325
}
326326
});
327327

328-
it.skip('custom types', async () => {
328+
test('custom types', async () => {
329329
await using context = await WalStreamTestContext.open(factory);
330330

331331
await context.updateSyncRules(`
@@ -346,6 +346,6 @@ config:
346346
await pool.query(`INSERT INTO test_data(id, description) VALUES ('t1', ROW(TRUE, 2)::composite)`);
347347

348348
const data = await context.getBucketData('1#stream|0[]');
349-
expect(data).toMatchObject([putOp('test_data', { id: 't1', description: 'test1' })]);
349+
expect(data).toMatchObject([putOp('test_data', { id: 't1', description: '{"foo":1,"bar":2}' })]);
350350
});
351351
}

0 commit comments

Comments
 (0)