-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdateTable.js
More file actions
45 lines (40 loc) · 1.62 KB
/
updateTable.js
File metadata and controls
45 lines (40 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*jslint node: true */
"use strict";
/**
* @description:
* 第一次更新sqlite数据库
* 初始化版本号version=1
* @author: lhp
* @time: 2019-07-16 11:04
*/
var VERSION = 2;
var async = require('async');
var bCordova = (typeof window === 'object' && window.cordova);
console.log('bCordova: ',bCordova)
function migrateDb(connection, onDone){
connection.db[bCordova ? 'query' : 'all']("PRAGMA user_version", function(err, result){
if (err)
throw Error("PRAGMA user_version failed: "+err);
var rows = bCordova ? result.rows : result;
var version = rows[0].user_version;
console.log("db version "+version+", software version "+VERSION);
if(VERSION == version){
return onDone();
}
var arrQueries = [];
if( version < 1 || version == 18){
connection.addQuery(arrQueries, "ALTER TABLE transactions_index ADD COLUMN sysTableIndex INTEGER DEFAULT 0");
connection.addQuery(arrQueries, "ALTER TABLE transactions_index ADD COLUMN sysOffset INTEGER DEFAULT 0");
connection.addQuery(arrQueries, "ALTER TABLE transactions ADD COLUMN tranType INTEGER DEFAULT 1");
}
if(version < 2 || version == 18){
connection.addQuery(arrQueries, "ALTER TABLE transactions ADD COLUMN executionResult CHAR ");
connection.addQuery(arrQueries, "ALTER TABLE transactions ADD COLUMN error CHAR ");
}
connection.addQuery(arrQueries, "PRAGMA user_version="+VERSION);
async.series(arrQueries, function(){
onDone();
});
});
}
exports.migrateDb = migrateDb;