Commit d7c82cf6 authored by Timo Tegtmeier's avatar Timo Tegtmeier

Corrected db update handling

parent a270933f
...@@ -55,7 +55,7 @@ enyo.kind({ ...@@ -55,7 +55,7 @@ enyo.kind({
} }
// Initialize database. // Initialize database.
var request = this.indexedDb.open("FeedReader Database", 1); //enyo.application.versionInt); var request = this.indexedDb.open("FeedReader Database", enyo.application.versionInt);
request.onerror = enyo.bind(this, this.dbSetupFailed); request.onerror = enyo.bind(this, this.dbSetupFailed);
request.onsuccess = enyo.bind(this, this.dbReady, request); request.onsuccess = enyo.bind(this, this.dbReady, request);
request.onupgradeneeded = enyo.bind(this, this.upgradeDb); request.onupgradeneeded = enyo.bind(this, this.upgradeDb);
...@@ -83,43 +83,44 @@ enyo.kind({ ...@@ -83,43 +83,44 @@ enyo.kind({
upgradeDb: function(event) { upgradeDb: function(event) {
var db = event.currentTarget.result; var db = event.currentTarget.result;
var lastVersion = event.oldVersion;
// Setup object storages.
var categories = db.createObjectStore("categories", { keyPath: "id", autoIncrement: true }); if(lastVersion < 1) {
var feeds = db.createObjectStore("feeds", { keyPath: "id", autoIncrement: true }); // Setup object storages.
var stories = db.createObjectStore("stories", { keyPath: "id", autoIncrement: true }); var categories = db.createObjectStore("categories", { keyPath: "id", autoIncrement: true });
var feeds = db.createObjectStore("feeds", { keyPath: "id", autoIncrement: true });
// Create indexes. var stories = db.createObjectStore("stories", { keyPath: "id", autoIncrement: true });
categories.createIndex("title", "title", { unique: true });
categories.createIndex("catOrder", "catOrder", { unique: false }); // Create indexes.
categories.createIndex("catOrder", "catOrder", { unique: false });
feeds.createIndex("title", "title", { unique: false });
feeds.createIndex("feedType", "feedType", { unique: false }); feeds.createIndex("feedType", "feedType", { unique: false });
feeds.createIndex("category", "category", { unique: false }); feeds.createIndex("category", "category", { unique: false });
feeds.createIndex("feedOrder", "feedOrder", { unique: false }); feeds.createIndex("feedOrder", "feedOrder", { unique: false });
stories.createIndex("fid", "fid", { unique: false }); stories.createIndex("fid", "fid", { unique: false });
// Create default objects. // Create default objects.
categories.add(new Category({ title: "Uncategorized", catOrder: 0 })); categories.add(new Category({ title: "Uncategorized", catOrder: 0 }));
categories.add(new Category({ title: "Aggregations", catOrder: 1 })); categories.add(new Category({ title: "Aggregations", catOrder: 1 }));
feeds.add(new Feed({ feeds.add(new Feed({
title: "Starred Items", title: "Starred Items",
url: "starred", url: "starred",
feedType: feedTypes.ftStarred, feedType: feedTypes.ftStarred,
category: 2, category: 2,
feedOrder: 0, feedOrder: 0,
enabled: 1 enabled: 1
})); }));
feeds.add(new Feed({ feeds.add(new Feed({
title: "All Items", title: "All Items",
url:"allItems", url:"allItems",
feedType: feedTypes.ftAllItems, feedType: feedTypes.ftAllItems,
category: 2, category: 2,
feedOrder: 1, feedOrder: 1,
enabled: 1 enabled: 1
})); }));
}
}, },
cloneWhenNeeded: function(obj, constructor) { cloneWhenNeeded: function(obj, constructor) {
...@@ -128,13 +129,6 @@ enyo.kind({ ...@@ -128,13 +129,6 @@ enyo.kind({
return new constructor(obj); return new constructor(obj);
}, },
boundBetween: function(a, b) {
var lower = Math.min(a, b);
var upper = Math.max(a, b);
return IDBKeyRange.bound(lower, upper);
},
boundOnly: function(a) { boundOnly: function(a) {
return IDBKeyRange.only(a); return IDBKeyRange.only(a);
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment