@powersync/service-module-postgres-storage 0.0.0-dev-20260225093637 → 0.0.0-dev-20260313100403
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 +53 -8
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/migrations/scripts/1771424826685-current-data-pending-deletes.d.ts +3 -0
- package/dist/@types/migrations/scripts/1771491856000-sync-plan.d.ts +3 -0
- package/dist/@types/storage/PostgresBucketStorageFactory.d.ts +4 -0
- package/dist/@types/storage/PostgresCompactor.d.ts +8 -2
- package/dist/@types/storage/PostgresReportStorage.d.ts +3 -3
- package/dist/@types/storage/PostgresSyncRulesStorage.d.ts +10 -4
- package/dist/@types/storage/batch/OperationBatch.d.ts +2 -2
- package/dist/@types/storage/batch/PostgresBucketBatch.d.ts +13 -9
- package/dist/@types/storage/batch/PostgresPersistedBatch.d.ts +17 -5
- package/dist/@types/storage/current-data-store.d.ts +85 -0
- package/dist/@types/storage/current-data-table.d.ts +9 -0
- package/dist/@types/storage/table-id.d.ts +2 -0
- package/dist/@types/types/models/CurrentData.d.ts +18 -3
- package/dist/@types/types/models/SyncRules.d.ts +9 -0
- package/dist/@types/types/models/json.d.ts +11 -0
- package/dist/@types/utils/bson.d.ts +1 -1
- package/dist/@types/utils/test-utils.d.ts +1 -1
- package/dist/migrations/scripts/1771424826685-current-data-pending-deletes.js +8 -0
- package/dist/migrations/scripts/1771424826685-current-data-pending-deletes.js.map +1 -0
- package/dist/migrations/scripts/1771491856000-sync-plan.js +91 -0
- package/dist/migrations/scripts/1771491856000-sync-plan.js.map +1 -0
- package/dist/storage/PostgresBucketStorageFactory.js +50 -5
- package/dist/storage/PostgresBucketStorageFactory.js.map +1 -1
- package/dist/storage/PostgresCompactor.js +14 -6
- package/dist/storage/PostgresCompactor.js.map +1 -1
- package/dist/storage/PostgresReportStorage.js +7 -7
- package/dist/storage/PostgresReportStorage.js.map +1 -1
- package/dist/storage/PostgresSyncRulesStorage.js +98 -24
- package/dist/storage/PostgresSyncRulesStorage.js.map +1 -1
- package/dist/storage/batch/OperationBatch.js +2 -1
- package/dist/storage/batch/OperationBatch.js.map +1 -1
- package/dist/storage/batch/PostgresBucketBatch.js +295 -213
- package/dist/storage/batch/PostgresBucketBatch.js.map +1 -1
- package/dist/storage/batch/PostgresPersistedBatch.js +86 -81
- package/dist/storage/batch/PostgresPersistedBatch.js.map +1 -1
- package/dist/storage/current-data-store.js +270 -0
- package/dist/storage/current-data-store.js.map +1 -0
- package/dist/storage/current-data-table.js +22 -0
- package/dist/storage/current-data-table.js.map +1 -0
- package/dist/storage/sync-rules/PostgresPersistedSyncRulesContent.js +1 -0
- package/dist/storage/sync-rules/PostgresPersistedSyncRulesContent.js.map +1 -1
- package/dist/storage/table-id.js +8 -0
- package/dist/storage/table-id.js.map +1 -0
- package/dist/types/models/CurrentData.js +11 -2
- package/dist/types/models/CurrentData.js.map +1 -1
- package/dist/types/models/SyncRules.js +11 -1
- package/dist/types/models/SyncRules.js.map +1 -1
- package/dist/types/models/json.js +21 -0
- package/dist/types/models/json.js.map +1 -0
- package/dist/utils/bson.js.map +1 -1
- package/dist/utils/db.js +9 -0
- package/dist/utils/db.js.map +1 -1
- package/dist/utils/test-utils.js +13 -6
- package/dist/utils/test-utils.js.map +1 -1
- package/package.json +9 -9
- package/src/migrations/scripts/1771424826685-current-data-pending-deletes.ts +10 -0
- package/src/migrations/scripts/1771491856000-sync-plan.ts +21 -0
- package/src/storage/PostgresBucketStorageFactory.ts +62 -7
- package/src/storage/PostgresCompactor.ts +17 -8
- package/src/storage/PostgresReportStorage.ts +7 -7
- package/src/storage/PostgresSyncRulesStorage.ts +47 -31
- package/src/storage/batch/OperationBatch.ts +4 -3
- package/src/storage/batch/PostgresBucketBatch.ts +316 -238
- package/src/storage/batch/PostgresPersistedBatch.ts +92 -84
- package/src/storage/current-data-store.ts +326 -0
- package/src/storage/current-data-table.ts +26 -0
- package/src/storage/sync-rules/PostgresPersistedSyncRulesContent.ts +1 -7
- package/src/storage/table-id.ts +9 -0
- package/src/types/models/CurrentData.ts +17 -4
- package/src/types/models/SyncRules.ts +15 -1
- package/src/types/models/json.ts +26 -0
- package/src/utils/bson.ts +1 -1
- package/src/utils/db.ts +10 -0
- package/src/utils/test-utils.ts +14 -7
- package/test/src/__snapshots__/{connection-report-storage.test.ts.snap → client-connections-storage.test.ts.snap} +22 -22
- package/test/src/__snapshots__/storage.test.ts.snap +151 -0
- package/test/src/__snapshots__/storage_compacting.test.ts.snap +17 -0
- package/test/src/__snapshots__/storage_sync.test.ts.snap +1111 -16
- package/test/src/{connection-report-storage.test.ts → client-connections-storage.test.ts} +1 -1
- package/test/src/env.ts +1 -1
- package/test/src/migrations.test.ts +1 -1
- package/test/src/storage.test.ts +138 -131
- package/test/src/storage_compacting.test.ts +80 -11
- package/test/src/storage_sync.test.ts +57 -54
- package/test/src/util.ts +4 -4
|
@@ -20,6 +20,10 @@ export declare class PostgresBucketStorageFactory extends storage.BucketStorageF
|
|
|
20
20
|
getPowerSyncInstanceId(): Promise<string>;
|
|
21
21
|
getSystemIdentifier(): Promise<storage.BucketStorageSystemIdentifier>;
|
|
22
22
|
updateSyncRules(options: storage.UpdateSyncRulesOptions): Promise<PostgresPersistedSyncRulesContent>;
|
|
23
|
+
/**
|
|
24
|
+
* Lazy-initializes storage-version-specific structures, if needed.
|
|
25
|
+
*/
|
|
26
|
+
private initializeStorageVersion;
|
|
23
27
|
restartReplication(sync_rules_group_id: number): Promise<void>;
|
|
24
28
|
getActiveSyncRulesContent(): Promise<storage.PersistedSyncRulesContent | null>;
|
|
25
29
|
getNextSyncRulesContent(): Promise<storage.PersistedSyncRulesContent | null>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
2
|
-
import { storage } from '@powersync/service-core';
|
|
2
|
+
import { InternalOpId, storage } from '@powersync/service-core';
|
|
3
3
|
/**
|
|
4
4
|
* Additional options, primarily for testing.
|
|
5
5
|
*/
|
|
@@ -15,7 +15,7 @@ export declare class PostgresCompactor {
|
|
|
15
15
|
private clearBatchLimit;
|
|
16
16
|
private maxOpId;
|
|
17
17
|
private buckets;
|
|
18
|
-
constructor(db: lib_postgres.DatabaseClient, group_id: number, options
|
|
18
|
+
constructor(db: lib_postgres.DatabaseClient, group_id: number, options: PostgresCompactOptions);
|
|
19
19
|
/**
|
|
20
20
|
* Compact buckets by converting operations into MOVE and/or CLEAR operations.
|
|
21
21
|
*
|
|
@@ -25,6 +25,12 @@ export declare class PostgresCompactor {
|
|
|
25
25
|
private compactAllBuckets;
|
|
26
26
|
private compactSingleBucket;
|
|
27
27
|
private flush;
|
|
28
|
+
/**
|
|
29
|
+
* Expose the internal clearBucket() method to tests.
|
|
30
|
+
*
|
|
31
|
+
* @deprecated Only for tests
|
|
32
|
+
*/
|
|
33
|
+
clearBucketForTests(bucket: string, op: InternalOpId): Promise<void>;
|
|
28
34
|
/**
|
|
29
35
|
* Perform a CLEAR compact for a bucket.
|
|
30
36
|
*
|
|
@@ -17,9 +17,9 @@ export declare class PostgresReportStorage implements storage.ReportStorage {
|
|
|
17
17
|
private clientsConnectionPagination;
|
|
18
18
|
reportClientConnection(data: event_types.ClientConnectionBucketData): Promise<void>;
|
|
19
19
|
reportClientDisconnection(data: event_types.ClientDisconnectionEventData): Promise<void>;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
getCurrentConnections(): Promise<event_types.ClientConnectionReportResponse>;
|
|
21
|
+
getClientConnectionsSummary(data: event_types.ClientConnectionReportRequest): Promise<event_types.ClientConnectionReportResponse>;
|
|
22
|
+
getClientSessions(data: event_types.ClientConnectionAnalyticsRequest): Promise<event_types.PaginatedResponse<event_types.ClientConnection>>;
|
|
23
23
|
deleteOldConnectionData(data: event_types.DeleteOldConnectionData): Promise<void>;
|
|
24
24
|
[Symbol.asyncDispose](): Promise<void>;
|
|
25
25
|
prepareStatements(connection: pg_wire.PgConnection): Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
2
|
-
import { CheckpointChanges, GetCheckpointChangesOptions, InternalOpId, PopulateChecksumCacheOptions, PopulateChecksumCacheResults, ReplicationCheckpoint, storage, utils, WatchWriteCheckpointOptions } from '@powersync/service-core';
|
|
2
|
+
import { CheckpointChanges, GetCheckpointChangesOptions, InternalOpId, PopulateChecksumCacheOptions, PopulateChecksumCacheResults, ReplicationCheckpoint, storage, StorageVersionConfig, utils, WatchWriteCheckpointOptions } from '@powersync/service-core';
|
|
3
3
|
import * as sync_rules from '@powersync/service-sync-rules';
|
|
4
4
|
import { RequiredOperationBatchLimits } from '../types/types.js';
|
|
5
5
|
import * as framework from '@powersync/lib-services-framework';
|
|
@@ -18,9 +18,11 @@ export declare class PostgresSyncRulesStorage extends framework.BaseObserver<sto
|
|
|
18
18
|
readonly sync_rules: storage.PersistedSyncRulesContent;
|
|
19
19
|
readonly slot_name: string;
|
|
20
20
|
readonly factory: PostgresBucketStorageFactory;
|
|
21
|
+
readonly storageConfig: StorageVersionConfig;
|
|
21
22
|
private sharedIterator;
|
|
22
23
|
protected db: lib_postgres.DatabaseClient;
|
|
23
24
|
protected writeCheckpointAPI: PostgresWriteCheckpointAPI;
|
|
25
|
+
private readonly currentDataStore;
|
|
24
26
|
private parsedSyncRulesCache;
|
|
25
27
|
private _checksumCache;
|
|
26
28
|
constructor(options: PostgresSyncRulesStorageOptions);
|
|
@@ -40,10 +42,14 @@ export declare class PostgresSyncRulesStorage extends framework.BaseObserver<sto
|
|
|
40
42
|
createManagedWriteCheckpoint(checkpoint: storage.ManagedWriteCheckpointOptions): Promise<bigint>;
|
|
41
43
|
getCheckpoint(): Promise<storage.ReplicationCheckpoint>;
|
|
42
44
|
resolveTable(options: storage.ResolveTableOptions): Promise<storage.ResolveTableResult>;
|
|
43
|
-
|
|
45
|
+
createWriter(options: storage.CreateWriterOptions): Promise<storage.BucketStorageBatch>;
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Use `createWriter()` with `await using` instead.
|
|
48
|
+
*/
|
|
49
|
+
startBatch(options: storage.CreateWriterOptions, callback: (batch: storage.BucketStorageBatch) => Promise<void>): Promise<storage.FlushedResult | null>;
|
|
44
50
|
getParameterSets(checkpoint: ReplicationCheckpoint, lookups: sync_rules.ScopedParameterLookup[]): Promise<sync_rules.SqliteJsonRow[]>;
|
|
45
|
-
getBucketDataBatch(checkpoint: InternalOpId, dataBuckets:
|
|
46
|
-
getChecksums(checkpoint: utils.InternalOpId, buckets:
|
|
51
|
+
getBucketDataBatch(checkpoint: InternalOpId, dataBuckets: storage.BucketDataRequest[], options?: storage.BucketDataBatchOptions): AsyncIterable<storage.SyncBucketDataChunk>;
|
|
52
|
+
getChecksums(checkpoint: utils.InternalOpId, buckets: storage.BucketChecksumRequest[]): Promise<utils.ChecksumMap>;
|
|
47
53
|
clearChecksumCache(): void;
|
|
48
54
|
terminate(options?: storage.TerminateOptions): Promise<void>;
|
|
49
55
|
getStatus(): Promise<storage.SyncRuleStatus>;
|
|
@@ -40,8 +40,8 @@ export declare class RecordOperation {
|
|
|
40
40
|
/**
|
|
41
41
|
* In-memory cache key - must not be persisted.
|
|
42
42
|
*/
|
|
43
|
-
export declare function cacheKey(sourceTableId:
|
|
43
|
+
export declare function cacheKey(sourceTableId: storage.SourceTableId, id: storage.ReplicaId): string;
|
|
44
44
|
/**
|
|
45
45
|
* Calculates a cache key for a stored ReplicaId. This is usually stored as a bytea/Buffer.
|
|
46
46
|
*/
|
|
47
|
-
export declare function encodedCacheKey(sourceTableId:
|
|
47
|
+
export declare function encodedCacheKey(sourceTableId: storage.SourceTableId, storedKey: Buffer): string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
2
2
|
import { BaseObserver, Logger } from '@powersync/lib-services-framework';
|
|
3
|
-
import { BucketStorageMarkRecordUnavailable, InternalOpId, storage } from '@powersync/service-core';
|
|
3
|
+
import { BucketStorageMarkRecordUnavailable, CheckpointResult, InternalOpId, storage } from '@powersync/service-core';
|
|
4
4
|
import * as sync_rules from '@powersync/service-sync-rules';
|
|
5
5
|
import * as t from 'ts-codec';
|
|
6
|
-
import {
|
|
6
|
+
import { V3CurrentDataDecoded } from '../../types/models/CurrentData.js';
|
|
7
7
|
import { RequiredOperationBatchLimits } from '../../types/types.js';
|
|
8
8
|
import { OperationBatch, RecordOperation } from './OperationBatch.js';
|
|
9
9
|
import { PostgresPersistedBatch } from './PostgresPersistedBatch.js';
|
|
@@ -14,7 +14,6 @@ export interface PostgresBucketBatchOptions {
|
|
|
14
14
|
group_id: number;
|
|
15
15
|
slot_name: string;
|
|
16
16
|
last_checkpoint_lsn: string | null;
|
|
17
|
-
no_checkpoint_before_lsn: string;
|
|
18
17
|
store_current_data: boolean;
|
|
19
18
|
keep_alive_op?: InternalOpId | null;
|
|
20
19
|
resumeFromLsn: string | null;
|
|
@@ -24,6 +23,7 @@ export interface PostgresBucketBatchOptions {
|
|
|
24
23
|
skip_existing_rows: boolean;
|
|
25
24
|
batch_limits: RequiredOperationBatchLimits;
|
|
26
25
|
markRecordUnavailable: BucketStorageMarkRecordUnavailable | undefined;
|
|
26
|
+
storageConfig: storage.StorageVersionConfig;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Intermediate type which helps for only watching the active sync rules
|
|
@@ -49,7 +49,6 @@ export declare class PostgresBucketBatch extends BaseObserver<storage.BucketBatc
|
|
|
49
49
|
protected db: lib_postgres.DatabaseClient;
|
|
50
50
|
protected group_id: number;
|
|
51
51
|
protected last_checkpoint_lsn: string | null;
|
|
52
|
-
protected no_checkpoint_before_lsn: string;
|
|
53
52
|
protected persisted_op: InternalOpId | null;
|
|
54
53
|
protected write_checkpoint_batch: storage.CustomWriteCheckpointOptions[];
|
|
55
54
|
protected readonly sync_rules: sync_rules.HydratedSyncRules;
|
|
@@ -58,24 +57,28 @@ export declare class PostgresBucketBatch extends BaseObserver<storage.BucketBatc
|
|
|
58
57
|
private markRecordUnavailable;
|
|
59
58
|
private needsActivation;
|
|
60
59
|
private clearedError;
|
|
60
|
+
private readonly storageConfig;
|
|
61
|
+
private readonly currentDataStore;
|
|
61
62
|
constructor(options: PostgresBucketBatchOptions);
|
|
62
63
|
get lastCheckpointLsn(): string | null;
|
|
63
|
-
get noCheckpointBeforeLsn(): string;
|
|
64
64
|
[Symbol.asyncDispose](): Promise<void>;
|
|
65
|
+
dispose(): Promise<void>;
|
|
65
66
|
save(record: storage.SaveOptions): Promise<storage.FlushedResult | null>;
|
|
66
67
|
truncate(sourceTables: storage.SourceTable[]): Promise<storage.FlushedResult | null>;
|
|
67
68
|
protected truncateSingle(sourceTable: storage.SourceTable): Promise<bigint | null>;
|
|
68
69
|
drop(sourceTables: storage.SourceTable[]): Promise<storage.FlushedResult | null>;
|
|
69
70
|
flush(): Promise<storage.FlushedResult | null>;
|
|
70
71
|
private flushInner;
|
|
71
|
-
commit(lsn: string, options?: storage.BucketBatchCommitOptions): Promise<
|
|
72
|
-
keepalive(lsn: string): Promise<
|
|
72
|
+
commit(lsn: string, options?: storage.BucketBatchCommitOptions): Promise<CheckpointResult>;
|
|
73
|
+
keepalive(lsn: string): Promise<CheckpointResult>;
|
|
73
74
|
setResumeLsn(lsn: string): Promise<void>;
|
|
74
|
-
|
|
75
|
+
markAllSnapshotDone(no_checkpoint_before_lsn: string): Promise<void>;
|
|
76
|
+
markTableSnapshotRequired(table: storage.SourceTable): Promise<void>;
|
|
77
|
+
markTableSnapshotDone(tables: storage.SourceTable[], no_checkpoint_before_lsn?: string): Promise<storage.SourceTable[]>;
|
|
75
78
|
updateTableProgress(table: storage.SourceTable, progress: Partial<storage.TableSnapshotStatus>): Promise<storage.SourceTable>;
|
|
76
79
|
addCustomWriteCheckpoint(checkpoint: storage.BatchedCustomWriteCheckpointOptions): void;
|
|
77
80
|
protected replicateBatch(db: lib_postgres.WrappedConnection, batch: OperationBatch): Promise<OperationBatch | null>;
|
|
78
|
-
protected saveOperation(persistedBatch: PostgresPersistedBatch, operation: RecordOperation, currentData?:
|
|
81
|
+
protected saveOperation(persistedBatch: PostgresPersistedBatch, operation: RecordOperation, currentData?: V3CurrentDataDecoded | null): Promise<{
|
|
79
82
|
group_id: number;
|
|
80
83
|
source_table: string;
|
|
81
84
|
source_key: Buffer<ArrayBuffer>;
|
|
@@ -86,6 +89,7 @@ export declare class PostgresBucketBatch extends BaseObserver<storage.BucketBatc
|
|
|
86
89
|
table: string;
|
|
87
90
|
}[];
|
|
88
91
|
lookups: Buffer<ArrayBuffer>[];
|
|
92
|
+
pending_delete: bigint | null;
|
|
89
93
|
} | null>;
|
|
90
94
|
/**
|
|
91
95
|
* Switch from processing -> active if relevant.
|
|
@@ -18,7 +18,7 @@ export type SaveParameterDataOptions = {
|
|
|
18
18
|
existing_lookups: Buffer[];
|
|
19
19
|
};
|
|
20
20
|
export type DeleteCurrentDataOptions = {
|
|
21
|
-
source_table_id:
|
|
21
|
+
source_table_id: string;
|
|
22
22
|
/**
|
|
23
23
|
* ReplicaID which needs to be serialized in order to be queried
|
|
24
24
|
* or inserted into the DB
|
|
@@ -28,12 +28,19 @@ export type DeleteCurrentDataOptions = {
|
|
|
28
28
|
* Optionally provide the serialized source key directly
|
|
29
29
|
*/
|
|
30
30
|
serialized_source_key?: Buffer;
|
|
31
|
+
/**
|
|
32
|
+
* Streaming replication needs soft deletes, while truncating tables can use a hard delete directly.
|
|
33
|
+
*/
|
|
34
|
+
soft: boolean;
|
|
31
35
|
};
|
|
32
36
|
export type PostgresPersistedBatchOptions = RequiredOperationBatchLimits & {
|
|
33
37
|
group_id: number;
|
|
38
|
+
storageConfig: storage.StorageVersionConfig;
|
|
34
39
|
};
|
|
35
40
|
export declare class PostgresPersistedBatch {
|
|
36
41
|
group_id: number;
|
|
42
|
+
private readonly storageConfig;
|
|
43
|
+
private readonly currentDataStore;
|
|
37
44
|
/**
|
|
38
45
|
* Very rough estimate of current operations size in bytes
|
|
39
46
|
*/
|
|
@@ -45,16 +52,21 @@ export declare class PostgresPersistedBatch {
|
|
|
45
52
|
*/
|
|
46
53
|
protected bucketDataInserts: models.BucketData[];
|
|
47
54
|
protected parameterDataInserts: models.BucketParameters[];
|
|
48
|
-
protected currentDataDeletes: Pick<models.CurrentData, 'group_id' | 'source_key' | 'source_table'>[];
|
|
49
55
|
/**
|
|
50
|
-
* This is stored as a map to avoid multiple inserts (or conflicts) for the same key
|
|
56
|
+
* This is stored as a map to avoid multiple inserts (or conflicts) for the same key.
|
|
57
|
+
*
|
|
58
|
+
* Each key may only occur in one of these two maps.
|
|
51
59
|
*/
|
|
52
|
-
protected currentDataInserts: Map<string, models.
|
|
60
|
+
protected currentDataInserts: Map<string, models.V3CurrentData>;
|
|
61
|
+
protected currentDataDeletes: Map<string, {
|
|
62
|
+
source_key_hex: string;
|
|
63
|
+
source_table: string;
|
|
64
|
+
}>;
|
|
53
65
|
constructor(options: PostgresPersistedBatchOptions);
|
|
54
66
|
saveBucketData(options: SaveBucketDataOptions): void;
|
|
55
67
|
saveParameterData(options: SaveParameterDataOptions): void;
|
|
56
68
|
deleteCurrentData(options: DeleteCurrentDataOptions): void;
|
|
57
|
-
upsertCurrentData(options: models.
|
|
69
|
+
upsertCurrentData(options: models.V3CurrentDataDecoded, serialized_source_key?: Buffer): void;
|
|
58
70
|
shouldFlushTransaction(): boolean;
|
|
59
71
|
flush(db: lib_postgres.WrappedConnection): Promise<{
|
|
60
72
|
flushedAny: boolean;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
2
|
+
import { storage } from '@powersync/service-core';
|
|
3
|
+
import * as t from 'ts-codec';
|
|
4
|
+
import * as models from '../types/models/CurrentData.js';
|
|
5
|
+
type Queryable = Pick<lib_postgres.DatabaseClient, 'sql' | 'streamRows'>;
|
|
6
|
+
declare const TruncateCurrentDataCodec: t.ObjectCodec<Pick<{
|
|
7
|
+
buckets: t.Codec<{
|
|
8
|
+
id: string;
|
|
9
|
+
bucket: string;
|
|
10
|
+
table: string;
|
|
11
|
+
}[], string, string, t.CodecProps>;
|
|
12
|
+
data: t.Codec<Buffer<ArrayBuffer>, string, "hexBuffer", t.CodecProps>;
|
|
13
|
+
group_id: t.Codec<number, number, "pg_number", t.CodecProps>;
|
|
14
|
+
lookups: t.ArrayCodec<t.Codec<Buffer<ArrayBuffer>, string, "hexBuffer", t.CodecProps>>;
|
|
15
|
+
source_key: t.Codec<Buffer<ArrayBuffer>, string, "hexBuffer", t.CodecProps>;
|
|
16
|
+
source_table: t.IdentityCodec<t.CodecType.String>;
|
|
17
|
+
}, "source_key" | "buckets" | "lookups">>;
|
|
18
|
+
declare const LookupKeyCodec: t.ObjectCodec<Pick<{
|
|
19
|
+
buckets: t.Codec<{
|
|
20
|
+
id: string;
|
|
21
|
+
bucket: string;
|
|
22
|
+
table: string;
|
|
23
|
+
}[], string, string, t.CodecProps>;
|
|
24
|
+
data: t.Codec<Buffer<ArrayBuffer>, string, "hexBuffer", t.CodecProps>;
|
|
25
|
+
group_id: t.Codec<number, number, "pg_number", t.CodecProps>;
|
|
26
|
+
lookups: t.ArrayCodec<t.Codec<Buffer<ArrayBuffer>, string, "hexBuffer", t.CodecProps>>;
|
|
27
|
+
source_key: t.Codec<Buffer<ArrayBuffer>, string, "hexBuffer", t.CodecProps>;
|
|
28
|
+
source_table: t.IdentityCodec<t.CodecType.String>;
|
|
29
|
+
}, "source_table" | "source_key">>;
|
|
30
|
+
export type TruncateCurrentDataRow = t.Decoded<typeof TruncateCurrentDataCodec>;
|
|
31
|
+
export type CurrentDataLookupRow = t.Decoded<typeof LookupKeyCodec> | t.Decoded<typeof models.V1CurrentData> | t.Decoded<typeof models.V3CurrentData>;
|
|
32
|
+
export declare const V1_CURRENT_DATA_TABLE = "current_data";
|
|
33
|
+
export declare const V3_CURRENT_DATA_TABLE = "v3_current_data";
|
|
34
|
+
export declare class PostgresCurrentDataStore {
|
|
35
|
+
readonly table: string;
|
|
36
|
+
readonly softDeleteEnabled: boolean;
|
|
37
|
+
constructor(storageConfig: storage.StorageVersionConfig);
|
|
38
|
+
streamTruncateRows(db: Queryable, options: {
|
|
39
|
+
groupId: number;
|
|
40
|
+
sourceTableId: string;
|
|
41
|
+
limit: number;
|
|
42
|
+
}): AsyncIterableIterator<{
|
|
43
|
+
source_key: string;
|
|
44
|
+
buckets: string;
|
|
45
|
+
lookups: string[];
|
|
46
|
+
}[]>;
|
|
47
|
+
decodeTruncateRow(row: t.Encoded<typeof TruncateCurrentDataCodec>): TruncateCurrentDataRow;
|
|
48
|
+
streamSizeRows(db: Queryable, options: {
|
|
49
|
+
groupId: number;
|
|
50
|
+
lookups: {
|
|
51
|
+
source_table: string;
|
|
52
|
+
source_key: string;
|
|
53
|
+
}[];
|
|
54
|
+
}): AsyncIterableIterator<{
|
|
55
|
+
source_table: string;
|
|
56
|
+
source_key: storage.ReplicaId;
|
|
57
|
+
data_size: number;
|
|
58
|
+
}[]>;
|
|
59
|
+
streamLookupRows(db: Queryable, options: {
|
|
60
|
+
groupId: number;
|
|
61
|
+
lookups: {
|
|
62
|
+
source_table: string;
|
|
63
|
+
source_key: string;
|
|
64
|
+
}[];
|
|
65
|
+
skipExistingRows: boolean;
|
|
66
|
+
}): AsyncIterableIterator<any[]>;
|
|
67
|
+
decodeLookupRow(row: any, skipExistingRows: boolean): CurrentDataLookupRow;
|
|
68
|
+
flushUpserts(db: Queryable, updates: models.V3CurrentData[]): Promise<void>;
|
|
69
|
+
flushDeletes(db: Queryable, options: {
|
|
70
|
+
groupId: number;
|
|
71
|
+
deletes: {
|
|
72
|
+
source_key_hex: string;
|
|
73
|
+
source_table: string;
|
|
74
|
+
}[];
|
|
75
|
+
}): Promise<void>;
|
|
76
|
+
cleanupPendingDeletes(db: Queryable, options: {
|
|
77
|
+
groupId: number;
|
|
78
|
+
lastCheckpoint: bigint;
|
|
79
|
+
}): Promise<void>;
|
|
80
|
+
deleteGroupRows(db: Queryable, options: {
|
|
81
|
+
groupId: number;
|
|
82
|
+
}): Promise<void>;
|
|
83
|
+
private wherePendingDelete;
|
|
84
|
+
}
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { storage } from '@powersync/service-core';
|
|
2
|
+
export declare const V1_CURRENT_DATA_TABLE = "current_data";
|
|
3
|
+
export declare const V3_CURRENT_DATA_TABLE = "v3_current_data";
|
|
4
|
+
/**
|
|
5
|
+
* The table used by a specific storage version for general current_data access.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getCommonCurrentDataTable(storageConfig: storage.StorageVersionConfig): "current_data" | "v3_current_data";
|
|
8
|
+
export declare function getV1CurrentDataTable(storageConfig: storage.StorageVersionConfig): string;
|
|
9
|
+
export declare function getV3CurrentDataTable(storageConfig: storage.StorageVersionConfig): string;
|
|
@@ -6,7 +6,7 @@ export declare const CurrentBucket: t.ObjectCodec<{
|
|
|
6
6
|
}>;
|
|
7
7
|
export type CurrentBucket = t.Encoded<typeof CurrentBucket>;
|
|
8
8
|
export type CurrentBucketDecoded = t.Decoded<typeof CurrentBucket>;
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const V1CurrentData: t.ObjectCodec<{
|
|
10
10
|
buckets: t.Codec<{
|
|
11
11
|
id: string;
|
|
12
12
|
bucket: string;
|
|
@@ -18,5 +18,20 @@ export declare const CurrentData: t.ObjectCodec<{
|
|
|
18
18
|
source_key: t.Codec<Buffer<ArrayBuffer>, string, "hexBuffer", t.CodecProps>;
|
|
19
19
|
source_table: t.IdentityCodec<t.CodecType.String>;
|
|
20
20
|
}>;
|
|
21
|
-
export
|
|
22
|
-
|
|
21
|
+
export declare const V3CurrentData: t.ObjectCodec<{
|
|
22
|
+
buckets: t.Codec<{
|
|
23
|
+
id: string;
|
|
24
|
+
bucket: string;
|
|
25
|
+
table: string;
|
|
26
|
+
}[], string, string, t.CodecProps>;
|
|
27
|
+
data: t.Codec<Buffer<ArrayBuffer>, string, "hexBuffer", t.CodecProps>;
|
|
28
|
+
group_id: t.Codec<number, number, "pg_number", t.CodecProps>;
|
|
29
|
+
lookups: t.ArrayCodec<t.Codec<Buffer<ArrayBuffer>, string, "hexBuffer", t.CodecProps>>;
|
|
30
|
+
source_key: t.Codec<Buffer<ArrayBuffer>, string, "hexBuffer", t.CodecProps>;
|
|
31
|
+
source_table: t.IdentityCodec<t.CodecType.String>;
|
|
32
|
+
pending_delete: t.Union<t.Codec<null, null, string, t.CodecProps>, t.Codec<bigint, string | number, string, t.CodecProps>>;
|
|
33
|
+
}>;
|
|
34
|
+
export type V1CurrentData = t.Encoded<typeof V1CurrentData>;
|
|
35
|
+
export type V1CurrentDataDecoded = t.Decoded<typeof V1CurrentData>;
|
|
36
|
+
export type V3CurrentData = t.Encoded<typeof V3CurrentData>;
|
|
37
|
+
export type V3CurrentDataDecoded = t.Decoded<typeof V3CurrentData>;
|
|
@@ -47,6 +47,15 @@ export declare const SyncRules: t.ObjectCodec<{
|
|
|
47
47
|
keepalive_op: t.Union<t.Codec<null, null, string, t.CodecProps>, t.Codec<bigint, string | number, string, t.CodecProps>>;
|
|
48
48
|
storage_version: t.OptionalCodec<t.Codec<number | null, number | null, string, t.CodecProps>>;
|
|
49
49
|
content: t.IdentityCodec<t.CodecType.String>;
|
|
50
|
+
sync_plan: t.Union<t.Codec<null, null, string, t.CodecProps>, t.Codec<{
|
|
51
|
+
plan: any;
|
|
52
|
+
compatibility: {
|
|
53
|
+
edition: number;
|
|
54
|
+
overrides: Record<string, boolean>;
|
|
55
|
+
maxTimeValuePrecision?: number | undefined;
|
|
56
|
+
};
|
|
57
|
+
eventDescriptors: Record<string, string[]>;
|
|
58
|
+
}, import("@powersync/service-jsonbig").JsonContainer>>;
|
|
50
59
|
}>;
|
|
51
60
|
export type SyncRules = t.Encoded<typeof SyncRules>;
|
|
52
61
|
export type SyncRulesDecoded = t.Decoded<typeof SyncRules>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { JsonContainer } from '@powersync/service-jsonbig';
|
|
2
|
+
import { Codec } from 'ts-codec';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a codec to support {@link JsonContainer} values.
|
|
5
|
+
*
|
|
6
|
+
* Because our postgres client implementation wraps JSON objects in a {@link JsonContainer}, this intermediate layer is
|
|
7
|
+
* required to use JSON columns from Postgres in `ts-codec` models.
|
|
8
|
+
*
|
|
9
|
+
* Note that this serializes and deserializes values using {@link JSON}, so bigints are not supported.
|
|
10
|
+
*/
|
|
11
|
+
export declare function jsonContainerObject<I, O>(inner: Codec<I, O>): Codec<I, JsonContainer>;
|
|
@@ -3,4 +3,4 @@ import { storage } from '@powersync/service-core';
|
|
|
3
3
|
* BSON is used to serialize certain documents for storage in BYTEA columns.
|
|
4
4
|
* JSONB columns do not directly support storing binary data which could be required in future.
|
|
5
5
|
*/
|
|
6
|
-
export declare function replicaIdToSubkey(tableId:
|
|
6
|
+
export declare function replicaIdToSubkey(tableId: storage.SourceTableId, id: storage.ReplicaId): string;
|
|
@@ -15,5 +15,5 @@ export declare function postgresTestSetup(factoryOptions: PostgresTestStorageOpt
|
|
|
15
15
|
reportFactory: (options?: TestStorageOptions) => Promise<PostgresReportStorage>;
|
|
16
16
|
factory: (options?: TestStorageOptions) => Promise<PostgresBucketStorageFactory>;
|
|
17
17
|
migrate: (direction: framework.migrations.Direction) => Promise<void>;
|
|
18
|
+
tableIdStrings: boolean;
|
|
18
19
|
};
|
|
19
|
-
export declare function postgresTestStorageFactoryGenerator(factoryOptions: PostgresTestStorageOptions): (options?: TestStorageOptions) => Promise<PostgresBucketStorageFactory>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const up = async (_context) => {
|
|
2
|
+
// No-op.
|
|
3
|
+
// Pending-delete support is now storage-version specific and initialized when v3 sync rules are deployed.
|
|
4
|
+
};
|
|
5
|
+
export const down = async (_context) => {
|
|
6
|
+
// No-op.
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=1771424826685-current-data-pending-deletes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"1771424826685-current-data-pending-deletes.js","sourceRoot":"","sources":["../../../src/migrations/scripts/1771424826685-current-data-pending-deletes.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,EAAE,GAA0C,KAAK,EAAE,QAAQ,EAAE,EAAE;IAC1E,SAAS;IACT,0GAA0G;AAC5G,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAA0C,KAAK,EAAE,QAAQ,EAAE,EAAE;IAC5E,SAAS;AACX,CAAC,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
53
|
+
import { openMigrationDB } from '../migration-utils.js';
|
|
54
|
+
export const up = async (context) => {
|
|
55
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
56
|
+
try {
|
|
57
|
+
const { service_context: { configuration } } = context;
|
|
58
|
+
const client = __addDisposableResource(env_1, openMigrationDB(configuration.storage), true);
|
|
59
|
+
await client.sql `
|
|
60
|
+
ALTER TABLE sync_rules
|
|
61
|
+
ADD COLUMN sync_plan JSON;
|
|
62
|
+
`.execute();
|
|
63
|
+
}
|
|
64
|
+
catch (e_1) {
|
|
65
|
+
env_1.error = e_1;
|
|
66
|
+
env_1.hasError = true;
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
const result_1 = __disposeResources(env_1);
|
|
70
|
+
if (result_1)
|
|
71
|
+
await result_1;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
export const down = async (context) => {
|
|
75
|
+
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
76
|
+
try {
|
|
77
|
+
const { service_context: { configuration } } = context;
|
|
78
|
+
const client = __addDisposableResource(env_2, openMigrationDB(configuration.storage), true);
|
|
79
|
+
await client.sql `ALTER TABLE sync_rules DROP COLUMN sync_plan`.execute();
|
|
80
|
+
}
|
|
81
|
+
catch (e_2) {
|
|
82
|
+
env_2.error = e_2;
|
|
83
|
+
env_2.hasError = true;
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
const result_2 = __disposeResources(env_2);
|
|
87
|
+
if (result_2)
|
|
88
|
+
await result_2;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=1771491856000-sync-plan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"1771491856000-sync-plan.js","sourceRoot":"","sources":["../../../src/migrations/scripts/1771491856000-sync-plan.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,MAAM,EAAE,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;;;QACzE,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;QACZ,MAAY,MAAM,kCAAG,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,OAAA,CAAC;QAC5D,MAAM,MAAM,CAAC,GAAG,CAAA;;;GAGf,CAAC,OAAO,EAAE,CAAC;;;;;;;;;;;CACb,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;;;QAC3E,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;QACZ,MAAY,MAAM,kCAAG,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,OAAA,CAAC;QAC5D,MAAM,MAAM,CAAC,GAAG,CAAA,8CAA8C,CAAC,OAAO,EAAE,CAAC;;;;;;;;;;;CAC1E,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { storage } from '@powersync/service-core';
|
|
1
|
+
import { framework, storage } from '@powersync/service-core';
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import * as uuid from 'uuid';
|
|
4
4
|
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
5
5
|
import { models } from '../types/types.js';
|
|
6
|
+
import { getStorageApplicationName } from '../utils/application-name.js';
|
|
6
7
|
import { NOTIFICATION_CHANNEL, STORAGE_SCHEMA_NAME } from '../utils/db.js';
|
|
7
8
|
import { notifySyncRulesUpdate } from './batch/PostgresBucketBatch.js';
|
|
8
9
|
import { PostgresSyncRulesStorage } from './PostgresSyncRulesStorage.js';
|
|
9
10
|
import { PostgresPersistedSyncRulesContent } from './sync-rules/PostgresPersistedSyncRulesContent.js';
|
|
10
|
-
import { getStorageApplicationName } from '../utils/application-name.js';
|
|
11
11
|
export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
12
12
|
options;
|
|
13
13
|
db;
|
|
@@ -64,14 +64,21 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
64
64
|
}
|
|
65
65
|
const sizes = await this.db.sql `
|
|
66
66
|
SELECT
|
|
67
|
-
|
|
67
|
+
COALESCE(
|
|
68
|
+
pg_total_relation_size(to_regclass('current_data')),
|
|
69
|
+
0
|
|
70
|
+
) AS v1_current_size_bytes,
|
|
71
|
+
COALESCE(
|
|
72
|
+
pg_total_relation_size(to_regclass('v3_current_data')),
|
|
73
|
+
0
|
|
74
|
+
) AS v3_current_size_bytes,
|
|
68
75
|
pg_total_relation_size('bucket_parameters') AS parameter_size_bytes,
|
|
69
76
|
pg_total_relation_size('bucket_data') AS operations_size_bytes;
|
|
70
77
|
`.first();
|
|
71
78
|
return {
|
|
72
79
|
operations_size_bytes: Number(sizes.operations_size_bytes),
|
|
73
80
|
parameters_size_bytes: Number(sizes.parameter_size_bytes),
|
|
74
|
-
replication_size_bytes: Number(sizes.
|
|
81
|
+
replication_size_bytes: Number(sizes.v1_current_size_bytes) + Number(sizes.v3_current_size_bytes)
|
|
75
82
|
};
|
|
76
83
|
}
|
|
77
84
|
async getPowerSyncInstanceId() {
|
|
@@ -117,6 +124,11 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
117
124
|
}
|
|
118
125
|
async updateSyncRules(options) {
|
|
119
126
|
const storageVersion = options.storageVersion ?? storage.CURRENT_STORAGE_VERSION;
|
|
127
|
+
const storageConfig = storage.STORAGE_VERSION_CONFIG[storageVersion];
|
|
128
|
+
if (storageConfig == null) {
|
|
129
|
+
throw new framework.ServiceError(framework.ErrorCode.PSYNC_S1005, `Unsupported storage version ${storageVersion}`);
|
|
130
|
+
}
|
|
131
|
+
await this.initializeStorageVersion(storageConfig);
|
|
120
132
|
return this.db.transaction(async (db) => {
|
|
121
133
|
await db.sql `
|
|
122
134
|
UPDATE sync_rules
|
|
@@ -132,7 +144,14 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
132
144
|
nextval('sync_rules_id_sequence') AS id
|
|
133
145
|
)
|
|
134
146
|
INSERT INTO
|
|
135
|
-
sync_rules (
|
|
147
|
+
sync_rules (
|
|
148
|
+
id,
|
|
149
|
+
content,
|
|
150
|
+
sync_plan,
|
|
151
|
+
state,
|
|
152
|
+
slot_name,
|
|
153
|
+
storage_version
|
|
154
|
+
)
|
|
136
155
|
VALUES
|
|
137
156
|
(
|
|
138
157
|
(
|
|
@@ -142,6 +161,7 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
142
161
|
next_id
|
|
143
162
|
),
|
|
144
163
|
${{ type: 'varchar', value: options.config.yaml }},
|
|
164
|
+
${{ type: 'json', value: options.config.plan }},
|
|
145
165
|
${{ type: 'varchar', value: storage.SyncRuleState.PROCESSING }},
|
|
146
166
|
CONCAT(
|
|
147
167
|
${{ type: 'varchar', value: this.slot_name_prefix }},
|
|
@@ -165,6 +185,31 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
165
185
|
return new PostgresPersistedSyncRulesContent(this.db, newSyncRulesRow);
|
|
166
186
|
});
|
|
167
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Lazy-initializes storage-version-specific structures, if needed.
|
|
190
|
+
*/
|
|
191
|
+
async initializeStorageVersion(storageConfig) {
|
|
192
|
+
if (!storageConfig.softDeleteCurrentData) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
await this.db.sql `
|
|
196
|
+
CREATE TABLE IF NOT EXISTS v3_current_data (
|
|
197
|
+
group_id integer NOT NULL,
|
|
198
|
+
source_table TEXT NOT NULL,
|
|
199
|
+
source_key bytea NOT NULL,
|
|
200
|
+
CONSTRAINT unique_v3_current_data_id PRIMARY KEY (group_id, source_table, source_key),
|
|
201
|
+
buckets jsonb NOT NULL,
|
|
202
|
+
data bytea NOT NULL,
|
|
203
|
+
lookups bytea[] NOT NULL,
|
|
204
|
+
pending_delete BIGINT NULL
|
|
205
|
+
)
|
|
206
|
+
`.execute();
|
|
207
|
+
await this.db.sql `
|
|
208
|
+
CREATE INDEX IF NOT EXISTS v3_current_data_pending_deletes ON v3_current_data (group_id, pending_delete)
|
|
209
|
+
WHERE
|
|
210
|
+
pending_delete IS NOT NULL
|
|
211
|
+
`.execute();
|
|
212
|
+
}
|
|
168
213
|
async restartReplication(sync_rules_group_id) {
|
|
169
214
|
const next = await this.getNextSyncRulesContent();
|
|
170
215
|
const active = await this.getActiveSyncRulesContent();
|