Files
PaperClipAI/packages/db/src/schema/run_identity_contexts.ts
T
DottaandPaperclip 6abeb67334 feat: add opt-in chat provider and data foundation (#13100)
Add dormant provider contracts, qualified patched adapters, tenant-scoped persistence and lifecycle ownership without activating chat routes. Preserve the experimental integration as dependent PR #13038.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-09-09 13:49:12 -05:00

60 lines
1.8 KiB
TypeScript

import {
pgTable,
uuid,
text,
integer,
timestamp,
jsonb,
uniqueIndex,
index,
} from "drizzle-orm/pg-core";
import { companies } from "./companies.js";
/** Immutable attribution records. Only acceptance state and redacted diagnostics advance. */
export const runIdentityContexts = pgTable(
"run_identity_contexts",
{
id: uuid("id").primaryKey().defaultRandom(),
companyId: uuid("company_id")
.notNull()
.references(() => companies.id, { onDelete: "cascade" }),
// Retain attribution after an agent and its runs are deleted: surviving tasks
// and approvals still reference these contexts. The original run UUID is archival.
runId: uuid("run_id").notNull(),
revision: integer("revision").notNull(),
responsibleUserId: text("responsible_user_id"),
messageId: uuid("message_id"),
parentContextId: uuid("parent_context_id"),
cause: text("cause").notNull(),
correlationId: text("correlation_id").notNull(),
status: text("status").notNull().default("accepted"),
acceptedAt: timestamp("accepted_at", { withTimezone: true }),
github: jsonb("github").$type<{
status: "available" | "absent" | "unavailable";
login?: string;
source?: "personal" | "dedicated";
reason?: string;
connectionId?: string;
grantId?: string;
authenticationMode?: "managed" | "host" | "anonymous";
}>(),
createdAt: timestamp("created_at", { withTimezone: true })
.notNull()
.defaultNow(),
},
(t) => ({
revisionIdx: uniqueIndex("run_identity_contexts_run_revision_idx").on(
t.runId,
t.revision,
),
correlationIdx: uniqueIndex("run_identity_contexts_run_correlation_idx").on(
t.runId,
t.correlationId,
),
companyRunIdx: index("run_identity_contexts_company_run_idx").on(
t.companyId,
t.runId,
),
}),
);