@powersync/service-module-postgres-storage 0.17.0 → 0.19.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 +66 -0
- package/dist/migrations/scripts/1784900000000-source-metadata.d.ts +3 -0
- package/dist/migrations/scripts/1784900000000-source-metadata.js +22 -0
- package/dist/migrations/scripts/1784900000000-source-metadata.js.map +1 -0
- package/dist/migrations/scripts/1788000000000-sync-config-version-label.d.ts +3 -0
- package/dist/migrations/scripts/1788000000000-sync-config-version-label.js +12 -0
- package/dist/migrations/scripts/1788000000000-sync-config-version-label.js.map +1 -0
- package/dist/storage/PostgresBucketStorageFactory.d.ts +1 -0
- package/dist/storage/PostgresBucketStorageFactory.js +14 -7
- package/dist/storage/PostgresBucketStorageFactory.js.map +1 -1
- package/dist/storage/PostgresStorageProvider.js +2 -1
- package/dist/storage/PostgresStorageProvider.js.map +1 -1
- package/dist/storage/PostgresSyncRulesStorage.d.ts +4 -3
- package/dist/storage/PostgresSyncRulesStorage.js +17 -5
- package/dist/storage/PostgresSyncRulesStorage.js.map +1 -1
- package/dist/storage/batch/PostgresBucketBatch.d.ts +2 -2
- package/dist/storage/batch/PostgresBucketBatch.js +63 -94
- package/dist/storage/batch/PostgresBucketBatch.js.map +1 -1
- package/dist/storage/checkpoints/PostgresWriteCheckpointAPI.d.ts +1 -1
- package/dist/storage/checkpoints/PostgresWriteCheckpointAPI.js +2 -2
- package/dist/storage/checkpoints/PostgresWriteCheckpointAPI.js.map +1 -1
- package/dist/storage/sync-rules/PostgresPersistedSyncConfigContent.js +5 -1
- package/dist/storage/sync-rules/PostgresPersistedSyncConfigContent.js.map +1 -1
- package/dist/types/models/ActiveCheckpoint.d.ts +2 -2
- package/dist/types/models/ActiveCheckpoint.js +3 -2
- package/dist/types/models/ActiveCheckpoint.js.map +1 -1
- package/dist/types/models/ActiveCheckpointNotification.d.ts +2 -2
- package/dist/types/models/BucketData.d.ts +6 -6
- package/dist/types/models/BucketData.js +7 -6
- package/dist/types/models/BucketData.js.map +1 -1
- package/dist/types/models/CurrentData.d.ts +1 -1
- package/dist/types/models/CurrentData.js +2 -1
- package/dist/types/models/CurrentData.js.map +1 -1
- package/dist/types/models/SdkReporting.d.ts +3 -3
- package/dist/types/models/SdkReporting.js +3 -5
- package/dist/types/models/SdkReporting.js.map +1 -1
- package/dist/types/models/SourceTable.d.ts +13 -8
- package/dist/types/models/SourceTable.js +11 -6
- package/dist/types/models/SourceTable.js.map +1 -1
- package/dist/types/models/SyncRules.d.ts +11 -10
- package/dist/types/models/SyncRules.js +12 -11
- package/dist/types/models/SyncRules.js.map +1 -1
- package/dist/types/models/WriteCheckpoint.d.ts +2 -2
- package/dist/types/models/WriteCheckpoint.js +3 -2
- package/dist/types/models/WriteCheckpoint.js.map +1 -1
- package/dist/types/types.d.ts +2 -0
- package/package.json +8 -8
- package/src/migrations/scripts/1784900000000-source-metadata.ts +31 -0
- package/src/migrations/scripts/1788000000000-sync-config-version-label.ts +18 -0
- package/src/storage/PostgresBucketStorageFactory.ts +15 -7
- package/src/storage/PostgresStorageProvider.ts +2 -1
- package/src/storage/PostgresSyncRulesStorage.ts +21 -6
- package/src/storage/batch/PostgresBucketBatch.ts +67 -98
- package/src/storage/checkpoints/PostgresWriteCheckpointAPI.ts +2 -2
- package/src/storage/sync-rules/PostgresPersistedSyncConfigContent.ts +8 -1
- package/src/types/models/ActiveCheckpoint.ts +3 -2
- package/src/types/models/BucketData.ts +7 -6
- package/src/types/models/CurrentData.ts +2 -1
- package/src/types/models/SdkReporting.ts +4 -4
- package/src/types/models/SourceTable.ts +12 -6
- package/src/types/models/SyncRules.ts +12 -11
- package/src/types/models/WriteCheckpoint.ts +3 -2
- package/test/src/__snapshots__/storage_sync.test.ts.snap +0 -995
- package/test/src/checkpoint_notifications.test.ts +8 -2
- package/test/src/storage.test.ts +12 -4
- package/test/src/storage_compacting.test.ts +2 -2
- package/test/src/storage_sync.test.ts +44 -0
- package/test/src/util.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { orNull } from '@powersync/service-types';
|
|
1
2
|
import * as t from 'ts-codec';
|
|
2
3
|
import { bigint, hexBuffer, jsonb, pgwire_number } from '../codecs.js';
|
|
3
4
|
export const CurrentBucket = t.object({
|
|
@@ -20,6 +21,6 @@ export const V3CurrentData = t.object({
|
|
|
20
21
|
lookups: t.array(hexBuffer),
|
|
21
22
|
source_key: hexBuffer,
|
|
22
23
|
source_table: t.string,
|
|
23
|
-
pending_delete:
|
|
24
|
+
pending_delete: orNull(bigint)
|
|
24
25
|
});
|
|
25
26
|
//# sourceMappingURL=CurrentData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrentData.js","sourceRoot":"","sources":["../../../src/types/models/CurrentData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEvE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,MAAM,EAAE,CAAC,CAAC,MAAM;IAChB,KAAK,EAAE,CAAC,CAAC,MAAM;IACf,EAAE,EAAE,CAAC,CAAC,MAAM;CACb,CAAC,CAAC;AAKH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IACtC,IAAI,EAAE,SAAS;IACf,QAAQ,EAAE,aAAa;IACvB,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC;IAC3B,UAAU,EAAE,SAAS;IACrB,YAAY,EAAE,CAAC,CAAC,MAAM;CACvB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IACtC,IAAI,EAAE,SAAS;IACf,QAAQ,EAAE,aAAa;IACvB,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC;IAC3B,UAAU,EAAE,SAAS;IACrB,YAAY,EAAE,CAAC,CAAC,MAAM;IACtB,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"CurrentData.js","sourceRoot":"","sources":["../../../src/types/models/CurrentData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEvE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,MAAM,EAAE,CAAC,CAAC,MAAM;IAChB,KAAK,EAAE,CAAC,CAAC,MAAM;IACf,EAAE,EAAE,CAAC,CAAC,MAAM;CACb,CAAC,CAAC;AAKH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IACtC,IAAI,EAAE,SAAS;IACf,QAAQ,EAAE,aAAa;IACvB,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC;IAC3B,UAAU,EAAE,SAAS;IACrB,YAAY,EAAE,CAAC,CAAC,MAAM;CACvB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IACtC,IAAI,EAAE,SAAS;IACf,QAAQ,EAAE,aAAa;IACvB,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC;IAC3B,UAAU,EAAE,SAAS;IACrB,YAAY,EAAE,CAAC,CAAC,MAAM;IACtB,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC;CAC/B,CAAC,CAAC"}
|
|
@@ -7,15 +7,15 @@ export declare const Sdks: t.ObjectCodec<{
|
|
|
7
7
|
export type Sdks = t.Encoded<typeof Sdks>;
|
|
8
8
|
export declare const SdkReporting: t.ObjectCodec<{
|
|
9
9
|
users: t.Codec<bigint, string | number, string, t.CodecProps>;
|
|
10
|
-
sdks: t.
|
|
10
|
+
sdks: t.OptionalCodec<t.Codec<{
|
|
11
11
|
data: {
|
|
12
12
|
sdk: string;
|
|
13
13
|
clients: number;
|
|
14
14
|
users: number;
|
|
15
15
|
}[];
|
|
16
|
-
} |
|
|
16
|
+
} | null, {
|
|
17
17
|
data: string;
|
|
18
|
-
} |
|
|
18
|
+
} | null, string, t.CodecProps>>;
|
|
19
19
|
}>;
|
|
20
20
|
export type SdkReporting = t.Encoded<typeof SdkReporting>;
|
|
21
21
|
export type SdkReportingDecoded = t.Decoded<typeof SdkReporting>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { orNull } from '@powersync/service-types';
|
|
1
2
|
import * as t from 'ts-codec';
|
|
2
3
|
import { bigint, jsonb } from '../codecs.js';
|
|
3
4
|
export const Sdks = t.object({
|
|
@@ -7,11 +8,8 @@ export const Sdks = t.object({
|
|
|
7
8
|
});
|
|
8
9
|
export const SdkReporting = t.object({
|
|
9
10
|
users: bigint,
|
|
10
|
-
sdks: t
|
|
11
|
-
.object({
|
|
11
|
+
sdks: orNull(t.object({
|
|
12
12
|
data: jsonb(t.array(Sdks))
|
|
13
|
-
})
|
|
14
|
-
.optional()
|
|
15
|
-
.or(t.Null)
|
|
13
|
+
})).optional()
|
|
16
14
|
});
|
|
17
15
|
//# sourceMappingURL=SdkReporting.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SdkReporting.js","sourceRoot":"","sources":["../../../src/types/models/SdkReporting.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3B,GAAG,EAAE,CAAC,CAAC,MAAM;IACb,OAAO,EAAE,CAAC,CAAC,MAAM;IACjB,KAAK,EAAE,CAAC,CAAC,MAAM;CAChB,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,KAAK,EAAE,MAAM;IACb,IAAI,EAAE,CAAC
|
|
1
|
+
{"version":3,"file":"SdkReporting.js","sourceRoot":"","sources":["../../../src/types/models/SdkReporting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3B,GAAG,EAAE,CAAC,CAAC,MAAM;IACb,OAAO,EAAE,CAAC,CAAC,MAAM;IACjB,KAAK,EAAE,CAAC,CAAC,MAAM;CAChB,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,KAAK,EAAE,MAAM;IACb,IAAI,EAAE,MAAM,CACV,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,KAAK,CAAS,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KACnC,CAAC,CACH,CAAC,QAAQ,EAAE;CACb,CAAC,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { JsonValue } from '@powersync/service-core';
|
|
1
2
|
import * as t from 'ts-codec';
|
|
2
3
|
export type StoredRelationId = {
|
|
3
4
|
object_id: string | number | undefined;
|
|
@@ -11,24 +12,28 @@ export declare const ColumnDescriptor: t.ObjectCodec<{
|
|
|
11
12
|
/**
|
|
12
13
|
* Some data sources have a type id that can be used to identify the type of the column
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
|
+
type_oid: t.OptionalCodec<t.Codec<number, number, string, t.CodecProps>>;
|
|
15
16
|
}>;
|
|
16
17
|
export declare const SourceTable: t.ObjectCodec<{
|
|
17
18
|
id: t.IdentityCodec<t.CodecType.String>;
|
|
18
19
|
group_id: t.Codec<number, number, "pg_number", t.CodecProps>;
|
|
19
20
|
connection_id: t.Codec<bigint, string | number, string, t.CodecProps>;
|
|
20
|
-
relation_id: t.
|
|
21
|
+
relation_id: t.Codec<StoredRelationId | null, string | null>;
|
|
21
22
|
schema_name: t.IdentityCodec<t.CodecType.String>;
|
|
22
23
|
table_name: t.IdentityCodec<t.CodecType.String>;
|
|
23
|
-
replica_id_columns: t.
|
|
24
|
+
replica_id_columns: t.Codec<{
|
|
24
25
|
name: string;
|
|
25
26
|
type?: string | undefined;
|
|
26
|
-
|
|
27
|
-
}[]
|
|
27
|
+
type_oid?: number | undefined;
|
|
28
|
+
}[] | null, string | null>;
|
|
28
29
|
snapshot_done: t.IdentityCodec<t.CodecType.Boolean>;
|
|
29
|
-
snapshot_total_estimated_count: t.
|
|
30
|
-
snapshot_replicated_count: t.
|
|
31
|
-
snapshot_last_key: t.
|
|
30
|
+
snapshot_total_estimated_count: t.Codec<bigint | null, string | number | null>;
|
|
31
|
+
snapshot_replicated_count: t.Codec<bigint | null, string | number | null>;
|
|
32
|
+
snapshot_last_key: t.Codec<Buffer<ArrayBuffer> | null, string | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Source-specific metadata. Null for legacy records.
|
|
35
|
+
*/
|
|
36
|
+
source_metadata: t.Codec<JsonValue, string | null>;
|
|
32
37
|
}>;
|
|
33
38
|
export type SourceTable = t.Encoded<typeof SourceTable>;
|
|
34
39
|
export type SourceTableDecoded = t.Decoded<typeof SourceTable>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { orNull } from '@powersync/service-types';
|
|
1
2
|
import * as t from 'ts-codec';
|
|
2
3
|
import { bigint, hexBuffer, jsonb, jsonb_raw, pgwire_number } from '../codecs.js';
|
|
3
4
|
export const ColumnDescriptor = t.object({
|
|
@@ -9,19 +10,23 @@ export const ColumnDescriptor = t.object({
|
|
|
9
10
|
/**
|
|
10
11
|
* Some data sources have a type id that can be used to identify the type of the column
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
+
type_oid: t.number.optional()
|
|
13
14
|
});
|
|
14
15
|
export const SourceTable = t.object({
|
|
15
16
|
id: t.string,
|
|
16
17
|
group_id: pgwire_number,
|
|
17
18
|
connection_id: bigint,
|
|
18
|
-
relation_id:
|
|
19
|
+
relation_id: orNull(jsonb_raw()),
|
|
19
20
|
schema_name: t.string,
|
|
20
21
|
table_name: t.string,
|
|
21
|
-
replica_id_columns:
|
|
22
|
+
replica_id_columns: orNull(jsonb(t.array(ColumnDescriptor))),
|
|
22
23
|
snapshot_done: t.boolean,
|
|
23
|
-
snapshot_total_estimated_count:
|
|
24
|
-
snapshot_replicated_count:
|
|
25
|
-
snapshot_last_key:
|
|
24
|
+
snapshot_total_estimated_count: orNull(bigint),
|
|
25
|
+
snapshot_replicated_count: orNull(bigint),
|
|
26
|
+
snapshot_last_key: orNull(hexBuffer),
|
|
27
|
+
/**
|
|
28
|
+
* Source-specific metadata. Null for legacy records.
|
|
29
|
+
*/
|
|
30
|
+
source_metadata: orNull(jsonb_raw())
|
|
26
31
|
});
|
|
27
32
|
//# sourceMappingURL=SourceTable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SourceTable.js","sourceRoot":"","sources":["../../../src/types/models/SourceTable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SourceTable.js","sourceRoot":"","sources":["../../../src/types/models/SourceTable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAMlF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,IAAI,EAAE,CAAC,CAAC,MAAM;IACd;;OAEG;IACH,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE;IACzB;;OAEG;IACH,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,EAAE,EAAE,CAAC,CAAC,MAAM;IACZ,QAAQ,EAAE,aAAa;IACvB,aAAa,EAAE,MAAM;IACrB,WAAW,EAAE,MAAM,CAAC,SAAS,EAAoB,CAAC;IAClD,WAAW,EAAE,CAAC,CAAC,MAAM;IACrB,UAAU,EAAE,CAAC,CAAC,MAAM;IACpB,kBAAkB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC5D,aAAa,EAAE,CAAC,CAAC,OAAO;IACxB,8BAA8B,EAAE,MAAM,CAAC,MAAM,CAAC;IAC9C,yBAAyB,EAAE,MAAM,CAAC,MAAM,CAAC;IACzC,iBAAiB,EAAE,MAAM,CAAC,SAAS,CAAC;IACpC;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC,SAAS,EAAa,CAAC;CAChD,CAAC,CAAC"}
|
|
@@ -12,42 +12,43 @@ export declare const SyncRules: t.ObjectCodec<{
|
|
|
12
12
|
/**
|
|
13
13
|
* May be set if snapshot_done = false, if the replication stream requires it.
|
|
14
14
|
*/
|
|
15
|
-
snapshot_lsn: t.
|
|
15
|
+
snapshot_lsn: t.Codec<string | null, string | null>;
|
|
16
16
|
/**
|
|
17
17
|
* The last consistent checkpoint.
|
|
18
18
|
*
|
|
19
19
|
* There may be higher OpIds used in the database if we're in the middle of replicating a large transaction.
|
|
20
20
|
*/
|
|
21
|
-
last_checkpoint: t.
|
|
21
|
+
last_checkpoint: t.Codec<bigint | null, string | number | null>;
|
|
22
22
|
/**
|
|
23
23
|
* The LSN associated with the last consistent checkpoint.
|
|
24
24
|
*/
|
|
25
|
-
last_checkpoint_lsn: t.
|
|
25
|
+
last_checkpoint_lsn: t.Codec<string | null, string | null>;
|
|
26
26
|
/**
|
|
27
27
|
* If set, no new checkpoints may be created < this value.
|
|
28
28
|
*/
|
|
29
|
-
no_checkpoint_before: t.
|
|
29
|
+
no_checkpoint_before: t.Codec<string | null, string | null>;
|
|
30
30
|
slot_name: t.IdentityCodec<t.CodecType.String>;
|
|
31
31
|
/**
|
|
32
32
|
* Last time we persisted a checkpoint.
|
|
33
33
|
*
|
|
34
34
|
* This may be old if no data is incoming.
|
|
35
35
|
*/
|
|
36
|
-
last_checkpoint_ts: t.
|
|
36
|
+
last_checkpoint_ts: t.Codec<Date | null, string | import("@powersync/service-sync-rules").DateTimeValue | null>;
|
|
37
37
|
/**
|
|
38
38
|
* Last time we persisted a checkpoint or keepalive.
|
|
39
39
|
*
|
|
40
40
|
* This should stay fairly current while replicating.
|
|
41
41
|
*/
|
|
42
|
-
last_keepalive_ts: t.
|
|
42
|
+
last_keepalive_ts: t.Codec<Date | null, string | import("@powersync/service-sync-rules").DateTimeValue | null>;
|
|
43
43
|
/**
|
|
44
44
|
* If an error is stopping replication, it will be stored here.
|
|
45
45
|
*/
|
|
46
|
-
last_fatal_error: t.
|
|
47
|
-
keepalive_op: t.
|
|
46
|
+
last_fatal_error: t.Codec<string | null, string | null>;
|
|
47
|
+
keepalive_op: t.Codec<bigint | null, string | number | null>;
|
|
48
48
|
storage_version: t.OptionalCodec<t.Codec<number | null, number | null, string, t.CodecProps>>;
|
|
49
|
+
version_label: t.OptionalCodec<t.Codec<string | null, string | null, string, t.CodecProps>>;
|
|
49
50
|
content: t.IdentityCodec<t.CodecType.String>;
|
|
50
|
-
sync_plan: t.
|
|
51
|
+
sync_plan: t.Codec<{
|
|
51
52
|
plan: any;
|
|
52
53
|
compatibility: {
|
|
53
54
|
edition: number;
|
|
@@ -64,7 +65,7 @@ export declare const SyncRules: t.ObjectCodec<{
|
|
|
64
65
|
} | undefined;
|
|
65
66
|
ts?: string | undefined;
|
|
66
67
|
}[] | undefined;
|
|
67
|
-
}, import("@powersync/service-jsonbig").JsonContainer
|
|
68
|
+
} | null, import("@powersync/service-jsonbig").JsonContainer | null>;
|
|
68
69
|
}>;
|
|
69
70
|
export type SyncRules = t.Encoded<typeof SyncRules>;
|
|
70
71
|
export type SyncRulesDecoded = t.Decoded<typeof SyncRules>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { framework, storage } from '@powersync/service-core';
|
|
2
|
-
import { ReplicationError } from '@powersync/service-types';
|
|
2
|
+
import { orNull, ReplicationError } from '@powersync/service-types';
|
|
3
3
|
import * as t from 'ts-codec';
|
|
4
4
|
import { bigint, pgwire_number } from '../codecs.js';
|
|
5
5
|
import { jsonContainerObject } from './json.js';
|
|
@@ -15,42 +15,43 @@ export const SyncRules = t.object({
|
|
|
15
15
|
/**
|
|
16
16
|
* May be set if snapshot_done = false, if the replication stream requires it.
|
|
17
17
|
*/
|
|
18
|
-
snapshot_lsn:
|
|
18
|
+
snapshot_lsn: orNull(t.string),
|
|
19
19
|
/**
|
|
20
20
|
* The last consistent checkpoint.
|
|
21
21
|
*
|
|
22
22
|
* There may be higher OpIds used in the database if we're in the middle of replicating a large transaction.
|
|
23
23
|
*/
|
|
24
|
-
last_checkpoint:
|
|
24
|
+
last_checkpoint: orNull(bigint),
|
|
25
25
|
/**
|
|
26
26
|
* The LSN associated with the last consistent checkpoint.
|
|
27
27
|
*/
|
|
28
|
-
last_checkpoint_lsn:
|
|
28
|
+
last_checkpoint_lsn: orNull(t.string),
|
|
29
29
|
/**
|
|
30
30
|
* If set, no new checkpoints may be created < this value.
|
|
31
31
|
*/
|
|
32
|
-
no_checkpoint_before:
|
|
32
|
+
no_checkpoint_before: orNull(t.string),
|
|
33
33
|
slot_name: t.string,
|
|
34
34
|
/**
|
|
35
35
|
* Last time we persisted a checkpoint.
|
|
36
36
|
*
|
|
37
37
|
* This may be old if no data is incoming.
|
|
38
38
|
*/
|
|
39
|
-
last_checkpoint_ts:
|
|
39
|
+
last_checkpoint_ts: orNull(framework.codecs.date),
|
|
40
40
|
/**
|
|
41
41
|
* Last time we persisted a checkpoint or keepalive.
|
|
42
42
|
*
|
|
43
43
|
* This should stay fairly current while replicating.
|
|
44
44
|
*/
|
|
45
|
-
last_keepalive_ts:
|
|
45
|
+
last_keepalive_ts: orNull(framework.codecs.date),
|
|
46
46
|
/**
|
|
47
47
|
* If an error is stopping replication, it will be stored here.
|
|
48
48
|
*/
|
|
49
|
-
last_fatal_error:
|
|
50
|
-
keepalive_op:
|
|
51
|
-
storage_version:
|
|
49
|
+
last_fatal_error: orNull(t.string),
|
|
50
|
+
keepalive_op: orNull(bigint),
|
|
51
|
+
storage_version: orNull(pgwire_number).optional(),
|
|
52
|
+
version_label: orNull(t.string).optional(),
|
|
52
53
|
content: t.string,
|
|
53
|
-
sync_plan:
|
|
54
|
+
sync_plan: orNull(jsonContainerObject(t.object({
|
|
54
55
|
plan: t.any,
|
|
55
56
|
compatibility: t.object({
|
|
56
57
|
edition: t.number,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyncRules.js","sourceRoot":"","sources":["../../../src/types/models/SyncRules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"SyncRules.js","sourceRoot":"","sources":["../../../src/types/models/SyncRules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,EAAE,EAAE,aAAa;IACjB,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC;IACpC;;;;OAIG;IACH,aAAa,EAAE,CAAC,CAAC,OAAO;IACxB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9B;;;;OAIG;IACH,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC;IAC/B;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IACrC;;OAEG;IACH,oBAAoB,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IACtC,SAAS,EAAE,CAAC,CAAC,MAAM;IACnB;;;;OAIG;IACH,kBAAkB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;IACjD;;;;OAIG;IACH,iBAAiB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;IAChD;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IAClC,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC,QAAQ,EAAE;IACjD,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE;IAC1C,OAAO,EAAE,CAAC,CAAC,MAAM;IACjB,SAAS,EAAE,MAAM,CACf,mBAAmB,CACjB,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,CAAC,CAAC,GAAG;QACX,aAAa,EAAE,CAAC,CAAC,MAAM,CAAC;YACtB,OAAO,EAAE,CAAC,CAAC,MAAM;YACjB,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;YAC9B,qBAAqB,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE;SAC3C,CAAC;QACF,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QAC7C,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,QAAQ,EAAE;KAC7C,CAAC,CACH,CACF;CACF,CAAC,CAAC"}
|
|
@@ -3,7 +3,7 @@ export declare const WriteCheckpoint: t.ObjectCodec<{
|
|
|
3
3
|
user_id: t.IdentityCodec<t.CodecType.String>;
|
|
4
4
|
lsns: t.Codec<Record<string, string>, string, string, t.CodecProps>;
|
|
5
5
|
write_checkpoint: t.Codec<bigint, string | number, string, t.CodecProps>;
|
|
6
|
-
checkpoint_requested_at: t.
|
|
6
|
+
checkpoint_requested_at: t.Codec<Date | null, string | import("@powersync/service-sync-rules").DateTimeValue | null>;
|
|
7
7
|
}>;
|
|
8
8
|
export type WriteCheckpoint = t.Encoded<typeof WriteCheckpoint>;
|
|
9
9
|
export type WriteCheckpointDecoded = t.Decoded<typeof WriteCheckpoint>;
|
|
@@ -11,7 +11,7 @@ export declare const CustomWriteCheckpoint: t.ObjectCodec<{
|
|
|
11
11
|
user_id: t.IdentityCodec<t.CodecType.String>;
|
|
12
12
|
write_checkpoint: t.Codec<bigint, string | number, string, t.CodecProps>;
|
|
13
13
|
sync_rules_id: t.Codec<bigint, string | number, string, t.CodecProps>;
|
|
14
|
-
checkpoint_requested_at: t.
|
|
14
|
+
checkpoint_requested_at: t.Codec<Date | null, string | import("@powersync/service-sync-rules").DateTimeValue | null>;
|
|
15
15
|
}>;
|
|
16
16
|
export type CustomWriteCheckpoint = t.Encoded<typeof CustomWriteCheckpoint>;
|
|
17
17
|
export type CustomWriteCheckpointDecoded = t.Decoded<typeof CustomWriteCheckpoint>;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { framework } from '@powersync/service-core';
|
|
2
|
+
import { orNull } from '@powersync/service-types';
|
|
2
3
|
import * as t from 'ts-codec';
|
|
3
4
|
import { bigint, jsonb } from '../codecs.js';
|
|
4
5
|
export const WriteCheckpoint = t.object({
|
|
5
6
|
user_id: t.string,
|
|
6
7
|
lsns: jsonb(t.record(t.string)),
|
|
7
8
|
write_checkpoint: bigint,
|
|
8
|
-
checkpoint_requested_at:
|
|
9
|
+
checkpoint_requested_at: orNull(framework.codecs.date)
|
|
9
10
|
});
|
|
10
11
|
export const CustomWriteCheckpoint = t.object({
|
|
11
12
|
user_id: t.string,
|
|
12
13
|
write_checkpoint: bigint,
|
|
13
14
|
sync_rules_id: bigint,
|
|
14
|
-
checkpoint_requested_at:
|
|
15
|
+
checkpoint_requested_at: orNull(framework.codecs.date)
|
|
15
16
|
});
|
|
16
17
|
//# sourceMappingURL=WriteCheckpoint.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WriteCheckpoint.js","sourceRoot":"","sources":["../../../src/types/models/WriteCheckpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,OAAO,EAAE,CAAC,CAAC,MAAM;IACjB,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC/B,gBAAgB,EAAE,MAAM;IACxB,uBAAuB,EAAE,
|
|
1
|
+
{"version":3,"file":"WriteCheckpoint.js","sourceRoot":"","sources":["../../../src/types/models/WriteCheckpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,OAAO,EAAE,CAAC,CAAC,MAAM;IACjB,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC/B,gBAAgB,EAAE,MAAM;IACxB,uBAAuB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;CACvD,CAAC,CAAC;AAKH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,OAAO,EAAE,CAAC,CAAC,MAAM;IACjB,gBAAgB,EAAE,MAAM;IACxB,aAAa,EAAE,MAAM;IACrB,uBAAuB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;CACvD,CAAC,CAAC"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export type OperationBatchLimits = t.Encoded<typeof OperationBatchLimits>;
|
|
|
32
32
|
export declare const PostgresStorageConfig: t.Intersection<t.Codec<{
|
|
33
33
|
type: string;
|
|
34
34
|
max_pool_size?: number | undefined;
|
|
35
|
+
default_storage_version?: number | undefined;
|
|
35
36
|
} & {
|
|
36
37
|
type: "postgresql";
|
|
37
38
|
id?: string | undefined;
|
|
@@ -54,6 +55,7 @@ export declare const PostgresStorageConfig: t.Intersection<t.Codec<{
|
|
|
54
55
|
}, {
|
|
55
56
|
type: string;
|
|
56
57
|
max_pool_size?: number | undefined;
|
|
58
|
+
default_storage_version?: number | undefined;
|
|
57
59
|
} & {
|
|
58
60
|
type: "postgresql";
|
|
59
61
|
id?: string | undefined;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/service-module-postgres-storage",
|
|
3
3
|
"repository": "https://github.com/powersync-ja/powersync-service",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.19.0",
|
|
5
5
|
"license": "FSL-1.1-ALv2",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"publishConfig": {
|
|
@@ -16,17 +16,17 @@
|
|
|
16
16
|
"lru-cache": "^10.2.2",
|
|
17
17
|
"ts-codec": "^1.3.0",
|
|
18
18
|
"uuid": "^14.0.0",
|
|
19
|
-
"@powersync/lib-
|
|
20
|
-
"@powersync/
|
|
21
|
-
"@powersync/service-
|
|
22
|
-
"@powersync/service-
|
|
19
|
+
"@powersync/lib-services-framework": "0.10.1",
|
|
20
|
+
"@powersync/service-core": "1.26.0",
|
|
21
|
+
"@powersync/service-types": "0.18.0",
|
|
22
|
+
"@powersync/lib-service-postgres": "0.5.4",
|
|
23
|
+
"@powersync/service-jpgwire": "0.21.23",
|
|
23
24
|
"@powersync/service-jsonbig": "0.17.13",
|
|
24
|
-
"@powersync/service-
|
|
25
|
-
"@powersync/service-sync-rules": "0.40.0"
|
|
25
|
+
"@powersync/service-sync-rules": "0.41.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"typescript": "~6.0.3",
|
|
29
|
-
"@powersync/service-core-tests": "0.18.
|
|
29
|
+
"@powersync/service-core-tests": "0.18.1"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsc -b",
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { migrations } from '@powersync/service-core';
|
|
2
|
+
|
|
3
|
+
import { openMigrationDB } from '../migration-utils.js';
|
|
4
|
+
|
|
5
|
+
export const up: migrations.PowerSyncMigrationFunction = async (context) => {
|
|
6
|
+
const {
|
|
7
|
+
service_context: { configuration }
|
|
8
|
+
} = context;
|
|
9
|
+
await using client = openMigrationDB(configuration.storage);
|
|
10
|
+
|
|
11
|
+
await client.transaction(async (db) => {
|
|
12
|
+
await db.sql`
|
|
13
|
+
ALTER TABLE source_tables
|
|
14
|
+
ADD COLUMN source_metadata JSONB
|
|
15
|
+
`.execute();
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const down: migrations.PowerSyncMigrationFunction = async (context) => {
|
|
20
|
+
const {
|
|
21
|
+
service_context: { configuration }
|
|
22
|
+
} = context;
|
|
23
|
+
await using client = openMigrationDB(configuration.storage);
|
|
24
|
+
|
|
25
|
+
await client.transaction(async (db) => {
|
|
26
|
+
await db.sql`
|
|
27
|
+
ALTER TABLE source_tables
|
|
28
|
+
DROP COLUMN source_metadata
|
|
29
|
+
`.execute();
|
|
30
|
+
});
|
|
31
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { migrations } from '@powersync/service-core';
|
|
2
|
+
import { openMigrationDB } from '../migration-utils.js';
|
|
3
|
+
|
|
4
|
+
export const up: migrations.PowerSyncMigrationFunction = async (context) => {
|
|
5
|
+
const {
|
|
6
|
+
service_context: { configuration }
|
|
7
|
+
} = context;
|
|
8
|
+
await using client = openMigrationDB(configuration.storage);
|
|
9
|
+
await client.sql`ALTER TABLE sync_rules ADD COLUMN version_label TEXT`.execute();
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const down: migrations.PowerSyncMigrationFunction = async (context) => {
|
|
13
|
+
const {
|
|
14
|
+
service_context: { configuration }
|
|
15
|
+
} = context;
|
|
16
|
+
await using client = openMigrationDB(configuration.storage);
|
|
17
|
+
await client.sql`ALTER TABLE sync_rules DROP COLUMN version_label`.execute();
|
|
18
|
+
};
|
|
@@ -15,6 +15,7 @@ export type PostgresBucketStorageOptions = {
|
|
|
15
15
|
config: NormalizedPostgresStorageConfig;
|
|
16
16
|
replicationStreamNamePrefix: string;
|
|
17
17
|
checksumCacheTtlMs?: number;
|
|
18
|
+
defaultStorageVersion?: number;
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
@@ -78,7 +79,8 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
78
79
|
return {
|
|
79
80
|
operations_size_bytes: 0,
|
|
80
81
|
parameters_size_bytes: 0,
|
|
81
|
-
replication_size_bytes: 0
|
|
82
|
+
replication_size_bytes: 0,
|
|
83
|
+
object_storage_size_bytes: 0
|
|
82
84
|
};
|
|
83
85
|
}
|
|
84
86
|
|
|
@@ -104,7 +106,8 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
104
106
|
return {
|
|
105
107
|
operations_size_bytes: Number(sizes!.operations_size_bytes),
|
|
106
108
|
parameters_size_bytes: Number(sizes!.parameter_size_bytes),
|
|
107
|
-
replication_size_bytes: Number(sizes!.v1_current_size_bytes) + Number(sizes!.v3_current_size_bytes)
|
|
109
|
+
replication_size_bytes: Number(sizes!.v1_current_size_bytes) + Number(sizes!.v3_current_size_bytes),
|
|
110
|
+
object_storage_size_bytes: 0
|
|
108
111
|
};
|
|
109
112
|
}
|
|
110
113
|
|
|
@@ -156,12 +159,15 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
156
159
|
|
|
157
160
|
async updateSyncRules(options: storage.UpdateSyncRulesOptions): Promise<PostgresPersistedReplicationStream> {
|
|
158
161
|
const storageVersion =
|
|
159
|
-
options.storageVersion ??
|
|
162
|
+
options.storageVersion ??
|
|
163
|
+
options.config.parsed.config.storageVersion ??
|
|
164
|
+
this.options.defaultStorageVersion ??
|
|
165
|
+
storage.CURRENT_STORAGE_VERSION;
|
|
160
166
|
const storageConfig = storage.STORAGE_VERSION_CONFIG[storageVersion];
|
|
161
|
-
if (storageConfig == null) {
|
|
167
|
+
if (storageConfig == null || storageVersion >= storage.STORAGE_VERSION_4) {
|
|
162
168
|
throw new framework.ServiceError(
|
|
163
169
|
framework.ErrorCode.PSYNC_S1005,
|
|
164
|
-
`Unsupported storage version ${storageVersion}`
|
|
170
|
+
`Unsupported storage version ${storageVersion} for PostgreSQL storage`
|
|
165
171
|
);
|
|
166
172
|
}
|
|
167
173
|
await this.initializeStorageVersion(storageConfig);
|
|
@@ -187,7 +193,8 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
187
193
|
sync_plan,
|
|
188
194
|
state,
|
|
189
195
|
slot_name,
|
|
190
|
-
storage_version
|
|
196
|
+
storage_version,
|
|
197
|
+
version_label
|
|
191
198
|
)
|
|
192
199
|
VALUES
|
|
193
200
|
(
|
|
@@ -211,7 +218,8 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
211
218
|
'_',
|
|
212
219
|
${{ type: 'varchar', value: crypto.randomBytes(2).toString('hex') }}
|
|
213
220
|
),
|
|
214
|
-
${{ type: 'int4', value: storageVersion }}
|
|
221
|
+
${{ type: 'int4', value: storageVersion }},
|
|
222
|
+
${{ type: 'varchar', value: options.version_label ?? null }}
|
|
215
223
|
)
|
|
216
224
|
RETURNING
|
|
217
225
|
*
|
|
@@ -28,7 +28,8 @@ export class PostgresStorageProvider implements storage.StorageProvider {
|
|
|
28
28
|
const storageFactory = new PostgresBucketStorageFactory({
|
|
29
29
|
config: normalizedConfig,
|
|
30
30
|
replicationStreamNamePrefix: options.resolvedConfig.slot_name_prefix,
|
|
31
|
-
checksumCacheTtlMs: options.resolvedConfig.api_parameters.bucket_count_cache_ttl_minutes * 60_000
|
|
31
|
+
checksumCacheTtlMs: options.resolvedConfig.api_parameters.bucket_count_cache_ttl_minutes * 60_000,
|
|
32
|
+
defaultStorageVersion: decodedConfig.default_storage_version
|
|
32
33
|
});
|
|
33
34
|
|
|
34
35
|
const reportStorageFactory = new PostgresReportStorage({
|
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
BucketChecksum,
|
|
5
5
|
CHECKPOINT_INVALIDATE_ALL,
|
|
6
6
|
CheckpointChanges,
|
|
7
|
+
CompactInitialReplicationOptions,
|
|
8
|
+
CompactInitialReplicationResults,
|
|
7
9
|
GetCheckpointChangesOptions,
|
|
8
10
|
InternalOpId,
|
|
9
11
|
internalToExternalOpId,
|
|
@@ -11,11 +13,10 @@ import {
|
|
|
11
13
|
maxLsn,
|
|
12
14
|
ParameterSetLimitExceededError,
|
|
13
15
|
PartialChecksum,
|
|
14
|
-
PopulateChecksumCacheOptions,
|
|
15
|
-
PopulateChecksumCacheResults,
|
|
16
16
|
ReplicationCheckpoint,
|
|
17
17
|
storage,
|
|
18
18
|
StorageVersionConfig,
|
|
19
|
+
SyncRuleState,
|
|
19
20
|
utils,
|
|
20
21
|
WatchWriteCheckpointOptions
|
|
21
22
|
} from '@powersync/service-core';
|
|
@@ -94,7 +95,7 @@ export class PostgresSyncRulesStorage
|
|
|
94
95
|
this.factory = options.factory;
|
|
95
96
|
this.storageConfig = options.replicationStream.getStorageConfig();
|
|
96
97
|
this.currentDataStore = new PostgresCurrentDataStore(this.storageConfig);
|
|
97
|
-
this.logger =
|
|
98
|
+
this.logger = this.sync_rules.logger;
|
|
98
99
|
|
|
99
100
|
this.writeCheckpointAPI = new PostgresWriteCheckpointAPI({
|
|
100
101
|
db: this.db,
|
|
@@ -145,7 +146,19 @@ export class PostgresSyncRulesStorage
|
|
|
145
146
|
`.execute();
|
|
146
147
|
}
|
|
147
148
|
|
|
149
|
+
supportsIncrementalParameterCompaction(): boolean {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
|
|
148
153
|
async compact(options?: storage.CompactOptions): Promise<void> {
|
|
154
|
+
if (options?.incrementalOnly) {
|
|
155
|
+
// Not supported yet
|
|
156
|
+
this.logger.info('Incremental compacting is not supported on Postgres storage yet.');
|
|
157
|
+
return;
|
|
158
|
+
} else if (this.replicationStream.state != SyncRuleState.ACTIVE) {
|
|
159
|
+
this.logger.info(`Skipping compacting of replication stream in ${this.replicationStream.state} state.`);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
149
162
|
let maxOpId = options?.maxOpId;
|
|
150
163
|
if (maxOpId == null) {
|
|
151
164
|
const checkpoint = await this.getCheckpoint();
|
|
@@ -160,7 +173,9 @@ export class PostgresSyncRulesStorage
|
|
|
160
173
|
}).compact();
|
|
161
174
|
}
|
|
162
175
|
|
|
163
|
-
async
|
|
176
|
+
async compactInitialReplication(
|
|
177
|
+
_options: CompactInitialReplicationOptions
|
|
178
|
+
): Promise<CompactInitialReplicationResults> {
|
|
164
179
|
// no-op - checksum cache is not implemented for Postgres yet
|
|
165
180
|
return { buckets: 0 };
|
|
166
181
|
}
|
|
@@ -172,8 +187,8 @@ export class PostgresSyncRulesStorage
|
|
|
172
187
|
});
|
|
173
188
|
}
|
|
174
189
|
|
|
175
|
-
setWriteCheckpointMode(
|
|
176
|
-
return this.writeCheckpointAPI.setWriteCheckpointMode(
|
|
190
|
+
setWriteCheckpointMode(config: storage.WriteCheckpointModeConfig): void {
|
|
191
|
+
return this.writeCheckpointAPI.setWriteCheckpointMode(config);
|
|
177
192
|
}
|
|
178
193
|
|
|
179
194
|
createManagedWriteCheckpoints(
|