@powersync/service-module-postgres-storage 0.19.4 → 0.19.5
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 +34 -0
- package/LICENSE +201 -67
- package/dist/storage/PostgresBucketStorageFactory.d.ts +2 -0
- package/dist/storage/PostgresBucketStorageFactory.js +105 -95
- package/dist/storage/PostgresBucketStorageFactory.js.map +1 -1
- package/dist/storage/PostgresReportStorage.js +1 -2
- package/dist/storage/PostgresReportStorage.js.map +1 -1
- package/dist/storage/PostgresSyncRulesStorage.js +1 -2
- package/dist/storage/PostgresSyncRulesStorage.js.map +1 -1
- package/dist/storage/batch/PostgresBucketBatch.js +14 -4
- package/dist/storage/batch/PostgresBucketBatch.js.map +1 -1
- package/dist/storage/batch/PostgresPersistedBatch.d.ts +15 -0
- package/dist/storage/batch/PostgresPersistedBatch.js +58 -4
- package/dist/storage/batch/PostgresPersistedBatch.js.map +1 -1
- package/dist/types/types.d.ts +22 -1
- package/dist/types/types.js +18 -1
- package/dist/types/types.js.map +1 -1
- package/dist/utils/test-utils.d.ts +6 -1
- package/dist/utils/test-utils.js +5 -1
- package/dist/utils/test-utils.js.map +1 -1
- package/package.json +10 -11
- package/src/storage/PostgresBucketStorageFactory.ts +114 -96
- package/src/storage/PostgresReportStorage.ts +1 -2
- package/src/storage/PostgresSyncRulesStorage.ts +1 -2
- package/src/storage/batch/PostgresBucketBatch.ts +16 -6
- package/src/storage/batch/PostgresPersistedBatch.ts +69 -4
- package/src/types/types.ts +25 -2
- package/src/utils/test-utils.ts +16 -2
- package/test/src/invalid_sync_config.test.ts +100 -0
- package/test/src/storage_flush.test.ts +207 -0
- package/test/src/util.ts +10 -5
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @powersync/service-module-postgres-storage
|
|
2
2
|
|
|
3
|
+
## 0.19.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 574ddbd: Change license from FSL to Apache-2.0
|
|
8
|
+
- 071507a: Reject sync configs with fatal parsing or source-capability errors before they enter replication. A context-owned `SyncConfigEngine` shares one source-aware parsed config and validation result between replication startup, diagnostics, and manual reprocess guards. The engine loads filesystem, Base64, or inline input on first use and caches the result.
|
|
9
|
+
|
|
10
|
+
With `exit_on_error: false`, a rejected startup submission stops pending processing work while preserving active replication, including when active and processing configs share a replication stream. This also stops invalid pending configs persisted by older services. Rejected content is exposed through diagnostics `deploying_sync_rules`. With `exit_on_error: true`, validation failures stop startup before storage changes. Warnings are advisory.
|
|
11
|
+
|
|
12
|
+
API-managed deployments share validation and reject fatal submissions before storage changes. Rejected API requests do not cancel accepted pending work or create a local diagnostic overlay.
|
|
13
|
+
|
|
14
|
+
- b64957d: Improve propagation of abort errors and fix some unhandled rejections.
|
|
15
|
+
- 071507a: Prevent replication recovery from cancelling a newer sync config deployment. Check active and processing configs and create any recovery replacement in one transaction, using a table lock to serialize concurrent sync config state changes. This preserves valid deployments submitted while recovery is starting, including after an invalid configured sync config cancels pending processing.
|
|
16
|
+
- f75978e: Fix replication failing with `RangeError: Invalid string length` when a single source row with large data is evaluated into many buckets. Bucket data and parameter data are now flushed in size-bounded INSERT statements.
|
|
17
|
+
- 070ef34: Prevent unused publication tables from blocking initial replication after an interruption with Postgres storage or MongoDB storage versions 1 and 2. Tables unused by the sync config no longer create persisted source-table records. Existing affected deployments must explicitly redeploy the sync config after upgrading; restarting the service or reloading unchanged configuration does not clear the existing state.
|
|
18
|
+
- cc6d30b: Only resnapshot rows with missing TOAST values when a streamed update has no stored record, as the MongoDB storage already does. A complete row is evaluated and stored anyway, so the resnapshot was redundant. On a bulk update to rows not yet snapshotted this queued one resnapshot per row and kept confirmed_flush_lsn from advancing.
|
|
19
|
+
- Updated dependencies [17a026d]
|
|
20
|
+
- Updated dependencies [ebba2a3]
|
|
21
|
+
- Updated dependencies [7cf585d]
|
|
22
|
+
- Updated dependencies [574ddbd]
|
|
23
|
+
- Updated dependencies [071507a]
|
|
24
|
+
- Updated dependencies [b64957d]
|
|
25
|
+
- Updated dependencies [070ef34]
|
|
26
|
+
- Updated dependencies [85c5e12]
|
|
27
|
+
- Updated dependencies [d951049]
|
|
28
|
+
- Updated dependencies [a8d5c22]
|
|
29
|
+
- @powersync/service-core@1.28.0
|
|
30
|
+
- @powersync/service-sync-rules@0.45.0
|
|
31
|
+
- @powersync/lib-service-postgres@0.5.8
|
|
32
|
+
- @powersync/lib-services-framework@0.10.5
|
|
33
|
+
- @powersync/service-jpgwire@0.21.27
|
|
34
|
+
- @powersync/service-jsonbig@0.17.14
|
|
35
|
+
- @powersync/service-types@0.21.0
|
|
36
|
+
|
|
3
37
|
## 0.19.4
|
|
4
38
|
|
|
5
39
|
### Patch Changes
|
package/LICENSE
CHANGED
|
@@ -1,67 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -22,7 +22,9 @@ export declare class PostgresBucketStorageFactory extends storage.BucketStorageF
|
|
|
22
22
|
getStorageMetrics(): Promise<storage.StorageMetrics>;
|
|
23
23
|
getPowerSyncInstanceId(): Promise<string>;
|
|
24
24
|
getSystemIdentifier(): Promise<storage.BucketStorageSystemIdentifier>;
|
|
25
|
+
stopProcessingSyncConfigs(): Promise<void>;
|
|
25
26
|
updateSyncRules(options: storage.UpdateSyncRulesOptions): Promise<PostgresPersistedReplicationStream>;
|
|
27
|
+
private updateSyncRulesInTransaction;
|
|
26
28
|
/**
|
|
27
29
|
* Lazy-initializes storage-version-specific structures, if needed.
|
|
28
30
|
*/
|
|
@@ -130,7 +130,19 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
130
130
|
type: lib_postgres.POSTGRES_CONNECTION_TYPE
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
|
+
async stopProcessingSyncConfigs() {
|
|
134
|
+
await this.db.sql `
|
|
135
|
+
UPDATE sync_rules
|
|
136
|
+
SET
|
|
137
|
+
state = ${{ type: 'varchar', value: storage.SyncRuleState.STOP }}
|
|
138
|
+
WHERE
|
|
139
|
+
state = ${{ type: 'varchar', value: storage.SyncRuleState.PROCESSING }}
|
|
140
|
+
`.execute();
|
|
141
|
+
}
|
|
133
142
|
async updateSyncRules(options) {
|
|
143
|
+
return this.db.transaction((db) => this.updateSyncRulesInTransaction(options, db));
|
|
144
|
+
}
|
|
145
|
+
async updateSyncRulesInTransaction(options, db) {
|
|
134
146
|
const storageVersion = options.storageVersion ??
|
|
135
147
|
options.config.parsed.config.storageVersion ??
|
|
136
148
|
this.options.defaultStorageVersion ??
|
|
@@ -139,73 +151,71 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
139
151
|
if (storageConfig == null || storageVersion >= storage.STORAGE_VERSION_4) {
|
|
140
152
|
throw new framework.ServiceError(framework.ErrorCode.PSYNC_S1005, `Unsupported storage version ${storageVersion} for PostgreSQL storage`);
|
|
141
153
|
}
|
|
142
|
-
await this.initializeStorageVersion(storageConfig);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
154
|
+
await this.initializeStorageVersion(storageConfig, db);
|
|
155
|
+
await db.sql `
|
|
156
|
+
UPDATE sync_rules
|
|
157
|
+
SET
|
|
158
|
+
state = ${{ type: 'varchar', value: storage.SyncRuleState.STOP }}
|
|
159
|
+
WHERE
|
|
160
|
+
state = ${{ type: 'varchar', value: storage.SyncRuleState.PROCESSING }}
|
|
161
|
+
`.execute();
|
|
162
|
+
// Uses the legacy sequence name "sync_rules_id_sequence" for backwards-compatibility. See AGENTS.md.
|
|
163
|
+
const newSyncRulesRow = await db.sql `
|
|
164
|
+
WITH
|
|
165
|
+
next_id AS (
|
|
166
|
+
SELECT
|
|
167
|
+
nextval('sync_rules_id_sequence') AS id
|
|
168
|
+
)
|
|
169
|
+
INSERT INTO
|
|
170
|
+
sync_rules (
|
|
171
|
+
id,
|
|
172
|
+
content,
|
|
173
|
+
sync_plan,
|
|
174
|
+
state,
|
|
175
|
+
slot_name,
|
|
176
|
+
storage_version,
|
|
177
|
+
version_label
|
|
178
|
+
)
|
|
179
|
+
VALUES
|
|
180
|
+
(
|
|
169
181
|
(
|
|
182
|
+
SELECT
|
|
183
|
+
id
|
|
184
|
+
FROM
|
|
185
|
+
next_id
|
|
186
|
+
),
|
|
187
|
+
${{ type: 'varchar', value: options.config.yaml }},
|
|
188
|
+
${{ type: 'json', value: options.config.plan }},
|
|
189
|
+
${{ type: 'varchar', value: storage.SyncRuleState.PROCESSING }},
|
|
190
|
+
CONCAT(
|
|
191
|
+
${{ type: 'varchar', value: this.replicationStreamNamePrefix }},
|
|
170
192
|
(
|
|
171
193
|
SELECT
|
|
172
194
|
id
|
|
173
195
|
FROM
|
|
174
196
|
next_id
|
|
175
197
|
),
|
|
176
|
-
|
|
177
|
-
${{ type: '
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
${{ type: 'varchar', value: crypto.randomBytes(2).toString('hex') }}
|
|
189
|
-
),
|
|
190
|
-
${{ type: 'int4', value: storageVersion }},
|
|
191
|
-
${{ type: 'varchar', value: options.version_label ?? null }}
|
|
192
|
-
)
|
|
193
|
-
RETURNING
|
|
194
|
-
*
|
|
195
|
-
`
|
|
196
|
-
.decoded(models.SyncRules)
|
|
197
|
-
.first();
|
|
198
|
-
return new PostgresPersistedReplicationStream(this.db, newSyncRulesRow);
|
|
199
|
-
});
|
|
198
|
+
'_',
|
|
199
|
+
${{ type: 'varchar', value: crypto.randomBytes(2).toString('hex') }}
|
|
200
|
+
),
|
|
201
|
+
${{ type: 'int4', value: storageVersion }},
|
|
202
|
+
${{ type: 'varchar', value: options.version_label ?? null }}
|
|
203
|
+
)
|
|
204
|
+
RETURNING
|
|
205
|
+
*
|
|
206
|
+
`
|
|
207
|
+
.decoded(models.SyncRules)
|
|
208
|
+
.first();
|
|
209
|
+
return new PostgresPersistedReplicationStream(this.db, newSyncRulesRow);
|
|
200
210
|
}
|
|
201
211
|
/**
|
|
202
212
|
* Lazy-initializes storage-version-specific structures, if needed.
|
|
203
213
|
*/
|
|
204
|
-
async initializeStorageVersion(storageConfig) {
|
|
214
|
+
async initializeStorageVersion(storageConfig, db) {
|
|
205
215
|
if (!storageConfig.softDeleteCurrentData) {
|
|
206
216
|
return;
|
|
207
217
|
}
|
|
208
|
-
await
|
|
218
|
+
await db.sql `
|
|
209
219
|
CREATE TABLE IF NOT EXISTS v3_current_data (
|
|
210
220
|
group_id integer NOT NULL,
|
|
211
221
|
source_table TEXT NOT NULL,
|
|
@@ -217,55 +227,55 @@ export class PostgresBucketStorageFactory extends storage.BucketStorageFactory {
|
|
|
217
227
|
pending_delete BIGINT NULL
|
|
218
228
|
)
|
|
219
229
|
`.execute();
|
|
220
|
-
await
|
|
230
|
+
await db.sql `
|
|
221
231
|
CREATE INDEX IF NOT EXISTS v3_current_data_pending_deletes ON v3_current_data (group_id, pending_delete)
|
|
222
232
|
WHERE
|
|
223
233
|
pending_delete IS NOT NULL
|
|
224
234
|
`.execute();
|
|
225
235
|
}
|
|
226
236
|
async restartReplication(replicationStreamId) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
UPDATE sync_rules
|
|
237
|
-
SET
|
|
238
|
-
state = ${{ value: storage.SyncRuleState.STOP, type: 'varchar' }}
|
|
239
|
-
WHERE
|
|
240
|
-
id = ${{ value: next.content.replicationStreamId, type: 'int4' }}
|
|
241
|
-
AND state = ${{ value: storage.SyncRuleState.PROCESSING, type: 'varchar' }}
|
|
242
|
-
`.execute();
|
|
243
|
-
}
|
|
244
|
-
else if (next == null && active?.content.replicationStreamId == replicationStreamId) {
|
|
245
|
-
// Slot removed for "active" replication stream, while there is no "next" one.
|
|
246
|
-
await this.updateSyncRules(active.content.asUpdateOptions());
|
|
247
|
-
// Pro-actively stop replicating, but still serve clients with existing data
|
|
248
|
-
await this.db.sql `
|
|
249
|
-
UPDATE sync_rules
|
|
250
|
-
SET
|
|
251
|
-
state = ${{ value: storage.SyncRuleState.ERRORED, type: 'varchar' }}
|
|
252
|
-
WHERE
|
|
253
|
-
id = ${{ value: active.content.replicationStreamId, type: 'int4' }}
|
|
254
|
-
AND state = ${{ value: storage.SyncRuleState.ACTIVE, type: 'varchar' }}
|
|
255
|
-
`.execute();
|
|
256
|
-
}
|
|
257
|
-
else if (next != null && active?.content.replicationStreamId == replicationStreamId) {
|
|
258
|
-
// Already have "next" replication stream - don't update any.
|
|
259
|
-
// Pro-actively stop replicating, but still serve clients with existing data
|
|
260
|
-
await this.db.sql `
|
|
261
|
-
UPDATE sync_rules
|
|
262
|
-
SET
|
|
263
|
-
state = ${{ value: storage.SyncRuleState.ERRORED, type: 'varchar' }}
|
|
237
|
+
await this.db.transaction(async (db) => {
|
|
238
|
+
// Protect the absence of pending work as well as existing rows. Deployments and activation
|
|
239
|
+
// take ROW EXCLUSIVE locks, so neither can change the decision before recovery commits.
|
|
240
|
+
await db.sql `LOCK TABLE sync_rules IN SHARE ROW EXCLUSIVE MODE`.execute();
|
|
241
|
+
const rows = await db.sql `
|
|
242
|
+
SELECT
|
|
243
|
+
*
|
|
244
|
+
FROM
|
|
245
|
+
sync_rules
|
|
264
246
|
WHERE
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
247
|
+
state IN (
|
|
248
|
+
${{ value: storage.SyncRuleState.PROCESSING, type: 'varchar' }},
|
|
249
|
+
${{ value: storage.SyncRuleState.ACTIVE, type: 'varchar' }},
|
|
250
|
+
${{ value: storage.SyncRuleState.ERRORED, type: 'varchar' }}
|
|
251
|
+
)
|
|
252
|
+
ORDER BY
|
|
253
|
+
id DESC
|
|
254
|
+
`
|
|
255
|
+
.decoded(models.SyncRules)
|
|
256
|
+
.rows();
|
|
257
|
+
const next = rows.find((row) => row.state === storage.SyncRuleState.PROCESSING);
|
|
258
|
+
const active = rows.find((row) => row.state === storage.SyncRuleState.ACTIVE || row.state === storage.SyncRuleState.ERRORED);
|
|
259
|
+
if (next?.id === replicationStreamId) {
|
|
260
|
+
// Replace the failed pending stream only while it is still the current deployment.
|
|
261
|
+
await this.updateSyncRulesInTransaction(this.resolvedSyncConfigFromRow(next).content.asUpdateOptions(), db);
|
|
262
|
+
}
|
|
263
|
+
else if (active?.id === replicationStreamId) {
|
|
264
|
+
if (next == null) {
|
|
265
|
+
await this.updateSyncRulesInTransaction(this.resolvedSyncConfigFromRow(active).content.asUpdateOptions(), db);
|
|
266
|
+
}
|
|
267
|
+
// Keep serving the old data, but stop replication. An existing newer deployment takes
|
|
268
|
+
// precedence over recovery and must remain eligible to activate.
|
|
269
|
+
await db.sql `
|
|
270
|
+
UPDATE sync_rules
|
|
271
|
+
SET
|
|
272
|
+
state = ${{ value: storage.SyncRuleState.ERRORED, type: 'varchar' }}
|
|
273
|
+
WHERE
|
|
274
|
+
id = ${{ value: active.id, type: 'int4' }}
|
|
275
|
+
AND state = ${{ value: storage.SyncRuleState.ACTIVE, type: 'varchar' }}
|
|
276
|
+
`.execute();
|
|
277
|
+
}
|
|
278
|
+
});
|
|
269
279
|
}
|
|
270
280
|
async getActiveSyncConfig() {
|
|
271
281
|
const activeRow = await this.db.sql `
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostgresBucketStorageFactory.js","sourceRoot":"","sources":["../../src/storage/PostgresBucketStorageFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAqB,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAEhF,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC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MAAM,MAAM,GAAG,IAAI,kCAAkC,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;QACpE,MAAM,OAAO,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;QAC5C,MAAM,WAAW,GAAG,IAAI,CAAC;QAEzB,OAAO;YACL,OAAO;YACP,iBAAiB,EAAE,MAAM;YACzB,IAAI,OAAO;gBACT,gDAAgD;gBAChD,+FAA+F;gBAC/F,wBAAwB;gBACxB,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;oBAC/B,MAAM,kBAAkB,GAAG,WAAW,CAAC,kBAAkB,CAAC;oBAC1D,IAAI,kBAAkB,EAAE,mBAAmB,IAAI,MAAM,CAAC,mBAAmB,EAAE,CAAC;wBAC1E,OAAO,kBAAkB,CAAC;oBAC5B,CAAC;gBACH,CAAC;gBAED,MAAM,QAAQ,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;gBACjD,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;oBAC/B,WAAW,CAAC,kBAAkB,GAAG,QAAQ,CAAC;gBAC5C,CAAC;gBACD,OAAO,QAAQ,CAAC;YAClB,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
2
2
|
import { logger } from '@powersync/lib-services-framework';
|
|
3
|
-
import { toInteger } from 'ix/util/tointeger.js';
|
|
4
3
|
import { v4 } from 'uuid';
|
|
5
4
|
import { SdkReporting } from '../types/models/SdkReporting.js';
|
|
6
5
|
import { getStorageApplicationName } from '../utils/application-name.js';
|
|
@@ -300,7 +299,7 @@ export class PostgresReportStorage {
|
|
|
300
299
|
)
|
|
301
300
|
);
|
|
302
301
|
`.execute();
|
|
303
|
-
const deletedRows =
|
|
302
|
+
const deletedRows = Number(result.results[1].status.split(' ')[1] || '0');
|
|
304
303
|
if (deletedRows > 0) {
|
|
305
304
|
logger.info(`TTL from ${date.toISOString()}: ${deletedRows} PostgresSQL rows have been removed from connection_report_events.`);
|
|
306
305
|
}
|