Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/rich-shrimps-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@powersync/service-sync-rules': minor
'@powersync/service-image': minor
---

Add the `versioned_bucket_ids` option in the `config:` block for sync rules. When enabled, generated bucket ids include the version of sync rules. This allows clients to sync more efficiently after updating sync rules.
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,8 @@ export class MongoBucketBatch
if (sourceTable.syncData) {
const { results: evaluated, errors: syncErrors } = this.sync_rules.evaluateRowWithErrors({
record: after,
sourceTable
sourceTable,
bucketIdTransformer: SqlSyncRules.versionedBucketIdTransformer(`${this.group_id}`)
});

for (let error of syncErrors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,116 @@ exports[`sync - mongodb > compacting data - invalidate checkpoint 2`] = `
]
`;

exports[`sync - mongodb > encodes sync rules id in buckes for streams 1`] = `
[
{
"checkpoint": {
"buckets": [
{
"bucket": "1#test|0[]",
"checksum": 920318466,
"count": 1,
"priority": 3,
"subscriptions": [
{
"default": 0,
},
],
},
],
"last_op_id": "1",
"streams": [
{
"errors": [],
"is_default": true,
"name": "test",
},
],
"write_checkpoint": undefined,
},
},
{
"data": {
"after": "0",
"bucket": "1#test|0[]",
"data": [
{
"checksum": 920318466,
"data": "{"id":"t1","description":"Test 1"}",
"object_id": "t1",
"object_type": "test",
"op": "PUT",
"op_id": "1",
"subkey": "e5aa2ddc-1328-58fa-a000-0b5ed31eaf1a",
},
],
"has_more": false,
"next_after": "1",
},
},
{
"checkpoint_complete": {
"last_op_id": "1",
},
},
]
`;

exports[`sync - mongodb > encodes sync rules id in buckes for streams 2`] = `
[
{
"checkpoint": {
"buckets": [
{
"bucket": "2#test|0[]",
"checksum": 920318466,
"count": 1,
"priority": 3,
"subscriptions": [
{
"default": 0,
},
],
},
],
"last_op_id": "2",
"streams": [
{
"errors": [],
"is_default": true,
"name": "test",
},
],
"write_checkpoint": undefined,
},
},
{
"data": {
"after": "0",
"bucket": "2#test|0[]",
"data": [
{
"checksum": 920318466,
"data": "{"id":"t1","description":"Test 1"}",
"object_id": "t1",
"object_type": "test",
"op": "PUT",
"op_id": "2",
"subkey": "e5aa2ddc-1328-58fa-a000-0b5ed31eaf1a",
},
],
"has_more": false,
"next_after": "2",
},
},
{
"checkpoint_complete": {
"last_op_id": "2",
},
},
]
`;

exports[`sync - mongodb > expired token 1`] = `
[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,8 @@ export class PostgresBucketBatch
if (sourceTable.syncData) {
const { results: evaluated, errors: syncErrors } = this.sync_rules.evaluateRowWithErrors({
record: after,
sourceTable
sourceTable,
bucketIdTransformer: sync_rules.SqlSyncRules.versionedBucketIdTransformer(`${this.group_id}`)
});

for (const error of syncErrors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,116 @@ exports[`sync - postgres > compacting data - invalidate checkpoint 2`] = `
]
`;

exports[`sync - postgres > encodes sync rules id in buckes for streams 1`] = `
[
{
"checkpoint": {
"buckets": [
{
"bucket": "1#test|0[]",
"checksum": 920318466,
"count": 1,
"priority": 3,
"subscriptions": [
{
"default": 0,
},
],
},
],
"last_op_id": "1",
"streams": [
{
"errors": [],
"is_default": true,
"name": "test",
},
],
"write_checkpoint": undefined,
},
},
{
"data": {
"after": "0",
"bucket": "1#test|0[]",
"data": [
{
"checksum": 920318466,
"data": "{"id":"t1","description":"Test 1"}",
"object_id": "t1",
"object_type": "test",
"op": "PUT",
"op_id": "1",
"subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
},
],
"has_more": false,
"next_after": "1",
},
},
{
"checkpoint_complete": {
"last_op_id": "1",
},
},
]
`;

exports[`sync - postgres > encodes sync rules id in buckes for streams 2`] = `
[
{
"checkpoint": {
"buckets": [
{
"bucket": "2#test|0[]",
"checksum": 920318466,
"count": 1,
"priority": 3,
"subscriptions": [
{
"default": 0,
},
],
},
],
"last_op_id": "2",
"streams": [
{
"errors": [],
"is_default": true,
"name": "test",
},
],
"write_checkpoint": undefined,
},
},
{
"data": {
"after": "0",
"bucket": "2#test|0[]",
"data": [
{
"checksum": 920318466,
"data": "{"id":"t1","description":"Test 1"}",
"object_id": "t1",
"object_type": "test",
"op": "PUT",
"op_id": "2",
"subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
},
],
"has_more": false,
"next_after": "2",
},
},
{
"checkpoint_complete": {
"last_op_id": "2",
},
},
]
`;

exports[`sync - postgres > expired token 1`] = `
[
{
Expand Down
3 changes: 2 additions & 1 deletion packages/service-core-tests/src/test-utils/general-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export function querierOptions(globalParameters: RequestParameters): GetQuerierO
return {
globalParameters,
hasDefaultStreams: true,
streams: {}
streams: {},
bucketIdTransformer: SqlSyncRules.versionedBucketIdTransformer('1')
};
}
Loading