Skip to content

Commit

Permalink
Second fix of the pglite-sync plugin for latest electric
Browse files Browse the repository at this point in the history
  • Loading branch information
samwillis committed Feb 12, 2025
1 parent b5368a4 commit e0cf951
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/pglite-sync/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ async function createPlugin(
shapeKey: options.shapeKey,
shapeId: shapeHandle,
lastOffset: getMessageOffset(
stream,
messageAggregator[messageAggregator.length - 1],
),
})
Expand Down Expand Up @@ -673,10 +674,15 @@ function subscriptionMetadataTableName(metadatSchema: string) {

const subscriptionTableName = `shape_subscriptions_metadata`

function getMessageOffset(message: LegacyChangeMessage<any>): Offset {
function getMessageOffset(
stream: ShapeStream,
message: LegacyChangeMessage<any>,
): Offset {
if (message.offset) {
return message.offset
} else {
} else if (message.headers.lsn && message.headers.op_position) {
return `${message.headers.lsn}_${message.headers.op_position}` as Offset
} else {
return stream.lastOffset
}
}

0 comments on commit e0cf951

Please sign in to comment.