mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-18 05:28:27 +03:00
Merge pull request #389 from mchangrh/replication-mirror
changes for mirror mode
This commit is contained in:
@@ -4,7 +4,6 @@ import { Mysql } from "./Mysql";
|
||||
import { Postgres } from "./Postgres";
|
||||
import { IDatabase } from "./IDatabase";
|
||||
|
||||
|
||||
let db: IDatabase;
|
||||
let privateDB: IDatabase;
|
||||
if (config.mysql) {
|
||||
@@ -68,6 +67,15 @@ async function initDb(): Promise<void> {
|
||||
// Attach private db to main db
|
||||
(db as Sqlite).attachDatabase(config.privateDB, "privateDB");
|
||||
}
|
||||
|
||||
if (config.mode === "mirror" && db instanceof Postgres) {
|
||||
const tables = config?.dumpDatabase?.tables ?? [];
|
||||
const tableNames = tables.map(table => table.name);
|
||||
for (const table of tableNames) {
|
||||
const filePath = `${config?.dumpDatabase?.postgresExportPath}/${table}.csv`;
|
||||
await db.prepare("run", `COPY "${table}" FROM '${filePath}' WITH (FORMAT CSV, HEADER true);`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
|
||||
@@ -12,6 +12,9 @@ async function init() {
|
||||
});
|
||||
|
||||
await initDb();
|
||||
// edge case clause for creating compatible .db files, do not enable
|
||||
if (config.mode === "init-db-and-exit") process.exit(0);
|
||||
// do not enable init-db-only mode for usage.
|
||||
(global as any).HEADCOMMIT = config.mode === "development" ? "development"
|
||||
: config.mode === "test" ? "test"
|
||||
: getCommit() as string;
|
||||
|
||||
@@ -184,7 +184,7 @@ export async function redirectLink(req: Request, res: Response): Promise<void> {
|
||||
res.sendStatus(404);
|
||||
}
|
||||
|
||||
await queueDump();
|
||||
if (req.query.generate !== "false") await queueDump();
|
||||
}
|
||||
|
||||
function updateQueueTime(): void {
|
||||
|
||||
Reference in New Issue
Block a user