remove stale native tasks on marketplace sync

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-22 17:55:14 +00:00
co-authored by Claude Opus 4.6
parent b3f1d10bc1
commit 039ea7ae71
3 changed files with 19 additions and 2 deletions
+1
View File
@@ -80,6 +80,7 @@ export {
updateTask,
deleteTask,
upsertNativeTask,
deleteNativeTasksNotIn,
} from './queries/tasks';
export {
+10 -1
View File
@@ -1,4 +1,4 @@
import { eq, or, and, isNull, sql } from 'drizzle-orm';
import { eq, or, and, isNull, notInArray, sql } from 'drizzle-orm';
import { db } from '../db';
import { tasks } from '../schema/agent-items';
@@ -73,6 +73,15 @@ export async function deleteTask(id: number) {
await db.delete(tasks).where(eq(tasks.id, id));
}
export async function deleteNativeTasksNotIn(dirNames: string[]) {
if (dirNames.length === 0) return [];
const deleted = await db
.delete(tasks)
.where(and(eq(tasks.scope, 'native'), notInArray(tasks.dirName, dirNames)))
.returning({ dirName: tasks.dirName });
return deleted;
}
export async function upsertNativeTask(data: Omit<TaskInsert, 'scope' | 'userId'>) {
const existing = await db
.select({ id: tasks.id })