@powersync/service-module-postgres 0.0.0-dev-20241128134723 → 0.0.0-dev-20241210162153

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,10 +8,11 @@ import * as pgwire from '@powersync/service-jpgwire';
8
8
  import { SqliteRow } from '@powersync/service-sync-rules';
9
9
 
10
10
  import { mapOpEntry, MongoBucketStorage } from '@/storage/storage-index.js';
11
- import { reduceBucket, validateCompactedBucket } from '@core-tests/bucket_validation.js';
11
+ import { validateCompactedBucket } from '@core-tests/bucket_validation.js';
12
12
  import { MONGO_STORAGE_FACTORY, StorageFactory } from '@core-tests/util.js';
13
13
  import { PgManager } from '@module/replication/PgManager.js';
14
14
  import * as timers from 'node:timers/promises';
15
+ import { reduceBucket } from '@powersync/service-core';
15
16
 
16
17
  describe('slow tests - mongodb', function () {
17
18
  // These are slow, inconsistent tests.
package/test/src/util.ts CHANGED
@@ -6,6 +6,7 @@ import { BucketStorageFactory, Metrics, MongoBucketStorage, OpId } from '@powers
6
6
  import * as pgwire from '@powersync/service-jpgwire';
7
7
  import { pgwireRows } from '@powersync/service-jpgwire';
8
8
  import { env } from './env.js';
9
+ import { PostgresRouteAPIAdapter } from '@module/api/PostgresRouteAPIAdapter.js';
9
10
 
10
11
  // The metrics need to be initialized before they can be used
11
12
  await Metrics.initialise({
@@ -82,7 +83,8 @@ export async function getClientCheckpoint(
82
83
  ): Promise<OpId> {
83
84
  const start = Date.now();
84
85
 
85
- const [{ lsn }] = pgwireRows(await db.query(`SELECT pg_logical_emit_message(false, 'powersync', 'ping') as lsn`));
86
+ const api = new PostgresRouteAPIAdapter(db);
87
+ const lsn = await api.getReplicationHead();
86
88
 
87
89
  // This old API needs a persisted checkpoint id.
88
90
  // Since we don't use LSNs anymore, the only way to get that is to wait.
@@ -1,17 +1,15 @@
1
1
  import { MONGO_STORAGE_FACTORY } from '@core-tests/util.js';
2
- import { expect, test } from 'vitest';
3
- import { walStreamTest } from './wal_stream_utils.js';
4
2
  import { getDebugTablesInfo } from '@module/replication/replication-utils.js';
3
+ import { expect, test } from 'vitest';
4
+ import { WalStreamTestContext } from './wal_stream_utils.js';
5
5
 
6
- // Not quite a walStreamTest, but it helps to manage the connection
7
- test(
8
- 'validate tables',
9
- walStreamTest(MONGO_STORAGE_FACTORY, async (context) => {
10
- const { pool } = context;
6
+ test('validate tables', async () => {
7
+ await using context = await WalStreamTestContext.open(MONGO_STORAGE_FACTORY);
8
+ const { pool } = context;
11
9
 
12
- await pool.query(`CREATE TABLE test_data(id uuid primary key default uuid_generate_v4(), description text)`);
10
+ await pool.query(`CREATE TABLE test_data(id uuid primary key default uuid_generate_v4(), description text)`);
13
11
 
14
- const syncRuleContent = `
12
+ const syncRuleContent = `
15
13
  bucket_definitions:
16
14
  global:
17
15
  data:
@@ -20,45 +18,44 @@ bucket_definitions:
20
18
  - SELECT * FROM "other%"
21
19
  `;
22
20
 
23
- const syncRules = await context.factory.updateSyncRules({ content: syncRuleContent });
21
+ const syncRules = await context.factory.updateSyncRules({ content: syncRuleContent });
24
22
 
25
- const tablePatterns = syncRules.parsed({ defaultSchema: 'public' }).sync_rules.getSourceTables();
26
- const tableInfo = await getDebugTablesInfo({
27
- db: pool,
28
- publicationName: context.publicationName,
29
- connectionTag: context.connectionTag,
30
- tablePatterns: tablePatterns,
31
- syncRules: syncRules.parsed({ defaultSchema: 'public' }).sync_rules
32
- });
33
- expect(tableInfo).toEqual([
34
- {
23
+ const tablePatterns = syncRules.parsed({ defaultSchema: 'public' }).sync_rules.getSourceTables();
24
+ const tableInfo = await getDebugTablesInfo({
25
+ db: pool,
26
+ publicationName: context.publicationName,
27
+ connectionTag: context.connectionTag,
28
+ tablePatterns: tablePatterns,
29
+ syncRules: syncRules.parsed({ defaultSchema: 'public' }).sync_rules
30
+ });
31
+ expect(tableInfo).toEqual([
32
+ {
33
+ schema: 'public',
34
+ pattern: 'test_data',
35
+ wildcard: false,
36
+ table: {
35
37
  schema: 'public',
36
- pattern: 'test_data',
37
- wildcard: false,
38
- table: {
39
- schema: 'public',
40
- name: 'test_data',
41
- replication_id: ['id'],
42
- pattern: undefined,
43
- data_queries: true,
44
- parameter_queries: false,
45
- errors: []
46
- }
47
- },
48
- {
38
+ name: 'test_data',
39
+ replication_id: ['id'],
40
+ pattern: undefined,
41
+ data_queries: true,
42
+ parameter_queries: false,
43
+ errors: []
44
+ }
45
+ },
46
+ {
47
+ schema: 'public',
48
+ pattern: 'other',
49
+ wildcard: false,
50
+ table: {
49
51
  schema: 'public',
50
- pattern: 'other',
51
- wildcard: false,
52
- table: {
53
- schema: 'public',
54
- name: 'other',
55
- replication_id: [],
56
- data_queries: true,
57
- parameter_queries: false,
58
- errors: [{ level: 'warning', message: 'Table "public"."other" not found.' }]
59
- }
60
- },
61
- { schema: 'public', pattern: 'other%', wildcard: true, tables: [] }
62
- ]);
63
- })
64
- );
52
+ name: 'other',
53
+ replication_id: [],
54
+ data_queries: true,
55
+ parameter_queries: false,
56
+ errors: [{ level: 'warning', message: 'Table "public"."other" not found.' }]
57
+ }
58
+ },
59
+ { schema: 'public', pattern: 'other%', wildcard: true, tables: [] }
60
+ ]);
61
+ });