Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

(#629) - Add boilerplate for idb upgrade migrations

  • Loading branch information...
commit 6b9fe0454f514eb334e47a75538369920ee3b944 1 parent 58e2a34
Dale  Harvey daleharvey authored
Showing with 11 additions and 3 deletions.
  1. +11 −3 src/adapters/pouch.idb.js
14 src/adapters/pouch.idb.js
View
@@ -77,10 +77,18 @@ var IdbPouch = function(opts, callback) {
console.log(name + ': Open Database');
}
- // TODO: before we release, make sure we write upgrade needed
- // in a way that supports a future upgrade path
req.onupgradeneeded = function(e) {
var db = e.target.result;
+ var currentVersion = e.oldVersion;
+ while (currentVersion !== e.newVersion) {
+ if (currentVersion === 0) {
+ createSchema(db);
+ }
+ currentVersion++;
+ }
+ };
+
+ function createSchema(db) {
db.createObjectStore(DOC_STORE, {keyPath : 'id'})
.createIndex('seq', 'seq', {unique: true});
db.createObjectStore(BY_SEQ_STORE, {autoIncrement : true})
@@ -88,7 +96,7 @@ var IdbPouch = function(opts, callback) {
db.createObjectStore(ATTACH_STORE, {keyPath: 'digest'});
db.createObjectStore(META_STORE, {keyPath: 'id', autoIncrement: false});
db.createObjectStore(DETECT_BLOB_SUPPORT_STORE);
- };
+ }
req.onsuccess = function(e) {
Please sign in to comment.
Something went wrong with that request. Please try again.