Skip to content

Commit 3d8db1c

Browse files
committed
Bugfix
- For the max version check in .commit(), we should query the snapshot table, not the ops table. (Op versions start from 0, whereas snapshot versions start from 1)
1 parent 9e33580 commit 3d8db1c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ PostgresDB.prototype.commit = function(collection, id, op, snapshot, options, ca
5757
}
5858
})
5959
}
60+
// ZW: Op versions start from 0, snapshot versions start from 1. To get
61+
// the next snapshot version, we should query the snapshots table, not
62+
// the ops table.
63+
// (cf: the MemoryDB adapter, which uses the number of op rows, rather
64+
// than the highest op version)
6065
client.query(
61-
'SELECT max(version) AS max_version FROM ops WHERE collection = $1 AND doc_id = $2',
66+
'SELECT max(version) AS max_version FROM snapshots WHERE collection = $1 AND doc_id = $2',
6267
[collection, id],
6368
function(err, res) {
6469
var max_version = res.rows[0].max_version;

0 commit comments

Comments
 (0)