feat: Implement trial event logging, archiving, experiment soft deletion, and new analytics/event data tables.

This commit is contained in:
2026-02-10 16:14:31 -05:00
parent 0f535f6887
commit a8c868ad3f
17 changed files with 1356 additions and 567 deletions

View File

@@ -1,6 +1,6 @@
import { TRPCError } from "@trpc/server";
import { randomUUID } from "crypto";
import { and, asc, count, desc, eq, inArray, sql } from "drizzle-orm";
import { and, asc, count, desc, eq, inArray, isNull, sql } from "drizzle-orm";
import { z } from "zod";
import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc";
@@ -87,7 +87,10 @@ export const experimentsRouter = createTRPCRouter({
// Check study access
await checkStudyAccess(ctx.db, userId, studyId);
const conditions = [eq(experiments.studyId, studyId)];
const conditions = [
eq(experiments.studyId, studyId),
isNull(experiments.deletedAt),
];
if (status) {
conditions.push(eq(experiments.status, status));
}
@@ -224,7 +227,10 @@ export const experimentsRouter = createTRPCRouter({
}
// Build where conditions
const conditions = [inArray(experiments.studyId, studyIds)];
const conditions = [
inArray(experiments.studyId, studyIds),
isNull(experiments.deletedAt),
];
if (status) {
conditions.push(eq(experiments.status, status));