Delete all the db creation old code to start from scratch
parent
f686b93168
commit
5b1fe6918b
|
@ -813,7 +813,7 @@ function setArticleRead( server, id, read )
|
|||
Internal functions
|
||||
*/
|
||||
|
||||
var DBVERSION = "0.3"
|
||||
var DBVERSION = "0.5";
|
||||
var _db = null;
|
||||
|
||||
function getDatabase()
|
||||
|
@ -827,29 +827,18 @@ function getDatabase()
|
|||
return _db;
|
||||
}
|
||||
|
||||
function checkDatabaseStatus( db )
|
||||
{
|
||||
if ( db.version === "" ) {
|
||||
function checkDatabaseStatus(db) {
|
||||
if (db.version === "") {
|
||||
createLatestDatabase( db );
|
||||
}
|
||||
// _updateSchema_v* will take care of calling the relevant update methods
|
||||
// to bring the database to the latest version
|
||||
else if ( db.version === "0.2" ) {
|
||||
_updateSchema_v3( db );
|
||||
}
|
||||
else if ( db.version === "0.3" ) {
|
||||
_updateSchema_v4( db )
|
||||
}
|
||||
}
|
||||
|
||||
function createLatestDatabase( db )
|
||||
{
|
||||
function createLatestDatabase(db) {
|
||||
var version = db.version;
|
||||
|
||||
if ( version !== DBVERSION ) {
|
||||
db.transaction(
|
||||
function( tx ) {
|
||||
tx.executeSql( "CREATE TABLE IF NOT EXISTS servers (" +
|
||||
function(tx) {
|
||||
tx.executeSql("CREATE TABLE IF NOT EXISTS servers (" +
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||
"name TEXT NOT NULL, " +
|
||||
"url TEXT NOT NULL, " +
|
||||
|
@ -857,12 +846,12 @@ function createLatestDatabase( db )
|
|||
"password TEXT NOT NULL, " +
|
||||
"clientId TEXT NOT NULL, " +
|
||||
"clientSecret TEXT NOT NULL, " +
|
||||
"fetchUnread INTEGER DEFAULT 0, " +
|
||||
"lastSync INTEGER DEFAULT 0" +
|
||||
")"
|
||||
);
|
||||
|
||||
tx.executeSql(
|
||||
"CREATE TABLE IF NOT EXISTS articles (" +
|
||||
tx.executeSql("CREATE TABLE IF NOT EXISTS articles (" +
|
||||
"id INTEGER, " +
|
||||
"server INTEGER REFERENCES servers(id), " +
|
||||
"created TEXT, " +
|
||||
|
@ -881,10 +870,9 @@ function createLatestDatabase( db )
|
|||
")"
|
||||
);
|
||||
|
||||
db.changeVersion( version, DBVERSION );
|
||||
db.changeVersion(version, DBVERSION);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function resetDatabase()
|
||||
|
@ -902,57 +890,3 @@ function resetDatabase()
|
|||
);
|
||||
}
|
||||
|
||||
function _updateSchema_v3( db )
|
||||
{
|
||||
db.transaction(
|
||||
function( tx ) {
|
||||
tx.executeSql(
|
||||
"CREATE TABLE IF NOT EXISTS articles_next (" +
|
||||
"id INTEGER, " +
|
||||
"server INTEGER REFERENCES servers(id), " +
|
||||
"created TEXT, " +
|
||||
"updated TEXT, " +
|
||||
"mimetype TEXT, " +
|
||||
"language TEXT, " +
|
||||
"readingTime INTEGER DEFAULT 0, " +
|
||||
"url TEXT, " +
|
||||
"domain TEXT, " +
|
||||
"archived INTEGER DEFAULT 0, " +
|
||||
"starred INTEGER DEFAULT 0, " +
|
||||
"title TEXT, " +
|
||||
"previewPicture BLOB, " +
|
||||
"content TEXT, " +
|
||||
"PRIMARY KEY(id, server)" +
|
||||
")"
|
||||
);
|
||||
tx.executeSql( "INSERT INTO articles_next SELECT * FROM articles" );
|
||||
tx.executeSql( "DROP TABLE articles" );
|
||||
tx.executeSql( "ALTER TABLE articles_next RENAME TO articles" );
|
||||
|
||||
db.changeVersion( db.version, "0.3" );
|
||||
_updateSchema_v4( db )
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
var errorFlag = false;
|
||||
function _updateSchema_v4( db )
|
||||
{
|
||||
db.transaction(
|
||||
function ( tx ) {
|
||||
try {
|
||||
tx.executeSql( "ALTER TABLE servers ADD COLUMN fetchUnread INTEGER DEFAULT 0" );
|
||||
tx.executeSql( "UPDATE servers SET fetchUnread=0" );
|
||||
} catch ( e ) {
|
||||
if ( errorFlag ) throw e;
|
||||
|
||||
errorFlag = true;
|
||||
resetDatabase();
|
||||
_updateSchema_v4( db );
|
||||
}
|
||||
|
||||
db.changeVersion( db.version, "0.4" );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue