2017-12-23 09:35:00 -05:00
|
|
|
"use strict";
|
|
|
|
|
2024-07-18 21:35:17 +03:00
|
|
|
import sql from "../../services/sql.js";
|
|
|
|
import log from "../../services/log.js";
|
|
|
|
import backupService from "../../services/backup.js";
|
|
|
|
import anonymizationService from "../../services/anonymization.js";
|
|
|
|
import consistencyChecksService from "../../services/consistency_checks.js";
|
2025-01-09 18:36:24 +02:00
|
|
|
import type { Request } from "express";
|
2024-07-18 21:35:17 +03:00
|
|
|
import ValidationError from "../../errors/validation_error.js";
|
2024-08-15 00:06:37 +03:00
|
|
|
import sql_init from "../../services/sql_init.js";
|
|
|
|
import becca_loader from "../../becca/becca_loader.js";
|
2018-01-07 14:07:59 -05:00
|
|
|
|
2023-10-18 23:16:47 +02:00
|
|
|
function getExistingBackups() {
|
|
|
|
return backupService.getExistingBackups();
|
2020-06-02 23:13:55 +02:00
|
|
|
}
|
|
|
|
|
2020-06-20 23:09:34 +02:00
|
|
|
async function backupDatabase() {
|
2020-05-29 21:55:08 +02:00
|
|
|
return {
|
2020-06-20 23:09:34 +02:00
|
|
|
backupFile: await backupService.backupNow("now")
|
2020-05-29 21:55:08 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
function vacuumDatabase() {
|
|
|
|
sql.execute("VACUUM");
|
2017-12-23 09:35:00 -05:00
|
|
|
|
2017-12-23 13:16:18 -05:00
|
|
|
log.info("Database has been vacuumed.");
|
2018-03-30 17:07:41 -04:00
|
|
|
}
|
2017-12-23 13:16:18 -05:00
|
|
|
|
2023-10-18 23:16:47 +02:00
|
|
|
function findAndFixConsistencyIssues() {
|
|
|
|
consistencyChecksService.runOnDemandChecks(true);
|
|
|
|
}
|
|
|
|
|
2024-08-15 00:06:37 +03:00
|
|
|
async function rebuildIntegrationTestDatabase() {
|
|
|
|
sql.rebuildIntegrationTestDatabase();
|
|
|
|
sql_init.initializeDb();
|
|
|
|
becca_loader.load();
|
|
|
|
}
|
|
|
|
|
2023-10-18 23:16:47 +02:00
|
|
|
function getExistingAnonymizedDatabases() {
|
|
|
|
return anonymizationService.getExistingAnonymizedDatabases();
|
|
|
|
}
|
|
|
|
|
2024-04-05 20:55:21 +03:00
|
|
|
async function anonymize(req: Request) {
|
|
|
|
if (req.params.type !== "full" && req.params.type !== "light") {
|
|
|
|
throw new ValidationError("Invalid type provided.");
|
|
|
|
}
|
2023-10-18 23:16:47 +02:00
|
|
|
return await anonymizationService.createAnonymizedCopy(req.params.type);
|
|
|
|
}
|
|
|
|
|
2022-02-01 21:22:43 +01:00
|
|
|
function checkIntegrity() {
|
|
|
|
const results = sql.getRows("PRAGMA integrity_check");
|
|
|
|
|
2022-12-21 15:19:05 +01:00
|
|
|
log.info(`Integrity check result: ${JSON.stringify(results)}`);
|
2022-02-01 21:22:43 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
results
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-07-18 21:47:30 +03:00
|
|
|
export default {
|
2023-10-18 23:16:47 +02:00
|
|
|
getExistingBackups,
|
2020-05-29 21:55:08 +02:00
|
|
|
backupDatabase,
|
2019-12-10 22:03:00 +01:00
|
|
|
vacuumDatabase,
|
2020-06-02 23:13:55 +02:00
|
|
|
findAndFixConsistencyIssues,
|
2024-08-15 00:06:37 +03:00
|
|
|
rebuildIntegrationTestDatabase,
|
2023-10-18 23:16:47 +02:00
|
|
|
getExistingAnonymizedDatabases,
|
2022-02-01 21:22:43 +01:00
|
|
|
anonymize,
|
|
|
|
checkIntegrity
|
2020-05-29 21:55:08 +02:00
|
|
|
};
|