@powersync/service-module-postgres 0.0.4 → 0.1.0
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.
- package/CHANGELOG.md +17 -0
- package/dist/api/PostgresRouteAPIAdapter.d.ts +6 -2
- package/dist/api/PostgresRouteAPIAdapter.js +24 -10
- package/dist/api/PostgresRouteAPIAdapter.js.map +1 -1
- package/dist/module/PostgresModule.js +9 -2
- package/dist/module/PostgresModule.js.map +1 -1
- package/dist/replication/PgManager.js +5 -1
- package/dist/replication/PgManager.js.map +1 -1
- package/dist/replication/WalStream.d.ts +9 -2
- package/dist/replication/WalStream.js +120 -114
- package/dist/replication/WalStream.js.map +1 -1
- package/package.json +4 -4
- package/src/api/PostgresRouteAPIAdapter.ts +31 -12
- package/src/module/PostgresModule.ts +11 -2
- package/src/replication/PgManager.ts +5 -1
- package/src/replication/WalStream.ts +136 -125
- package/test/src/large_batch.test.ts +268 -148
- package/test/src/schema_changes.test.ts +562 -513
- package/test/src/slow_tests.test.ts +2 -1
- package/test/src/util.ts +3 -1
- package/test/src/validation.test.ts +45 -48
- package/test/src/wal_stream.test.ts +224 -249
- package/test/src/wal_stream_utils.ts +61 -22
- package/tsconfig.tsbuildinfo +1 -1
- package/test/src/__snapshots__/pg_test.test.ts.snap +0 -256
|
@@ -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 {
|
|
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
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
10
|
+
await pool.query(`CREATE TABLE test_data(id uuid primary key default uuid_generate_v4(), description text)`);
|
|
13
11
|
|
|
14
|
-
|
|
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
|
-
|
|
21
|
+
const syncRules = await context.factory.updateSyncRules({ content: syncRuleContent });
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
+
});
|