Skip to content
This repository has been archived by the owner on Feb 4, 2021. It is now read-only.

Commit

Permalink
I think that's all needed to upgrade to the new state stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
freaktechnik committed May 2, 2016
1 parent cf535b1 commit bf53029
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions lib/channel/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
/**
* IndexedDB version
* @const {number}
* @default 1
* @default 2
*/
const VERSION = 1;
const VERSION = 2;

/**
* Database name
Expand Down Expand Up @@ -146,14 +146,29 @@ ChannelList.prototype.openDB = function(name, dontTry = false) {
// Set up DB
request.onupgradeneeded = (e) => {
this.db = e.target.result;
let users = this.db.createObjectStore("users", { keyPath: "id", autoIncrement: true });
users.createIndex("typename", ["type","login"], { unique: true });
users.createIndex("type", "type", { unique: false });
//users.createIndex("id", "id", { unique: true });
let channels = this.db.createObjectStore("channels", { keyPath: "id", autoIncrement: true });
channels.createIndex("typename", ["type","login"], { unique: true });
channels.createIndex("type", "type", { unique: false });
//channels.createIndex("id", "id", { unique: true });
if(e.oldVersion == 1) {
const channels = e.target.transaction.objectStore("channels");
const request = channels.openCursor();

request.onsuccess = (event) => {
const cursor = event.target.result;
if(cursor) {
const channel = cursor.value;
channel.live = (new LiveState()).serialize();
channels.put(channel);
}
};
}
else {
const users = this.db.createObjectStore("users", { keyPath: "id", autoIncrement: true });
users.createIndex("typename", ["type","login"], { unique: true });
users.createIndex("type", "type", { unique: false });
//users.createIndex("id", "id", { unique: true });
const channels = this.db.createObjectStore("channels", { keyPath: "id", autoIncrement: true });
channels.createIndex("typename", ["type","login"], { unique: true });
channels.createIndex("type", "type", { unique: false });
//channels.createIndex("id", "id", { unique: true });
}
};

// DB is ready
Expand Down

0 comments on commit bf53029

Please sign in to comment.