Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Provide an option to keep historical snapshots in the PostgresQL data…

…base adapter.
  • Loading branch information...
commit 6d09732ffee6b5a6ee4e1d950bc5c7e937f26bca 1 parent 391a94f
@nullobject nullobject authored
Showing with 13 additions and 6 deletions.
  1. +13 −6 src/server/db/pg.coffee
View
19 src/server/db/pg.coffee
@@ -30,6 +30,7 @@ defaultOptions =
create_tables_automatically: true
operations_table: 'ops'
snapshot_table: 'snapshots'
+ keep_snapshots: false
module.exports = PgDb = (options) ->
return new Db if !(this instanceof PgDb)
@@ -141,12 +142,18 @@ module.exports = PgDb = (options) ->
callback? error?.message
@writeSnapshot = (docName, docData, dbMeta, callback) ->
- sql = """
- UPDATE #{snapshot_table}
- SET "v" = $2, "snapshot" = $3, "meta" = $4
- WHERE "doc" = $1
- """
- values = [docName, docData.v, JSON.stringify(docData.snapshot), JSON.stringify(docData.meta)]
+ sql = if options.keep_snapshots
+ """
+ INSERT INTO #{snapshot_table} ("doc", "v", "snapshot", "meta", "type", "created_at")
+ VALUES ($1, $2, $3, $4, $5, now())
+ """
+ else
+ """
+ UPDATE #{snapshot_table}
+ SET "v" = $2, "snapshot" = $3, "meta" = $4
+ WHERE "doc" = $1
+ """
+ values = [docName, docData.v, JSON.stringify(docData.snapshot), JSON.stringify(docData.meta), docData.type]
client.query sql, values, (error, result) ->
if !error?
callback?()
Please sign in to comment.
Something went wrong with that request. Please try again.