feat: purge import history by retention
This commit is contained in:
21
server/db.ts
21
server/db.ts
@@ -1,4 +1,4 @@
|
||||
import { eq, and, desc, sql, inArray, getTableColumns, count } from "drizzle-orm";
|
||||
import { eq, and, desc, sql, inArray, getTableColumns, count, lt } from "drizzle-orm";
|
||||
import { drizzle } from "drizzle-orm/mysql2";
|
||||
import {
|
||||
InsertUser,
|
||||
@@ -628,6 +628,25 @@ export async function deleteAllImportLogs(userId: number | null): Promise<void>
|
||||
}
|
||||
}
|
||||
|
||||
/** Compte les seuls journaux d'import qui seront concernés par une purge de rétention. */
|
||||
export async function countImportLogsBefore(cutoff: Date): Promise<number> {
|
||||
const db = await getDb();
|
||||
if (!db) return 0;
|
||||
const [result] = await db.select({ total: count() }).from(importLogs).where(lt(importLogs.importedAt, cutoff));
|
||||
return Number(result?.total ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime uniquement les journaux d'import antérieurs à la borne donnée.
|
||||
* Les factures, fichiers source et PDF ne sont jamais modifiés.
|
||||
*/
|
||||
export async function deleteImportLogsBefore(cutoff: Date): Promise<number> {
|
||||
const db = await getDb();
|
||||
if (!db) throw new Error("Database not available");
|
||||
const result = await db.delete(importLogs).where(lt(importLogs.importedAt, cutoff));
|
||||
return Number(result[0]?.affectedRows ?? 0);
|
||||
}
|
||||
|
||||
// ============= LLM LOG OPERATIONS =============
|
||||
|
||||
export async function createLlmLog(data: InsertLlmLog): Promise<LlmLog> {
|
||||
|
||||
Reference in New Issue
Block a user