File tree Expand file tree Collapse file tree 3 files changed +12
-6
lines changed
packages/common/src/client Expand file tree Collapse file tree 3 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @powersync/common ' : patch
3+ ---
4+
5+ Fix issue where local changes could be reverted when a replication delay is present.
Original file line number Diff line number Diff line change @@ -582,12 +582,12 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
582582 if ( writeCheckpoint ) {
583583 const check = await tx . execute ( `SELECT 1 FROM ${ PSInternalTable . CRUD } LIMIT 1` ) ;
584584 if ( ! check . rows ?. length ) {
585- await tx . execute ( `UPDATE ${ PSInternalTable . BUCKETS } SET target_op = ? WHERE name='$local'` , [
585+ await tx . execute ( `UPDATE ${ PSInternalTable . BUCKETS } SET target_op = CAST(? as INTEGER) WHERE name='$local'` , [
586586 writeCheckpoint
587587 ] ) ;
588588 }
589589 } else {
590- await tx . execute ( `UPDATE ${ PSInternalTable . BUCKETS } SET target_op = ? WHERE name='$local'` , [
590+ await tx . execute ( `UPDATE ${ PSInternalTable . BUCKETS } SET target_op = CAST(? as INTEGER) WHERE name='$local'` , [
591591 this . bucketStorageAdapter . getMaxOpId ( )
592592 ] ) ;
593593 }
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
8585
8686 async getBucketStates ( ) : Promise < BucketState [ ] > {
8787 const result = await this . db . getAll < BucketState > (
88- ' SELECT name as bucket, cast(last_op as TEXT) as op_id FROM ps_buckets WHERE pending_delete = 0'
88+ " SELECT name as bucket, cast(last_op as TEXT) as op_id FROM ps_buckets WHERE pending_delete = 0 AND name != '$local'"
8989 ) ;
9090 return result ;
9191 }
@@ -249,9 +249,10 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
249249 }
250250
251251 async updateLocalTarget ( cb : ( ) => Promise < string > ) : Promise < boolean > {
252- const rs1 = await this . db . getAll ( "SELECT target_op FROM ps_buckets WHERE name = '$local' AND target_op = ?" , [
253- MAX_OP_ID
254- ] ) ;
252+ const rs1 = await this . db . getAll (
253+ "SELECT target_op FROM ps_buckets WHERE name = '$local' AND target_op = CAST(? as INTEGER)" ,
254+ [ MAX_OP_ID ]
255+ ) ;
255256 if ( ! rs1 . length ) {
256257 // Nothing to update
257258 return false ;
You can’t perform that action at this time.
0 commit comments