|
|
@ -131,7 +131,7 @@ class Database {
|
|
|
|
console.info("Latest database version: " + this.latestVersion);
|
|
|
|
console.info("Latest database version: " + this.latestVersion);
|
|
|
|
|
|
|
|
|
|
|
|
if (version === this.latestVersion) {
|
|
|
|
if (version === this.latestVersion) {
|
|
|
|
console.info("Database no need to patch");
|
|
|
|
console.info("Database patch not needed");
|
|
|
|
} else if (version > this.latestVersion) {
|
|
|
|
} else if (version > this.latestVersion) {
|
|
|
|
console.info("Warning: Database version is newer than expected");
|
|
|
|
console.info("Warning: Database version is newer than expected");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -152,8 +152,8 @@ class Database {
|
|
|
|
await Database.close();
|
|
|
|
await Database.close();
|
|
|
|
|
|
|
|
|
|
|
|
console.error(ex);
|
|
|
|
console.error(ex);
|
|
|
|
console.error("Start Uptime-Kuma failed due to patch db failed");
|
|
|
|
console.error("Start Uptime-Kuma failed due to issue patching the database");
|
|
|
|
console.error("Please submit the bug report if you still encounter the problem after restart: https://github.com/louislam/uptime-kuma/issues");
|
|
|
|
console.error("Please submit a bug report if you still encounter the problem after restart: https://github.com/louislam/uptime-kuma/issues");
|
|
|
|
|
|
|
|
|
|
|
|
this.restore();
|
|
|
|
this.restore();
|
|
|
|
process.exit(1);
|
|
|
|
process.exit(1);
|
|
|
@ -191,7 +191,7 @@ class Database {
|
|
|
|
await Database.close();
|
|
|
|
await Database.close();
|
|
|
|
|
|
|
|
|
|
|
|
console.error(ex);
|
|
|
|
console.error(ex);
|
|
|
|
console.error("Start Uptime-Kuma failed due to patch db failed");
|
|
|
|
console.error("Start Uptime-Kuma failed due to issue patching the database");
|
|
|
|
console.error("Please submit the bug report if you still encounter the problem after restart: https://github.com/louislam/uptime-kuma/issues");
|
|
|
|
console.error("Please submit the bug report if you still encounter the problem after restart: https://github.com/louislam/uptime-kuma/issues");
|
|
|
|
|
|
|
|
|
|
|
|
this.restore();
|
|
|
|
this.restore();
|
|
|
@ -232,7 +232,7 @@ class Database {
|
|
|
|
this.patched = true;
|
|
|
|
this.patched = true;
|
|
|
|
await this.importSQLFile("./db/" + sqlFilename);
|
|
|
|
await this.importSQLFile("./db/" + sqlFilename);
|
|
|
|
databasePatchedFiles[sqlFilename] = true;
|
|
|
|
databasePatchedFiles[sqlFilename] = true;
|
|
|
|
console.log(sqlFilename + " is patched successfully");
|
|
|
|
console.log(sqlFilename + " was patched successfully");
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
debug(sqlFilename + " is already patched, skip");
|
|
|
|
debug(sqlFilename + " is already patched, skip");
|
|
|
@ -287,7 +287,7 @@ class Database {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
process.addListener("unhandledRejection", listener);
|
|
|
|
process.addListener("unhandledRejection", listener);
|
|
|
|
|
|
|
|
|
|
|
|
console.log("Closing DB");
|
|
|
|
console.log("Closing the database");
|
|
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
while (true) {
|
|
|
|
Database.noReject = true;
|
|
|
|
Database.noReject = true;
|
|
|
@ -297,7 +297,7 @@ class Database {
|
|
|
|
if (Database.noReject) {
|
|
|
|
if (Database.noReject) {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
console.log("Waiting to close the db");
|
|
|
|
console.log("Waiting to close the database");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log("SQLite closed");
|
|
|
|
console.log("SQLite closed");
|
|
|
@ -312,7 +312,7 @@ class Database {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static backup(version) {
|
|
|
|
static backup(version) {
|
|
|
|
if (! this.backupPath) {
|
|
|
|
if (! this.backupPath) {
|
|
|
|
console.info("Backup the db");
|
|
|
|
console.info("Backup the database");
|
|
|
|
this.backupPath = this.dataDir + "kuma.db.bak" + version;
|
|
|
|
this.backupPath = this.dataDir + "kuma.db.bak" + version;
|
|
|
|
fs.copyFileSync(Database.path, this.backupPath);
|
|
|
|
fs.copyFileSync(Database.path, this.backupPath);
|
|
|
|
|
|
|
|
|
|
|
@ -335,7 +335,7 @@ class Database {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static restore() {
|
|
|
|
static restore() {
|
|
|
|
if (this.backupPath) {
|
|
|
|
if (this.backupPath) {
|
|
|
|
console.error("Patch db failed!!! Restoring the backup");
|
|
|
|
console.error("Patching the database failed!!! Restoring the backup");
|
|
|
|
|
|
|
|
|
|
|
|
const shmPath = Database.path + "-shm";
|
|
|
|
const shmPath = Database.path + "-shm";
|
|
|
|
const walPath = Database.path + "-wal";
|
|
|
|
const walPath = Database.path + "-wal";
|
|
|
@ -354,7 +354,7 @@ class Database {
|
|
|
|
fs.unlinkSync(walPath);
|
|
|
|
fs.unlinkSync(walPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
console.log("Restore failed, you may need to restore the backup manually");
|
|
|
|
console.log("Restore failed; you may need to restore the backup manually");
|
|
|
|
process.exit(1);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|