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

Commit

Permalink
Remove unused data from db
Browse files Browse the repository at this point in the history
  • Loading branch information
freaktechnik committed Aug 29, 2017
1 parent 3aa5b39 commit a43d1e6
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/read-channel-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import EventTarget from 'event-target-shim';
* @const {number}
* @default 2
*/
const VERSION = 2,
const VERSION = 3,
/**
* Database name.
*
Expand Down Expand Up @@ -108,7 +108,7 @@ export default class ReadChannelList extends EventTarget {
request.onupgradeneeded = (e) => {
this.db = e.target.result;

if(e.oldVersion != 1) {
if(e.oldVersion != 1 && e.oldVersion != 2) {
const users = this.db.createObjectStore("users", { keyPath: "id", autoIncrement: true }),
channels = this.db.createObjectStore("channels", { keyPath: "id", autoIncrement: true });
users.createIndex("typename", [ "type", "login" ], { unique: true });
Expand All @@ -118,6 +118,29 @@ export default class ReadChannelList extends EventTarget {
channels.createIndex("type", "type", { unique: false });
//channels.createIndex("id", "id", { unique: true });
}
else if(e.oldVersion === 2) {
const channels = e.target.transaction.objectStore("channels"),
request = channels.openCursor();
request.onsuccess = (event) => {
const cursor = event.target.result;
if(cursor) {
const channel = cursor.value;
if(channel.live.alternateUsername || channel.live.alternateURL) {
channel.live.state = -1;
}
if(channel.live.alternateUsername) {
delete channel.live.alternateUsername;
}
if(channel.live.alternateURL) {
delete channel.live.alternateURL;
}
const r = cursor.update(channel);
r.onerror = reject;
cursor.continue();
}
};
request.onerror = reject;
}
};

// DB is ready
Expand Down

0 comments on commit a43d1e6

Please sign in to comment.