mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-14 15:37:07 +03:00
Added schema upgrades for both DBs
This commit is contained in:
@@ -24,6 +24,11 @@ CREATE TABLE IF NOT EXISTS "sponsorTimes" (
|
|||||||
"timeSubmitted" INTEGER NOT NULL
|
"timeSubmitted" INTEGER NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "config" (
|
||||||
|
"key" TEXT NOT NULL,
|
||||||
|
"value" TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS sponsorTimes_hashedIP on sponsorTimes(hashedIP);
|
CREATE INDEX IF NOT EXISTS sponsorTimes_hashedIP on sponsorTimes(hashedIP);
|
||||||
CREATE INDEX IF NOT EXISTS votes_userID on votes(UUID);
|
CREATE INDEX IF NOT EXISTS votes_userID on votes(UUID);
|
||||||
|
|
||||||
|
|||||||
@@ -26,16 +26,8 @@ if (config.createDatabaseIfNotExist && !config.readOnly) {
|
|||||||
|
|
||||||
// Upgrade database if required
|
// Upgrade database if required
|
||||||
if (!config.readOnly) {
|
if (!config.readOnly) {
|
||||||
let versionCodeInfo = db.prepare("SELECT value FROM config WHERE key = ?").get("version");
|
ugradeDB(db, "sponsorTimes");
|
||||||
let versionCode = versionCodeInfo ? versionCodeInfo.value : 0;
|
ugradeDB(privateDB, "private")
|
||||||
|
|
||||||
let path = config.schemaFolder + "/_upgrade_" + (versionCode + 1) + ".sql";
|
|
||||||
while (fs.existsSync(path)) {
|
|
||||||
db.exec(fs.readFileSync(path).toString());
|
|
||||||
|
|
||||||
versionCode = db.prepare("SELECT value FROM config WHERE key = ?").get("version").value;
|
|
||||||
path = config.schemaFolder + "/_upgrade_" + (versionCode + 1) + ".sql";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable WAL mode checkpoint number
|
// Enable WAL mode checkpoint number
|
||||||
@@ -51,4 +43,17 @@ privateDB.exec("pragma mmap_size= 500000000;");
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
db: db,
|
db: db,
|
||||||
privateDB: privateDB
|
privateDB: privateDB
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function ugradeDB(db, prefix) {
|
||||||
|
let versionCodeInfo = db.prepare("SELECT value FROM config WHERE key = ?").get("version");
|
||||||
|
let versionCode = versionCodeInfo ? versionCodeInfo.value : 0;
|
||||||
|
|
||||||
|
let path = config.schemaFolder + "/_upgrade_" + prefix + "_" + (versionCode + 1) + ".sql";
|
||||||
|
while (fs.existsSync(path)) {
|
||||||
|
db.exec(fs.readFileSync(path).toString());
|
||||||
|
|
||||||
|
versionCode = db.prepare("SELECT value FROM config WHERE key = ?").get("version").value;
|
||||||
|
path = config.schemaFolder + "/_upgrade_" + prefix + "_" + (versionCode + 1) + ".sql";
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user