feat(database): exclude soft-deleted databases from all list queries

This commit is contained in:
charles-gauthereau
2026-07-05 18:31:52 +02:00
parent 64b3bf1b16
commit 8f2d6f0b01
7 changed files with 33 additions and 16 deletions
@@ -3,7 +3,7 @@ import {userAction} from "@/lib/safe-actions/actions";
import {z} from "zod";
import {ServerActionResult} from "@/types/action-type";
import {db} from "@/db";
import {and, eq, inArray} from "drizzle-orm";
import {and, eq, inArray, isNull} from "drizzle-orm";
import * as drizzleDb from "@/db";
import {AgentWith} from "@/db/schema/08_agent";
import {withUpdatedAt} from "@/db/utils";
@@ -25,7 +25,9 @@ export const updateAgentOrganizationsAction = userAction
where: eq(drizzleDb.schemas.agent.id, agentId),
with: {
organizations: true,
databases: true
databases: {
where: isNull(drizzleDb.schemas.database.deletedAt),
},
}
}) as AgentWith;
@@ -70,7 +72,7 @@ export const updateAgentOrganizationsAction = userAction
if (projectIds.length > 0) {
const databases = await db.query.database.findMany({
where: (db, { inArray }) => inArray(db.projectId, projectIds),
where: (db, { inArray, and, isNull }) => and(inArray(db.projectId, projectIds), isNull(db.deletedAt)),
columns: { id: true }
});
+4 -2
View File
@@ -2,7 +2,7 @@
import {action, ActionError, userAction} from "@/lib/safe-actions/actions";
import {AgentSchema} from "@/features/agents/schemas/agents.schema";
import {z} from "zod";
import {eq, and, ne, count, desc} from "drizzle-orm";
import {eq, and, ne, count, desc, isNull} from "drizzle-orm";
import {db} from "@/db";
import * as drizzleDb from "@/db";
import {slugify} from "@/utils/slugify";
@@ -87,7 +87,9 @@ export const getAgentAction = userAction.schema(z.string()).action(async ({parse
const agent = await db.query.agent.findFirst({
where: eq(drizzleDb.schemas.agent.id, parsedInput),
with: {
databases: true
databases: {
where: isNull(drizzleDb.schemas.database.deletedAt),
},
}
});