From d6336d1bec55797667cfd61189ff6ebbd807c771 Mon Sep 17 00:00:00 2001 From: DaKheera47 Date: Fri, 2 Jan 2026 17:21:05 +0000 Subject: [PATCH] clearing db actions in settings --- orchestrator/src/client/App.tsx | 12 -- orchestrator/src/client/api/client.ts | 12 ++ orchestrator/src/client/components/Header.tsx | 31 ----- .../src/client/pages/SettingsPage.tsx | 112 +++++++++++++++++- orchestrator/src/server/api/routes.ts | 21 ++++ orchestrator/src/server/repositories/jobs.ts | 8 ++ 6 files changed, 152 insertions(+), 44 deletions(-) diff --git a/orchestrator/src/client/App.tsx b/orchestrator/src/client/App.tsx index 48b409a..0b8365d 100644 --- a/orchestrator/src/client/App.tsx +++ b/orchestrator/src/client/App.tsx @@ -151,23 +151,11 @@ export const App: React.FC = () => { } }; - const handleClearDatabase = async () => { - try { - const result = await api.clearDatabase(); - toast.success("Database cleared", { description: `Deleted ${result.jobsDeleted} jobs.` }); - await loadJobs(); - } catch (error) { - const message = error instanceof Error ? error.message : "Failed to clear database"; - toast.error(message); - } - }; - return ( <>
{ + return fetchApi<{ + message: string; + count: number; + }>(`/jobs/status/${status}`, { + method: 'DELETE', + }); +} + // Bulk operations (intentionally none - processing is manual) diff --git a/orchestrator/src/client/components/Header.tsx b/orchestrator/src/client/components/Header.tsx index 0e6f579..057174b 100644 --- a/orchestrator/src/client/components/Header.tsx +++ b/orchestrator/src/client/components/Header.tsx @@ -40,7 +40,6 @@ import type { JobSource } from "../../shared/types"; interface HeaderProps { onRunPipeline: () => void; onRefresh: () => void; - onClearDatabase: () => void; isPipelineRunning: boolean; isLoading: boolean; pipelineSources: JobSource[]; @@ -50,7 +49,6 @@ interface HeaderProps { export const Header: React.FC = ({ onRunPipeline, onRefresh, - onClearDatabase, isPipelineRunning, isLoading, pipelineSources, @@ -91,35 +89,6 @@ export const Header: React.FC = ({
- - - - - - - Clear all jobs? - - This deletes all jobs from the database. This action cannot be - undone. - - - - Cancel - - Clear database - - - - -
+ + + + Danger Zone + + Irreversible actions that modify your database. + + + +
+
+
Clear Discovered Jobs
+
+ Delete all jobs with the status "discovered". Ready, applied, and rejected jobs are kept. +
+
+ + + + + + + Clear discovered jobs? + + This deletes all jobs with the status "discovered". This action cannot be undone. + + + + Cancel + + Clear discovered + + + + +
+ + + +
+
+
Clear Database
+
+ Delete all jobs and pipeline runs from the database. +
+
+ + + + + + + Clear all jobs? + + This deletes all jobs and pipeline runs from the database. This action cannot be undone. + + + + Cancel + + Clear database + + + + +
+
+
) } diff --git a/orchestrator/src/server/api/routes.ts b/orchestrator/src/server/api/routes.ts index d245d29..0a9584d 100644 --- a/orchestrator/src/server/api/routes.ts +++ b/orchestrator/src/server/api/routes.ts @@ -632,6 +632,27 @@ apiRouter.post('/webhook/trigger', async (req: Request, res: Response) => { } }); +/** + * DELETE /api/jobs/status/:status - Clear jobs with a specific status + */ +apiRouter.delete('/jobs/status/:status', async (req: Request, res: Response) => { + try { + const status = req.params.status as JobStatus; + const count = await jobsRepo.deleteJobsByStatus(status); + + res.json({ + success: true, + data: { + message: `Cleared ${count} ${status} jobs`, + count, + } + }); + } catch (error) { + const message = error instanceof Error ? error.message : 'Unknown error'; + res.status(500).json({ success: false, error: message }); + } +}); + // ============================================================================ // Database Management // ============================================================================ diff --git a/orchestrator/src/server/repositories/jobs.ts b/orchestrator/src/server/repositories/jobs.ts index 403d336..b6b0ba0 100644 --- a/orchestrator/src/server/repositories/jobs.ts +++ b/orchestrator/src/server/repositories/jobs.ts @@ -209,6 +209,14 @@ export async function getUnscoredDiscoveredJobs(limit?: number): Promise return rows.map(mapRowToJob); } +/** + * Delete jobs by status. + */ +export async function deleteJobsByStatus(status: JobStatus): Promise { + const result = await db.delete(jobs).where(eq(jobs.status, status)).run(); + return result.changes; +} + // Helper to map database row to Job type function mapRowToJob(row: typeof jobs.$inferSelect): Job { return {