Skip to content

Commit dbdfbed

Browse files
committed
Re-adding op version bugfix
1 parent 8699d6f commit dbdfbed

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ PostgresDB.prototype.commit = function (collection, id, op, snapshot, options, c
6060
* Casting is required as postgres thinks that collection and doc_id are
6161
* not varchar
6262
*/
63+
// ZW: We also should have the first op version be 0, not 1, to match the
64+
// reference MemoryDB implementation. Catching up outdated clients who
65+
// reconnect may be buggy otherwise.
6366
const query = {
6467
name: "sdb-commit-op-and-snap",
6568
text: `WITH snapshot_id AS (
@@ -91,7 +94,7 @@ PostgresDB.prototype.commit = function (collection, id, op, snapshot, options, c
9194
FROM ops
9295
WHERE collection = $1 AND doc_id = $2
9396
)
94-
) AND EXISTS (SELECT 1 FROM snapshot_id)
97+
) AND EXISTS (SELECT 0 FROM snapshot_id)
9598
RETURNING version`,
9699
values: [collection, id, snapshot.v, snapshot.type, snapshot.data, op]
97100
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sharedb-postgres",
3-
"version": "3.0.0-zw.1",
3+
"version": "3.0.0-zw.2",
44
"description": "PostgreSQL adapter for ShareDB",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)