⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
feat: search the agent chat history and star conversations (#248)
Croff6334a9c345f4
diff --git a/apps/api/src/modules/agents/chat-favorites.ts b/apps/api/src/modules/agents/chat-favorites.tsnew file mode 100644index 00000000..52008528--- /dev/null+++ b/apps/api/src/modules/agents/chat-favorites.ts@@ -0,0 +1,55 @@+import { db, agentChatFavorite } from '@repo/db';+import { and, eq, inArray } from 'drizzle-orm';++// The conversations a member starred (see the agent_chat_favorite comment in the+// schema). Both kinds of agent are starred here: the row names the thread by id, and+// the thread itself lives either in agent_chat_thread or in Mastra's tables, so the+// two stores share this module the way they share chat-usage.++// How many starred conversations the favorites group shows. The group is not paginated,+// so it is bounded here.+export const FAVORITES_LIMIT = 50;++// Which of the given threads the user starred.+export async function readFavorites(userId: string, threadIds: string[]): Promise<Set<string>> {+ if (threadIds.length === 0) return new Set();+ const rows = await db+ .select({ threadId: agentChatFavorite.threadId })+ .from(agentChatFavorite)+ .where(+ and(eq(agentChatFavorite.userId, userId), inArray(agentChatFavorite.threadId, threadIds)),+ );+ return new Set(rows.map((row) => row.threadId));+}++// The threads the user starred with one agent. Only the ids: the conversations+// themselves are read from whichever store holds them, which is also where the group+// is cut to FAVORITES_LIMIT, newest first.+export async function favoriteThreadIds(userId: string, agentId: number): Promise<string[]> {+ const rows = await db+ .select({ threadId: agentChatFavorite.threadId })+ .from(agentChatFavorite)+ .where(and(eq(agentChatFavorite.userId, userId), eq(agentChatFavorite.agentId, agentId)));+ return rows.map((row) => row.threadId);+}++// Stars a conversation. Starring one that is already starred changes nothing; the+// caller has checked the thread is theirs.+export async function addFavorite(+ userId: string,+ agentId: number,+ threadId: string,+): Promise<void> {+ await db.insert(agentChatFavorite).values({ userId, agentId, threadId }).onConflictDoNothing();+}++export async function removeFavorite(userId: string, threadId: string): Promise<void> {+ await db+ .delete(agentChatFavorite)+ .where(and(eq(agentChatFavorite.userId, userId), eq(agentChatFavorite.threadId, threadId)));+}++// The row has no foreign key to the thread, so deleting the thread has to take it along.+export async function deleteFavorite(threadId: string): Promise<void> {+ await db.delete(agentChatFavorite).where(eq(agentChatFavorite.threadId, threadId));+}diff --git a/apps/api/src/modules/agents/chat-history.ts b/apps/api/src/modules/agents/chat-history.tsnew file mode 100644index 00000000..7c800e91--- /dev/null+++ b/apps/api/src/modules/agents/chat-history.ts@@ -0,0 +1,89 @@+import { sql, type SQL } from 'drizzle-orm';+import { toIso } from './core/helpers/dates';+import { contextField, readContextSizes } from './chat-usage';+import type { ChatThreadSummary } from './model';++// The chat history list, as far as both stores build it the same way. An external+// agent's conversations are read from agent_chat_thread and an internal agent's from+// Mastra's tables, but they are searched by the same rules, ranked the same way, and+// come back as the same summaries.+//+// The list has three shapes: the starred conversations, then the rest of them a page at+// a time — a starred one is in the group and not in the page, so it is shown once — and,+// while a search is typed, its hits over all of them.++// Below this a search is not run: one character matches nearly every conversation.+const MIN_QUERY = 2;++// How much text is kept around the match, on each side, and the length that leaves.+const SNIPPET_RADIUS = 60;+const SNIPPET_LENGTH = SNIPPET_RADIUS * 2 + 40;++// What the history list is asked for: one page of the caller's conversations with the+// agent, the ones they starred (the favorites group, unpaginated), or the ones matching+// a search.+export type ThreadListOpts = {+ page?: number;+ q?: string;+ favorites?: boolean;+};++// Where a hit came from. It is read as a rank as well: the title first, then the+// conversations where the member's own message matches, then the ones matching only in+// the agent's reply.+export type ThreadMatch = 'title' | 'user' | 'assistant';++function matchOfRank(rank: number): ThreadMatch {+ if (rank === 1) return 'title';+ if (rank === 2) return 'user';+ return 'assistant';+}++// The search term, or null when there is nothing to search for.+export function searchTerm(q: string | undefined): string | null {+ const trimmed = q?.trim() ?? '';+ return trimmed.length >= MIN_QUERY ? trimmed : null;+}++// The ILIKE pattern for the term. The wildcards a member types are escaped, so a query+// with a % in it looks for that character.+export function likePattern(term: string): string {+ return `%${term.replace(/([\\%_])/g, '\\$1')}%`;+}++// The stretch of text around the first match, cut in the database: an answer can be+// 100,000 characters and must not be read into the app to show 160 of them.+export function snippetOf(text: SQL, term: string): SQL {+ return sql`substring(${text} from greatest(position(lower(${term}) in lower(${text})) - ${SNIPPET_RADIUS}, 1) for ${SNIPPET_LENGTH})`;+}++// One conversation as the two stores read it, before the parts every list adds. Each+// list knows the star of its rows without looking it up: the page leaves the starred+// ones out, the favorites group holds only those, and a search reads it per row.+export interface ThreadRow {+ id: string;+ title: string | null;+ cliSessionId: string | null;+ favorite: boolean;+ createdAt: Date | string;+ updatedAt: Date | string;+ // Set by a search: what matched, and the text around it.+ rank?: number;+ snippet?: string | null;+}++// The conversations as the list returns them, with the context size of each.+export async function summarize(rows: ThreadRow[]): Promise<ChatThreadSummary[]> {+ const sizes = await readContextSizes(rows.map((row) => row.id));+ return rows.map((row) => ({+ id: row.id,+ title: row.title && row.title.length > 0 ? row.title : null,+ cliSessionId: row.cliSessionId,+ favorite: row.favorite,+ ...(row.rank != null ? { match: matchOfRank(row.rank) } : {}),+ ...(row.snippet ? { snippet: row.snippet } : {}),+ ...contextField(sizes, row.id),+ createdAt: toIso(row.createdAt),+ updatedAt: toIso(row.updatedAt),+ }));+}diff --git a/apps/api/src/modules/agents/chat/__tests__/integration/agent-chat.test.ts b/apps/api/src/modules/agents/chat/__tests__/integration/agent-chat.test.tsindex bda4997d..14a6874b 100644--- a/apps/api/src/modules/agents/chat/__tests__/integration/agent-chat.test.ts+++ b/apps/api/src/modules/agents/chat/__tests__/integration/agent-chat.test.ts@@ -36,6 +36,16 @@ function send(api: Api, agentId: number, prompt: string, threadId?: string) {return chatOf(api, agentId).chat.post(threadId ? { prompt, threadId } : { prompt });}+// Claims the agent's queued answer and closes it with the given text, the way a runner+// does, so the conversation carries a reply the search can match.+async function answer(asRunner: Api, text: string) {+ const claimed = (await asRunner['agent-chats'].claim.post()).data!.message!;+ await asRunner['agent-chats']({ messageId: claimed.id }).events.post({+ events: [{ type: 'TEXT_MESSAGE_CONTENT', messageId: 'm1', delta: text }],+ });+ await asRunner['agent-chats']({ messageId: claimed.id }).result.post({ status: 'success' });+}+// The stream is a raw Response rather than a JSON body, so it is driven through the// app directly: Treaty has nothing to hand back for an event stream.async function readStream(@@ -513,6 +523,85 @@ describe('external agent chat', () => {expect((await chatOf(asOwner, agent.id).threads.get()).data!.items).toEqual([]);});+ it('finds a conversation by its title and by the text of both roles', async () => {+ const { asOwner, asRunner, agent } = await setup();+ const byTitle = await send(asOwner, agent.id, 'the launch plan');+ await answer(asRunner, 'noted');+ // Asked in the second turn, so the title of that conversation does not match too.+ const byQuestion = await send(asOwner, agent.id, 'status update');+ await answer(asRunner, 'all green');+ await send(asOwner, agent.id, 'when is the launch?', byQuestion.data!.threadId);+ await answer(asRunner, 'in May');+ const byAnswer = await send(asOwner, agent.id, 'what is next?');+ await answer(asRunner, 'the launch, then the retro');+ await send(asOwner, agent.id, 'invoices');+ await answer(asRunner, 'paid');++ const res = await chatOf(asOwner, agent.id).threads.get({ query: { q: 'launch' } });+ expect(res.status).toBe(200);+ // Ranked: the title first, then the member's own message, then the agent's reply.+ expect(res.data!.items.map((t) => t.id)).toEqual([+ byTitle.data!.threadId,+ byQuestion.data!.threadId,+ byAnswer.data!.threadId,+ ]);+ expect(res.data!.items.map((t) => t.match)).toEqual(['title', 'user', 'assistant']);+ expect(res.data!.items[2].snippet).toContain('the launch, then the retro');+ });++ it("does not match a tool call's arguments or result", async () => {+ const { asOwner, asRunner, agent } = await setup();+ await send(asOwner, agent.id, 'what is left?');+ const claimed = (await asRunner['agent-chats'].claim.post()).data!.message!;+ await asRunner['agent-chats']({ messageId: claimed.id }).events.post({+ events: [+ { type: 'TOOL_CALL_START', toolCallId: 'call-1', toolCallName: 'list_issues' },+ { type: 'TOOL_CALL_ARGS', toolCallId: 'call-1', delta: '{"status":"kryptonite"}' },+ { type: 'TOOL_CALL_RESULT', messageId: 'm1', toolCallId: 'call-1', content: 'kryptonite' },+ { type: 'TEXT_MESSAGE_CONTENT', messageId: 'm1', delta: 'Two things.' },+ ],+ });+ await asRunner['agent-chats']({ messageId: claimed.id }).result.post({ status: 'success' });++ const res = await chatOf(asOwner, agent.id).threads.get({ query: { q: 'kryptonite' } });+ expect(res.data!.items).toEqual([]);+ });++ it('stars a conversation, lists it as its own group, and drops the star with it', async () => {+ const { asOwner, agent } = await setup();+ const kept = await send(asOwner, agent.id, 'kept');+ const plain = await send(asOwner, agent.id, 'plain');+ const thread = chatOf(asOwner, agent.id).threads({ threadId: kept.data!.threadId });++ expect((await thread.favorite.put()).status).toBe(204);++ const favorites = await chatOf(asOwner, agent.id).threads.get({ query: { favorites: true } });+ expect(favorites.data!.items.map((t) => t.id)).toEqual([kept.data!.threadId]);+ expect(favorites.data!.nextPage).toBeNull();++ // The group holds it, so the list below no longer shows it a second time.+ const rest = await chatOf(asOwner, agent.id).threads.get();+ expect(rest.data!.items.map((t) => t.id)).toEqual([plain.data!.threadId]);++ expect((await thread.favorite.delete()).status).toBe(204);+ expect(+ (await chatOf(asOwner, agent.id).threads.get({ query: { favorites: true } })).data!.items,+ ).toEqual([]);+ const back = await chatOf(asOwner, agent.id).threads.get();+ expect(back.data!.items.map((t) => t.id)).toEqual([plain.data!.threadId, kept.data!.threadId]);+ });++ it("404s starring another member's conversation", async () => {+ const { asOwner, agent } = await setup();+ const sent = await send(asOwner, agent.id, 'Private question');+ const asMember = await addProjectMember(asOwner, 'MKT');++ expect(+ (await chatOf(asMember, agent.id).threads({ threadId: sent.data!.threadId }).favorite.put())+ .status,+ ).toBe(404);+ });+it("refuses another member's thread and another agent's answer", async () => {const { asOwner, asRunner, agent } = await setup();const sent = await send(asOwner, agent.id, 'Private question');diff --git a/apps/api/src/modules/agents/chat/service.ts b/apps/api/src/modules/agents/chat/service.tsindex 93604ce5..80ec78d7 100644--- a/apps/api/src/modules/agents/chat/service.ts+++ b/apps/api/src/modules/agents/chat/service.ts@@ -1,15 +1,18 @@-import { db, agentChatEvent, agentChatMessage, agentChatThread } from '@repo/db';-import { and, asc, desc, eq, gt, inArray, sql } from 'drizzle-orm';+import { db, agentChatEvent, agentChatFavorite, agentChatMessage, agentChatThread } from '@repo/db';+import { and, asc, desc, eq, gt, inArray, notExists, sql } from 'drizzle-orm';import { setTimeout as sleep } from 'node:timers/promises';import { iso } from '#shared/lib';-import { appendTextPart } from '../chat-parts';+import { deleteContextUsage, recordContextUsage, type ContextUsage } from '../chat-usage';+import { deleteFavorite, FAVORITES_LIMIT } from '../chat-favorites';import {- contextField,- deleteContextUsage,- readContextSizes,- recordContextUsage,- type ContextUsage,-} from '../chat-usage';+ likePattern,+ searchTerm,+ snippetOf,+ summarize,+ type ThreadListOpts,+ type ThreadRow,+} from '../chat-history';+import { appendTextPart } from '../chat-parts';import { intEnv } from '../core/helpers/env';import { attachmentPreamble, chartPreamble, projectPreamble } from '../core/prompt/framing';import { peoplePreamble, type Person } from '../core/prompt/run-context';@@ -55,31 +58,147 @@ const EVENT_PAGE = 500;// these take events, heartbeats and a result.const LIVE_STATUSES = ['pending', 'streaming'];-// One page of the caller's conversations with one external agent, newest first.+// The caller's conversations with one external agent: the favorites group, the hits of+// a search, or one page of the rest of them, newest first.export async function listThreads(userId: string,agentId: number,- page = 0,+ opts: ThreadListOpts = {},): Promise<ChatThreadPage> {+ if (opts.favorites) return favoriteThreads(userId, agentId);+ const term = searchTerm(opts.q);+ const page = opts.page ?? 0;+ const rows = term+ ? await searchThreads(userId, agentId, term, page)+ : await unstarredPage(userId, agentId, page);+ const hasMore = rows.length > PAGE_SIZE;+ const items = await summarize(hasMore ? rows.slice(0, PAGE_SIZE) : rows);+ return { items, nextPage: hasMore ? page + 1 : null };+}++// The conversations the caller starred, newest first, in one go.+async function favoriteThreads(userId: string, agentId: number): Promise<ChatThreadPage> {const rows = await db- .select()+ .select(threadColumns).from(agentChatThread)- .where(and(eq(agentChatThread.agentId, agentId), eq(agentChatThread.userId, userId)))+ .innerJoin(agentChatFavorite, eq(agentChatFavorite.threadId, agentChatThread.id))+ .where(+ and(+ eq(agentChatThread.agentId, agentId),+ eq(agentChatThread.userId, userId),+ eq(agentChatFavorite.userId, userId),+ ),+ )+ .orderBy(desc(agentChatThread.updatedAt))+ .limit(FAVORITES_LIMIT);+ return {+ items: await summarize(rows.map((row) => ({ ...row, favorite: true }))),+ nextPage: null,+ };+}++const threadColumns = {+ id: agentChatThread.id,+ title: agentChatThread.title,+ cliSessionId: agentChatThread.cliSessionId,+ createdAt: agentChatThread.createdAt,+ updatedAt: agentChatThread.updatedAt,+};++// One page of the conversations that are not starred, newest first, with one row over+// the page to tell whether there is another. The starred ones are left out because the+// group above the list already holds them.+async function unstarredPage(userId: string, agentId: number, page: number): Promise<ThreadRow[]> {+ const rows = await db+ .select(threadColumns)+ .from(agentChatThread)+ .where(+ and(+ eq(agentChatThread.agentId, agentId),+ eq(agentChatThread.userId, userId),+ notExists(+ db+ .select({ one: sql`1` })+ .from(agentChatFavorite)+ .where(+ and(+ eq(agentChatFavorite.userId, userId),+ eq(agentChatFavorite.threadId, agentChatThread.id),+ ),+ ),+ ),+ ),+ ).orderBy(desc(agentChatThread.updatedAt)).limit(PAGE_SIZE + 1).offset(page * PAGE_SIZE);- const hasMore = rows.length > PAGE_SIZE;- const threads = hasMore ? rows.slice(0, PAGE_SIZE) : rows;- const sizes = await readContextSizes(threads.map((r) => r.id));- const items = threads.map((r) => ({- id: r.id,- title: r.title && r.title.length > 0 ? r.title : null,- cliSessionId: r.cliSessionId,- ...contextField(sizes, r.id),- createdAt: iso(r.createdAt),- updatedAt: iso(r.updatedAt),- }));- return { items, nextPage: hasMore ? page + 1 : null };+ return rows.map((row) => ({ ...row, favorite: false }));+}++// The conversations whose title or messages contain the term. A tool call is not+// searched: its arguments and its result are events of their own, and the message text+// holds only what the agent wrote.+//+// The snippet is cut from the newest matching message, in the database — an answer runs+// to ANSWER_LIMIT characters. The rank puts a title hit first, then the ones where the+// member's own message matches, then the ones matching only in the agent's reply.+async function searchThreads(+ userId: string,+ agentId: number,+ term: string,+ page: number,+): Promise<ThreadRow[]> {+ const like = likePattern(term);+ const snippet = snippetOf(sql`msg.content`, term);+ const rows = await db.execute(sql`+ SELECT t.id,+ t.title,+ t.cli_session_id AS "cliSessionId",+ t.created_at AS "createdAt",+ t.updated_at AS "updatedAt",+ f.thread_id IS NOT NULL AS favorite,+ hit.snippet,+ CASE+ WHEN t.title ILIKE ${like} THEN 1+ WHEN coalesce(hit.user_match, false) THEN 2+ ELSE 3+ END AS rank+ FROM agent_chat_thread t+ LEFT JOIN agent_chat_favorite f ON f.thread_id = t.id AND f.user_id = t.user_id+ LEFT JOIN LATERAL (+ SELECT bool_or(msg.role = 'user') AS user_match,+ (array_agg(${snippet} ORDER BY msg.id DESC))[1] AS snippet+ FROM agent_chat_message msg+ WHERE msg.thread_id = t.id AND msg.content ILIKE ${like}+ ) hit ON true+ WHERE t.agent_id = ${agentId}+ AND t.user_id = ${userId}+ AND (t.title ILIKE ${like} OR hit.snippet IS NOT NULL)+ ORDER BY rank, t.updated_at DESC+ LIMIT ${PAGE_SIZE + 1} OFFSET ${page * PAGE_SIZE}+ `);+ return rows as unknown as ThreadRow[];+}++// Whether the conversation is the caller's own, and with this agent where the caller+// names one. False is a 404 for everything a thread is addressed by.+export async function ownsThread(+ threadId: string,+ userId: string,+ agentId?: number,+): Promise<boolean> {+ const rows = await db+ .select({ id: agentChatThread.id })+ .from(agentChatThread)+ .where(+ and(+ eq(agentChatThread.id, threadId),+ eq(agentChatThread.userId, userId),+ ...(agentId != null ? [eq(agentChatThread.agentId, agentId)] : []),+ ),+ )+ .limit(1);+ return rows.length > 0;}// One page of a thread's transcript, oldest first within the page, page 0 being the@@ -209,18 +328,10 @@ export async function deleteThread(threadId: string, userId: string): Promise<bo.returning({ id: agentChatThread.id });if (rows.length === 0) return false;await deleteContextUsage(threadId);+ await deleteFavorite(threadId);return true;}-async function ownsThread(threadId: string, userId: string): Promise<boolean> {- const rows = await db- .select({ id: agentChatThread.id })- .from(agentChatThread)- .where(and(eq(agentChatThread.id, threadId), eq(agentChatThread.userId, userId)))- .limit(1);- return rows.length > 0;-}-// Stores the member's message and queues the answer next to it. A thread id continues// that conversation; without one a thread is created, titled after the message. Null// when the thread named is not the caller's.diff --git a/apps/api/src/modules/agents/core/__tests__/integration/agent-threads.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/agent-threads.test.tsindex 10a6869e..25bbd861 100644--- a/apps/api/src/modules/agents/core/__tests__/integration/agent-threads.test.ts+++ b/apps/api/src/modules/agents/core/__tests__/integration/agent-threads.test.ts@@ -404,6 +404,142 @@ describe('agent chat history', () => {expect((await threads()).data!.items[0].contextTokens).toBeUndefined();});+ it('finds a thread by its title and by the text of both roles', async () => {+ const { owner, asOwner } = await setup();+ const agent = await createInternalAgent(asOwner, 'Design Bot', 'design');+ await seedThread('by-title', owner.userId, agent, 'the launch plan');+ await seedThread('by-question', owner.userId, agent, 'sprint', [+ { role: 'user', text: 'when is the launch?' },+ { role: 'assistant', text: 'in May' },+ ]);+ await seedThread('by-answer', owner.userId, agent, 'roadmap', [+ { role: 'user', text: 'what is next?' },+ { role: 'assistant', text: 'the launch, then the retro' },+ ]);+ await seedThread('no-match', owner.userId, agent, 'billing', [+ { role: 'user', text: 'invoices' },+ ]);++ const res = await agents(asOwner)({ agentId: agent.id }).threads.get({+ query: { q: 'launch' },+ });+ expect(res.status).toBe(200);+ // Ranked: the title first, then the member's own message, then the agent's reply.+ expect(res.data!.items.map((t) => t.id)).toEqual(['by-title', 'by-question', 'by-answer']);+ expect(res.data!.items.map((t) => t.match)).toEqual(['title', 'user', 'assistant']);+ expect(res.data!.items[2].snippet).toContain('the launch, then the retro');+ });++ it('searches nothing for a query of one character', async () => {+ const { owner, asOwner } = await setup();+ const agent = await createInternalAgent(asOwner, 'Design Bot', 'design');+ await seedThread('t1', owner.userId, agent, 'billing');++ const res = await agents(asOwner)({ agentId: agent.id }).threads.get({ query: { q: 'b' } });+ expect(res.data!.items.map((t) => t.id)).toEqual(['t1']);+ expect(res.data!.items[0].match).toBeUndefined();+ });++ it("does not match a tool call's arguments or result", async () => {+ const { owner, asOwner } = await setup();+ const agent = await createInternalAgent(asOwner, 'Design Bot', 'design');+ await seedThread('tools', owner.userId, agent, 'sprint', [+ { role: 'user', text: 'what is left?' },+ {+ role: 'assistant',+ text: 'Two things.',+ parts: [+ {+ type: 'tool-invocation',+ toolInvocation: {+ toolCallId: 'call-1',+ toolName: 'list_issues',+ args: { status: 'kryptonite' },+ state: 'result',+ result: 'kryptonite',+ },+ },+ { type: 'text', text: 'Two things.' },+ ],+ },+ ]);++ const res = await agents(asOwner)({ agentId: agent.id }).threads.get({+ query: { q: 'kryptonite' },+ });+ expect(res.data!.items).toEqual([]);+ });++ it('stars a thread, lists it as its own group, and unstars it', async () => {+ const { owner, asOwner } = await setup();+ const agent = await createInternalAgent(asOwner, 'Design Bot', 'design');+ await seedThread('kept', owner.userId, agent, 'kept');+ await backdateThread('kept');+ await seedThread('plain', owner.userId, agent, 'plain');+ const thread = agents(asOwner)({ agentId: agent.id }).threads({ threadId: 'kept' });++ expect((await thread.favorite.put()).status).toBe(204);++ const favorites = await agents(asOwner)({ agentId: agent.id }).threads.get({+ query: { favorites: true },+ });+ expect(favorites.data!.items.map((t) => t.id)).toEqual(['kept']);+ expect(favorites.data!.nextPage).toBeNull();++ // The group holds it, so the list below no longer shows it a second time.+ const rest = await agents(asOwner)({ agentId: agent.id }).threads.get();+ expect(rest.data!.items.map((t) => t.id)).toEqual(['plain']);++ expect((await thread.favorite.delete()).status).toBe(204);+ const cleared = await agents(asOwner)({ agentId: agent.id }).threads.get({+ query: { favorites: true },+ });+ expect(cleared.data!.items).toEqual([]);+ const back = await agents(asOwner)({ agentId: agent.id }).threads.get();+ expect(back.data!.items.map((t) => t.id)).toEqual(['plain', 'kept']);+ });++ it('covers the starred conversations in a search', async () => {+ const { owner, asOwner } = await setup();+ const agent = await createInternalAgent(asOwner, 'Design Bot', 'design');+ await seedThread('kept', owner.userId, agent, 'the launch plan');+ await agents(asOwner)({ agentId: agent.id }).threads({ threadId: 'kept' }).favorite.put();++ const res = await agents(asOwner)({ agentId: agent.id }).threads.get({+ query: { q: 'launch' },+ });+ expect(res.data!.items.map((t) => [t.id, t.favorite])).toEqual([['kept', true]]);+ });++ it("404s starring another user's thread and a thread of another agent", async () => {+ const { owner, asOwner } = await setup();+ const a = await createInternalAgent(asOwner, 'Bot A', 'bota');+ const b = await createInternalAgent(asOwner, 'Bot B', 'botb');+ await seedThread('theirs', 'another-user-id', a, 'theirs');+ await seedThread('mine', owner.userId, a, 'mine');++ expect(+ (await agents(asOwner)({ agentId: a.id }).threads({ threadId: 'theirs' }).favorite.put())+ .status,+ ).toBe(404);+ expect(+ (await agents(asOwner)({ agentId: b.id }).threads({ threadId: 'mine' }).favorite.put())+ .status,+ ).toBe(404);+ });++ it('drops the star with the thread', async () => {+ const { owner, asOwner } = await setup();+ const agent = await createInternalAgent(asOwner, 'Design Bot', 'design');+ await seedThread('kept', owner.userId, agent, 'kept');+ await agents(asOwner)({ agentId: agent.id }).threads({ threadId: 'kept' }).favorite.put();+ await agents(asOwner)({ agentId: agent.id }).threads({ threadId: 'kept' }).delete();++ await seedThread('kept', owner.userId, agent, 'kept');+ const all = await agents(asOwner)({ agentId: agent.id }).threads.get();+ expect(all.data!.items.map((t) => [t.id, t.favorite])).toEqual([['kept', false]]);+ });+it("404s a run continuing another user's chat thread", async () => {const { asOwner } = await setup();const agent = await createInternalAgent(asOwner, 'Design Bot', 'design');diff --git a/apps/api/src/modules/agents/core/__tests__/integration/ai-agents.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/ai-agents.test.tsindex 7eec7244..8e04c8f9 100644--- a/apps/api/src/modules/agents/core/__tests__/integration/ai-agents.test.ts+++ b/apps/api/src/modules/agents/core/__tests__/integration/ai-agents.test.ts@@ -608,6 +608,8 @@ describe('ai agents', () => {'GET /projects/:projectKey/ai-agents/:agentId/runs','POST /projects/:projectKey/ai-agents/:agentId/run/stream','GET /projects/:projectKey/ai-agents/:agentId/threads',+ 'PUT /projects/:projectKey/ai-agents/:agentId/threads/:threadId/favorite',+ 'DELETE /projects/:projectKey/ai-agents/:agentId/threads/:threadId/favorite','GET /projects/:projectKey/ai-agents/:agentId/threads/:threadId/messages','PATCH /projects/:projectKey/ai-agents/:agentId/threads/:threadId','DELETE /projects/:projectKey/ai-agents/:agentId/threads/:threadId',diff --git a/apps/api/src/modules/agents/core/index.ts b/apps/api/src/modules/agents/core/index.tsindex d8b3af2f..c822688b 100644--- a/apps/api/src/modules/agents/core/index.ts+++ b/apps/api/src/modules/agents/core/index.ts@@ -29,6 +29,7 @@ import {createAgentBody,runBody,runsQuery,+ threadListQuery,threadPageQuery,threadParams,updateAgentBody,@@ -43,13 +44,16 @@ import {getChatThreadMessages,deleteChatThread,renameChatThread,+ ownsChatThread,} from './runtime/memory';+import { addFavorite, removeFavorite } from '../chat-favorites';import { isOwnChatThread } from './runtime/thread-ids';import {listThreads as listExternalThreads,getThreadMessages as getExternalThreadMessages,deleteThread as deleteExternalThread,renameThread as renameExternalThread,+ ownsThread as ownsExternalThread,} from '../chat/service';// Run options for an interactive chat run (the test chat): the caller owns the memory@@ -90,12 +94,14 @@ function threadStore(kind: AgentKind) {messages: getExternalThreadMessages,rename: renameExternalThread,remove: deleteExternalThread,+ owns: ownsExternalThread,}: {list: listChatThreads,messages: getChatThreadMessages,rename: renameChatThread,remove: deleteChatThread,+ owns: ownsChatThread,};}@@ -306,24 +312,65 @@ export const aiAgentRoutes = new Elysia({ name: 'ai-agents', detail: { tags: ['A// The caller's own chat threads with this agent, newest first, a page at a time.// Scoped to the caller (the thread's owner), so a user only sees their own- // conversations.+ // conversations. `q` searches them and `favorites` returns the starred ones instead..get('/projects/:projectKey/ai-agents/:agentId/threads',async ({ params, project, query, user }) => {const caller = requireUser(user);const agent = await getAgentById(params.agentId, project.id);if (!agent) throw new HttpError(404, 'Agent not found');- return threadStore(agent.kind).list(caller.id, params.agentId, query.page);+ return threadStore(agent.kind).list(caller.id, params.agentId, query);},{params: agentParams,- query: threadPageQuery,+ query: threadListQuery,permission: ['ai_agents', 'read'],response: { 200: ChatThreadListResponse, ...commonErrors },detail: { summary: 'List chat threads' },},)+ // Stars one of the caller's conversations, so it stays in the favorites group of the+ // history. Scoped the same way as reading it: a thread that is not the caller's own+ // with this agent is a 404.+ .put(+ '/projects/:projectKey/ai-agents/:agentId/threads/:threadId/favorite',+ async ({ params, project, user }) => {+ const caller = requireUser(user);+ const agent = await getAgentById(params.agentId, project.id);+ if (!agent) throw new HttpError(404, 'Agent not found');+ if (!(await threadStore(agent.kind).owns(params.threadId, caller.id, params.agentId)))+ throw new HttpError(404, 'Thread not found');+ await addFavorite(caller.id, params.agentId, params.threadId);+ return noContent();+ },+ {+ params: threadParams,+ permission: ['ai_agents', 'read'],+ response: { 204: t.Void(), ...commonErrors },+ detail: { summary: 'Star a chat thread' },+ },+ )++ .delete(+ '/projects/:projectKey/ai-agents/:agentId/threads/:threadId/favorite',+ async ({ params, project, user }) => {+ const caller = requireUser(user);+ const agent = await getAgentById(params.agentId, project.id);+ if (!agent) throw new HttpError(404, 'Agent not found');+ if (!(await threadStore(agent.kind).owns(params.threadId, caller.id, params.agentId)))+ throw new HttpError(404, 'Thread not found');+ await removeFavorite(caller.id, params.threadId);+ return noContent();+ },+ {+ params: threadParams,+ permission: ['ai_agents', 'read'],+ response: { 204: t.Void(), ...commonErrors },+ detail: { summary: 'Unstar a chat thread' },+ },+ )+// The transcript of one of the caller's chat threads, to restore the conversation// in the UI. 404 when the thread does not exist or is not owned by the caller..get(diff --git a/apps/api/src/modules/agents/core/model.ts b/apps/api/src/modules/agents/core/model.tsindex d559c0e6..d56e2b0b 100644--- a/apps/api/src/modules/agents/core/model.ts+++ b/apps/api/src/modules/agents/core/model.ts@@ -196,6 +196,16 @@ export const ChatThreadResponse = t.Object({}),),),+ favorite: t.Boolean({ description: 'Whether the caller starred this conversation.' }),+ snippet: t.Optional(+ t.String({ description: 'Search only: the text around the match in a message.' }),+ ),+ match: t.Optional(+ t.Union([t.Literal('title'), t.Literal('user'), t.Literal('assistant')], {+ description:+ "Search only: where the match was found — the title, the member's message, or the agent's reply.",+ }),+ ),createdAt: t.String(),updatedAt: t.String(),});@@ -262,3 +272,19 @@ export const renameThreadBody = t.Object({// Both the thread list and a thread's transcript are read a page at a time.export const threadPageQuery = t.Object({ page: t.Optional(t.Numeric({ minimum: 0 })) });++// The history list also searches and shows the starred conversations. `favorites` is a+// group of its own: it is not paginated and ignores the page.+export const threadListQuery = t.Object({+ page: t.Optional(t.Numeric({ minimum: 0 })),+ q: t.Optional(+ t.String({+ description:+ 'Case-insensitive substring, matched against the thread title and the message text of ' ++ 'both roles. Shorter than two characters searches nothing.',+ }),+ ),+ favorites: t.Optional(+ t.Boolean({ description: 'Return the starred conversations instead of the page.' }),+ ),+});diff --git a/apps/api/src/modules/agents/core/runtime/memory.ts b/apps/api/src/modules/agents/core/runtime/memory.tsindex e674e757..c29c8d15 100644--- a/apps/api/src/modules/agents/core/runtime/memory.ts+++ b/apps/api/src/modules/agents/core/runtime/memory.ts@@ -1,8 +1,24 @@import { Memory } from '@mastra/memory';import { PostgresStore } from '@mastra/pg';-import { toIso } from '../helpers/dates';+import { db } from '@repo/db';+import { sql } from 'drizzle-orm';import { appendTextPart, toolArgsText, toolText } from '../../chat-parts';-import { contextField, deleteContextUsage, readContextSizes } from '../../chat-usage';+import { deleteContextUsage } from '../../chat-usage';+import {+ deleteFavorite,+ favoriteThreadIds,+ readFavorites,+ FAVORITES_LIMIT,+} from '../../chat-favorites';+import {+ likePattern,+ searchTerm,+ snippetOf,+ summarize,+ type ThreadListOpts,+ type ThreadRow,+} from '../../chat-history';+import { toIso } from '../helpers/dates';import type { ChatMessageDTO, ChatMessagePage, ChatPart, ChatThreadPage } from '../../model';// Conversation memory for internal agents. Threads and their messages are@@ -108,6 +124,7 @@ export async function deleteChatThread(threadId: string, resourceId: string): Prif (!thread) return false;await memory.deleteThread(threadId);await deleteContextUsage(threadId);+ await deleteFavorite(threadId);return true;}@@ -126,30 +143,138 @@ export async function deleteThreadsWhere(return threads.length;}-// One page of a user's chat threads with one agent, newest first. Scoped by resourceId-// (the caller) and the agent binding in metadata, so a caller only ever sees their-// own conversations with that agent.+// A user's chat threads with one agent: the favorites group, the hits of a search, or+// one page of the rest of them, newest first. Scoped by resourceId (the caller) and the+// agent binding in metadata, so a caller only ever sees their own conversations with+// that agent.export async function listChatThreads(resourceId: string,agentId: number,- page = 0,+ opts: ThreadListOpts = {},): Promise<ChatThreadPage> {- const res = await getReadMemory().listThreads({- filter: { resourceId, metadata: { agentId, kind: 'chat' } },- orderBy: { field: 'updatedAt', direction: 'DESC' },- perPage: THREAD_PAGE_SIZE,- page,- });- const sizes = await readContextSizes(res.threads.map((t) => t.id));- const items = res.threads.map((t) => ({- id: t.id,- title: t.title && t.title.length > 0 ? t.title : null,- cliSessionId: null,- ...contextField(sizes, t.id),- createdAt: toIso(t.createdAt),- updatedAt: toIso(t.updatedAt),- }));- return { items, nextPage: res.hasMore ? page + 1 : null };+ if (opts.favorites) return favoriteChatThreads(resourceId, agentId);+ const term = searchTerm(opts.q);+ const page = opts.page ?? 0;+ const rows = term+ ? await searchChatThreads(resourceId, agentId, term, page)+ : await unstarredChatThreads(resourceId, agentId, page);+ const hasMore = rows.length > THREAD_PAGE_SIZE;+ const items = await summarize(hasMore ? rows.slice(0, THREAD_PAGE_SIZE) : rows);+ return { items, nextPage: hasMore ? page + 1 : null };+}++// One page of the conversations that are not starred, newest first, with one row over+// the page to tell whether there is another. The starred ones are left out because the+// group above the list already holds them — which is also why this reads the threads+// directly instead of through Mastra's storage API, which filters on metadata only.+async function unstarredChatThreads(+ resourceId: string,+ agentId: number,+ page: number,+): Promise<ThreadRow[]> {+ const rows = await db.execute(sql`+ SELECT ${threadFields}, false AS favorite+ FROM mastra_threads t+ WHERE ${ownedChatThreads(resourceId, agentId)}+ AND NOT EXISTS (+ SELECT 1 FROM agent_chat_favorite f+ WHERE f.user_id = ${resourceId} AND f.thread_id = t.id+ )+ ORDER BY t."updatedAt" DESC+ LIMIT ${THREAD_PAGE_SIZE + 1} OFFSET ${page * THREAD_PAGE_SIZE}+ `);+ return rows as unknown as ThreadRow[];+}++// The conversations the caller starred, newest first. The stars are ours and the+// threads are Mastra's, so the two are read one after the other rather than joined.+async function favoriteChatThreads(resourceId: string, agentId: number): Promise<ChatThreadPage> {+ const ids = await favoriteThreadIds(resourceId, agentId);+ if (ids.length === 0) return { items: [], nextPage: null };+ const rows = await db.execute(sql`+ SELECT ${threadFields}, true AS favorite+ FROM mastra_threads t+ WHERE ${ownedChatThreads(resourceId, agentId)}+ AND t.id IN (${sql.join(+ ids.map((id) => sql`${id}`),+ sql`, `,+ )})+ ORDER BY t."updatedAt" DESC+ LIMIT ${FAVORITES_LIMIT}+ `);+ return { items: await summarize(rows as unknown as ThreadRow[]), nextPage: null };+}++// The columns of a thread the history list reads. Mastra owns these tables, so they are+// addressed in raw SQL: its storage API searches no text and returns no snippet.+const threadFields = sql`t.id, t.title, NULL AS "cliSessionId", t."createdAt", t."updatedAt"`;++// The caller's own chat threads with one agent. A thread is bound to its agent through+// the metadata written when it was created, and 'chat' is what tells a conversation+// apart from an autonomous run's thread.+function ownedChatThreads(resourceId: string, agentId: number) {+ return sql`t."resourceId" = ${resourceId}+ AND t.metadata->>'agentId' = ${String(agentId)}+ AND t.metadata->>'kind' = 'chat'`;+}++// The conversations whose title or message text contains the term. A message is stored+// as JSON, so its text parts are taken out one by one: matching the whole document would+// also match the arguments and the result of a tool call, which are not what the member+// wrote or read.+//+// The snippet is cut from the newest matching message, in the database. The rank puts a+// title hit first, then the ones where the member's own message matches, then the ones+// matching only in the agent's reply.+async function searchChatThreads(+ resourceId: string,+ agentId: number,+ term: string,+ page: number,+): Promise<ThreadRow[]> {+ const like = likePattern(term);+ const snippet = snippetOf(sql`part->>'text'`, term);+ const rows = await db.execute(sql`+ SELECT ${threadFields},+ hit.snippet,+ CASE+ WHEN t.title ILIKE ${like} THEN 1+ WHEN coalesce(hit.user_match, false) THEN 2+ ELSE 3+ END AS rank+ FROM mastra_threads t+ LEFT JOIN LATERAL (+ SELECT bool_or(msg.role = 'user') AS user_match,+ (array_agg(${snippet} ORDER BY msg."createdAt" DESC))[1] AS snippet+ FROM mastra_messages msg+ CROSS JOIN LATERAL jsonb_array_elements(msg.content::jsonb -> 'parts') AS part+ WHERE msg.thread_id = t.id+ AND part->>'type' = 'text'+ AND part->>'text' ILIKE ${like}+ ) hit ON true+ WHERE ${ownedChatThreads(resourceId, agentId)}+ AND (t.title ILIKE ${like} OR hit.snippet IS NOT NULL)+ ORDER BY rank, t."updatedAt" DESC+ LIMIT ${THREAD_PAGE_SIZE + 1} OFFSET ${page * THREAD_PAGE_SIZE}+ `);+ // The stars are in our own table, so they are read for the hits rather than joined.+ const hits = rows as unknown as ThreadRow[];+ const favorites = await readFavorites(+ resourceId,+ hits.map((row) => row.id),+ );+ return hits.map((row) => ({ ...row, favorite: favorites.has(row.id) }));+}++// Whether the conversation is the caller's own with this agent, which is what a star is+// checked against.+export async function ownsChatThread(+ threadId: string,+ resourceId: string,+ agentId: number,+): Promise<boolean> {+ const thread = await getReadMemory().getThreadById({ threadId, resourceId });+ return thread?.metadata?.agentId === agentId;}// Loads the transcript of one chat thread for the given owner. Returns null whendiff --git a/apps/api/src/modules/agents/model.ts b/apps/api/src/modules/agents/model.tsindex a287d403..41fd79df 100644--- a/apps/api/src/modules/agents/model.ts+++ b/apps/api/src/modules/agents/model.ts@@ -1,5 +1,7 @@import { t } from 'elysia';+import type { ThreadMatch } from './chat-history';+// Shared by every route in the domain that addresses an agent by its id.export const agentParams = t.Object({projectKey: t.String(),@@ -49,11 +51,16 @@ export const contextUsageBody = t.Optional(// `contextTokens` is the size of the conversation's context after its last completed// answer: absent while no answer has completed, null where the agent reports no counts// that can be read as one.+// `favorite` is the star the caller put on the conversation. `snippet` and `match` are+// set by a search: the text around the hit, and where it was found.export type ChatThreadSummary = {id: string;title: string | null;cliSessionId: string | null;contextTokens?: number | null;+ favorite: boolean;+ snippet?: string;+ match?: ThreadMatch;createdAt: string;updatedAt: string;};diff --git a/apps/web/messages/ar/aiChat.json b/apps/web/messages/ar/aiChat.jsonindex f619fe3e..b17f9545 100644--- a/apps/web/messages/ar/aiChat.json+++ b/apps/web/messages/ar/aiChat.json@@ -18,6 +18,12 @@"deleteThread": "حذف المحادثة","deleteThreadConfirm": "سيُحذف «{title}» ورسائله نهائيًا.","noThreads": "مفيش محادثات لسه. ابعت رسالة عشان تبدأ واحدة.",+ "searchThreads": "دوّر في المحادثات",+ "noMatches": "مفيش نتايج.",+ "favorites": "المفضّلة",+ "otherThreads": "باقي المحادثات",+ "addFavorite": "إضافة للمفضّلة",+ "removeFavorite": "إزالة من المفضّلة","noModel": "لم يُحدَّد نموذج","copySession": "نسخ معرّف الجلسة","sessionLabel": "معرّف الجلسة المحلية",diff --git a/apps/web/messages/en/aiChat.json b/apps/web/messages/en/aiChat.jsonindex 2c2398d9..9bde6e0f 100644--- a/apps/web/messages/en/aiChat.json+++ b/apps/web/messages/en/aiChat.json@@ -18,6 +18,12 @@"deleteThread": "Delete conversation","deleteThreadConfirm": "“{title}” and its messages are deleted permanently.","noThreads": "No conversations yet. Send a message to start one.",+ "searchThreads": "Search conversations",+ "noMatches": "Nothing found.",+ "favorites": "Favorites",+ "otherThreads": "Other conversations",+ "addFavorite": "Add to favorites",+ "removeFavorite": "Remove from favorites","noModel": "No model set","copySession": "Copy session id","sessionLabel": "Local session id",diff --git a/apps/web/messages/ru/aiChat.json b/apps/web/messages/ru/aiChat.jsonindex e63565b9..922fbe5d 100644--- a/apps/web/messages/ru/aiChat.json+++ b/apps/web/messages/ru/aiChat.json@@ -18,6 +18,12 @@"deleteThread": "Удалить разговор","deleteThreadConfirm": "«{title}» и его сообщения будут удалены навсегда.","noThreads": "Разговоров пока нет. Отправьте сообщение, чтобы начать.",+ "searchThreads": "Поиск по разговорам",+ "noMatches": "Ничего не найдено.",+ "favorites": "Избранное",+ "otherThreads": "Остальные разговоры",+ "addFavorite": "Добавить в избранное",+ "removeFavorite": "Убрать из избранного","noModel": "Модель не задана","copySession": "Скопировать идентификатор сессии","sessionLabel": "Идентификатор локальной сессии",diff --git a/apps/web/messages/uk/aiChat.json b/apps/web/messages/uk/aiChat.jsonindex 629fc7a5..c2d484a3 100644--- a/apps/web/messages/uk/aiChat.json+++ b/apps/web/messages/uk/aiChat.json@@ -18,6 +18,12 @@"deleteThread": "Видалити розмову","deleteThreadConfirm": "«{title}» та її повідомлення буде видалено назавжди.","noThreads": "Розмов ще немає. Надішліть повідомлення, щоб почати.",+ "searchThreads": "Пошук у розмовах",+ "noMatches": "Нічого не знайдено.",+ "favorites": "Обране",+ "otherThreads": "Інші розмови",+ "addFavorite": "Додати в обране",+ "removeFavorite": "Прибрати з обраного","noModel": "Модель не задано","copySession": "Скопіювати ідентифікатор сесії","sessionLabel": "Ідентифікатор локальної сесії",diff --git a/apps/web/messages/zh-CN/aiChat.json b/apps/web/messages/zh-CN/aiChat.jsonindex d1419491..82b20cc6 100644--- a/apps/web/messages/zh-CN/aiChat.json+++ b/apps/web/messages/zh-CN/aiChat.json@@ -18,6 +18,12 @@"deleteThread": "删除对话","deleteThreadConfirm": "将永久删除“{title}”及其中的消息。","noThreads": "暂无对话。发送消息以开始对话。",+ "searchThreads": "搜索对话",+ "noMatches": "未找到结果。",+ "favorites": "收藏",+ "otherThreads": "其他对话",+ "addFavorite": "加入收藏",+ "removeFavorite": "取消收藏","noModel": "未设置模型","copySession": "复制会话 ID","sessionLabel": "本地会话 ID",diff --git a/apps/web/src/components/common/agent-chat/AgentChatPanel.tsx b/apps/web/src/components/common/agent-chat/AgentChatPanel.tsxindex d06baaa8..86a96a4d 100644--- a/apps/web/src/components/common/agent-chat/AgentChatPanel.tsx+++ b/apps/web/src/components/common/agent-chat/AgentChatPanel.tsx@@ -240,8 +240,12 @@ export function AgentChatPanel({align="block-end"className="gap-1 px-2.5 pb-2"// The row carries a text cursor, and its own handler focuses an- // `input` — this group holds a textarea.+ // `input` — this group holds a textarea. A control of the row that+ // opens a popover keeps this row as its React parent while rendering+ // into a portal, so its clicks arrive here too: refocusing on those+ // would pull the focus out of the popover and close it.onClick={(e) => {+ if (!e.currentTarget.contains(e.target as Node)) return;if ((e.target as HTMLElement).closest('button')) return;e.currentTarget.parentElement?.querySelector('textarea')?.focus();}}diff --git a/apps/web/src/features/ai-chat/components/panel/ChatPanelHistory.tsx b/apps/web/src/features/ai-chat/components/panel/ChatPanelHistory.tsxindex 58cf4430..123fb683 100644--- a/apps/web/src/features/ai-chat/components/panel/ChatPanelHistory.tsx+++ b/apps/web/src/features/ai-chat/components/panel/ChatPanelHistory.tsx@@ -3,6 +3,7 @@import { useState } from 'react';import { History } from 'lucide-react';import { useTranslations } from 'next-intl';+import * as PopoverPrimitive from '@radix-ui/react-popover';import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';import { InputGroupButton } from '@/components/ui/input-group';import { AiChatThreadList } from '../shared/AiChatThreadList';@@ -42,8 +43,8 @@ export function ChatPanelHistory({</InputGroupButton></PopoverTrigger><PopoverContent- align="start"- className="flex max-h-96 w-80 flex-col p-0"+ align="center"+ className="flex h-[28rem] max-h-(--radix-popover-content-available-height) w-96 flex-col p-0"// Picking a conversation hides the session this popover is anchored to, and a// hidden trigger reports a zero rect in the top left corner, where the popover// would be moved while it plays its closing animation. Without that animation it@@ -56,6 +57,8 @@ export function ChatPanelHistory({event.preventDefault();}}>+ <PopoverPrimitive.Arrow className="size-2.5 translate-y-[calc(-50%_-_1px)] rotate-45 rounded-[2px] border border-t-0 border-l-0 bg-popover fill-popover" />+<div className="flex min-w-0 items-baseline gap-1.5 border-b px-3 py-2"><span className="text-sm font-medium">{t('history')}</span><span className="truncate text-xs text-muted-foreground">{agentName}</span>diff --git a/apps/web/src/features/ai-chat/components/panel/ChatPanelTabFavorite.tsx b/apps/web/src/features/ai-chat/components/panel/ChatPanelTabFavorite.tsxnew file mode 100644index 00000000..05f83578--- /dev/null+++ b/apps/web/src/features/ai-chat/components/panel/ChatPanelTabFavorite.tsx@@ -0,0 +1,43 @@+'use client';++import { Star } from 'lucide-react';+import { useTranslations } from 'next-intl';+import {+ useAgentFavoriteThreadsQuery,+ useToggleAgentThreadFavorite,+} from '@/services/aiAgents.service';+import { Button } from '@/components/ui/button';+import { cn } from '@/lib/utils';++// Stars the conversation of the tab that is open, from the tab row. Its state comes+// from the same favorites request the history popover reads, so the two always agree.+// The host mounts it only for a chat that has a thread: one that has not started, and+// one with an agent that keeps no memory, have nothing to star.+export function ChatPanelTabFavorite({+ projectKey,+ agentId,+ threadId,+}: {+ projectKey: string;+ agentId: number;+ threadId: string;+}) {+ const t = useTranslations('aiChat');+ const favoritesQuery = useAgentFavoriteThreadsQuery(projectKey, agentId);+ const toggleFavorite = useToggleAgentThreadFavorite(projectKey, agentId);+ const favorite = favoritesQuery.data?.items.some((thread) => thread.id === threadId) ?? false;++ return (+ <Button+ variant="ghost"+ size="icon"+ className="size-7 shrink-0 text-muted-foreground hover:text-foreground"+ title={t(favorite ? 'removeFavorite' : 'addFavorite')}+ aria-pressed={favorite}+ onClick={() => toggleFavorite.mutate({ threadId, favorite: !favorite })}+ >+ <Star className={cn(favorite && 'fill-current text-amber-500')} />+ <span className="sr-only">{t(favorite ? 'removeFavorite' : 'addFavorite')}</span>+ </Button>+ );+}diff --git a/apps/web/src/features/ai-chat/components/panel/ChatPanelTabs.tsx b/apps/web/src/features/ai-chat/components/panel/ChatPanelTabs.tsxindex 00092dea..ab26fcfb 100644--- a/apps/web/src/features/ai-chat/components/panel/ChatPanelTabs.tsx+++ b/apps/web/src/features/ai-chat/components/panel/ChatPanelTabs.tsx@@ -7,6 +7,7 @@ import { useTranslations } from 'next-intl';import { useStripSortSensors } from '@/lib/dnd';import { Button } from '@/components/ui/button';import { ChatPanelTab } from './ChatPanelTab';+import { ChatPanelTabFavorite } from './ChatPanelTabFavorite';import { ChatPanelTabSortable } from './ChatPanelTabSortable';import { ChatPanelTabsOverflow } from './ChatPanelTabsOverflow';import { useTabOverflow } from '../../hooks/useTabOverflow';@@ -37,6 +38,7 @@ export function ChatPanelTabs({const sensors = useStripSortSensors();const { rowRef, measureRef, visible, hidden } = useTabOverflow(sessions, activeId);const lastVisibleId = visible[visible.length - 1]?.id ?? null;+ const active = sessions.find((session) => session.id === activeId);// Selecting from the menu shows that chat in the last slot of the row; the swap is// what keeps it there afterwards.@@ -83,6 +85,16 @@ export function ChatPanelTabs({/>)}+ {/* A chat that has not started has no thread, and neither has one with an agent+ that keeps no memory, so there is nothing to star for either. */}+ {active?.threadId && (+ <ChatPanelTabFavorite+ projectKey={projectKey}+ agentId={active.agentId}+ threadId={active.threadId}+ />+ )}+<Buttonvariant="ghost"size="icon"diff --git a/apps/web/src/features/ai-chat/components/shared/AiChatThreadItem.tsx b/apps/web/src/features/ai-chat/components/shared/AiChatThreadItem.tsxindex 9edb4564..95688dc4 100644--- a/apps/web/src/features/ai-chat/components/shared/AiChatThreadItem.tsx+++ b/apps/web/src/features/ai-chat/components/shared/AiChatThreadItem.tsx@@ -1,26 +1,34 @@'use client';-import { MessageCircle, Trash2 } from 'lucide-react';+import type { ReactNode } from 'react';+import { MessageCircle, Star, Trash2 } from 'lucide-react';import { useTranslations } from 'next-intl';import { formatShortDate } from '@/utils/dates';import { cn } from '@/lib/utils';import { Button } from '@/components/ui/button';import type { AiChatThread } from '@/lib/api';-// One conversation in the chat history list. The delete control sits next to the row-// rather than inside it, so the row stays a single button.+// One conversation in the chat history list. The controls sit next to the row rather+// than inside it, so the row stays a single button. `query` is the search the list was+// filtered by: the row marks it where it appears, in the title and in the snippet the+// search brought back.export function AiChatThreadItem({thread,active,+ query,onSelect,+ onToggleFavorite,onDelete,}: {thread: AiChatThread;active: boolean;+ query: string;onSelect: () => void;+ onToggleFavorite: () => void;onDelete: () => void;}) {const t = useTranslations('aiChat');+ const title = thread.title ?? t('untitledThread');return (<div className="group relative">@@ -29,7 +37,7 @@ export function AiChatThreadItem({onClick={onSelect}aria-pressed={active}className={cn(- 'flex w-full items-start gap-2 rounded-lg py-2 pr-9 pl-2.5 text-left transition-colors',+ 'flex w-full items-start gap-2 rounded-lg py-2 pr-16 pl-2.5 text-left transition-colors',active ? 'bg-accent' : 'hover:bg-accent/50',)}>@@ -40,11 +48,31 @@ export function AiChatThreadItem({)}/><div className="min-w-0 flex-1">- <div className="truncate text-sm">{thread.title ?? t('untitledThread')}</div>+ <div className="truncate text-sm">{mark(title, query)}</div>+ {thread.snippet && (+ <div className="truncate text-xs text-muted-foreground">+ {mark(thread.snippet.replace(/\s+/g, ' ').trim(), query)}+ </div>+ )}<div className="text-xs text-muted-foreground">{formatShortDate(thread.updatedAt)}</div></div></button>+ <Button+ variant="ghost"+ size="icon"+ title={t(thread.favorite ? 'removeFavorite' : 'addFavorite')}+ aria-pressed={thread.favorite}+ onClick={onToggleFavorite}+ className={cn(+ 'absolute top-1/2 right-8 size-7 -translate-y-1/2 text-muted-foreground',+ !thread.favorite && 'opacity-0 group-hover:opacity-100 focus-visible:opacity-100',+ )}+ >+ <Star className={cn('size-3.5', thread.favorite && 'fill-current text-amber-500')} />+ <span className="sr-only">{t(thread.favorite ? 'removeFavorite' : 'addFavorite')}</span>+ </Button>+<Buttonvariant="ghost"size="icon"@@ -58,3 +86,19 @@ export function AiChatThreadItem({</div>);}++// The text with the first occurrence of the search marked. The search ran in the+// database, so the same query string is matched here again rather than returned.+function mark(text: string, query: string): ReactNode {+ const at = query ? text.toLowerCase().indexOf(query.toLowerCase()) : -1;+ if (at < 0) return text;+ return (+ <>+ {text.slice(0, at)}+ <mark className="rounded-[2px] bg-primary/20 text-foreground">+ {text.slice(at, at + query.length)}+ </mark>+ {text.slice(at + query.length)}+ </>+ );+}diff --git a/apps/web/src/features/ai-chat/components/shared/AiChatThreadList.tsx b/apps/web/src/features/ai-chat/components/shared/AiChatThreadList.tsxindex 34e1e5a4..558d0ad1 100644--- a/apps/web/src/features/ai-chat/components/shared/AiChatThreadList.tsx+++ b/apps/web/src/features/ai-chat/components/shared/AiChatThreadList.tsx@@ -1,19 +1,36 @@'use client';import { useEffect, useRef, useState } from 'react';+import { Search } from 'lucide-react';import { useTranslations } from 'next-intl';-import { useAgentThreadsQuery, useDeleteAgentThread } from '@/services/aiAgents.service';+import {+ useAgentFavoriteThreadsQuery,+ useAgentThreadsQuery,+ useDeleteAgentThread,+ useToggleAgentThreadFavorite,+} from '@/services/aiAgents.service';+import { useDebouncedValue } from '@/hooks/useDebouncedValue';import ConfirmDialog from '@/components/common/overlay/ConfirmDialog';+import { Input } from '@/components/ui/input';import type { AiChatThread } from '@/lib/api';import { AiChatThreadItem } from './AiChatThreadItem';import { AiChatThreadItemSkeleton } from './AiChatThreadItemSkeleton';+// Below this the search runs nothing, the way the API reads it: one character matches+// nearly every conversation.+const MIN_QUERY = 2;+const SEARCH_DEBOUNCE_MS = 300;+// The caller's own past conversations with one agent, newest first, loaded a page at a// time as the end of the list comes into view. The host supplies the header around it.// `selectedThreadId` marks the conversation currently shown; a thread that has not// produced its first reply yet has no id and so is not in this list. Deleting a// conversation removes it and its messages; `onDeleted` lets the host reset the chat// when the deleted one was open.+//+// The starred conversations are shown as a group of their own on top, and the list+// below holds the rest, so a conversation appears once. A search replaces both with its+// hits, over all of them.export function AiChatThreadList({projectKey,agentId,@@ -29,9 +46,16 @@ export function AiChatThreadList({}) {const t = useTranslations('aiChat');const tCommon = useTranslations('common');- const threadsQuery = useAgentThreadsQuery(projectKey, agentId);+ const [query, setQuery] = useState('');+ const debounced = useDebouncedValue(query.trim(), SEARCH_DEBOUNCE_MS);+ const search = debounced.length >= MIN_QUERY ? debounced : '';++ const threadsQuery = useAgentThreadsQuery(projectKey, agentId, search);const threads = threadsQuery.data?.pages.flatMap((page) => page.items) ?? [];const { hasNextPage, isFetchingNextPage, fetchNextPage } = threadsQuery;+ const favoritesQuery = useAgentFavoriteThreadsQuery(projectKey, agentId);+ const favorites = search ? [] : (favoritesQuery.data?.items ?? []);+ const toggleFavorite = useToggleAgentThreadFavorite(projectKey, agentId);const deleteThread = useDeleteAgentThread(projectKey, agentId);const [pending, setPending] = useState<AiChatThread | null>(null);@@ -57,40 +81,61 @@ export function AiChatThreadList({onDeleted(pending.id);}- if (threadsQuery.isLoading) {- return (- <div className="min-h-0 flex-1 space-y-1 overflow-y-auto p-3">- {Array.from({ length: 5 }).map((_, i) => (- <AiChatThreadItemSkeleton key={i} />- ))}- </div>- );- }+ const renderThread = (thread: AiChatThread) => (+ <AiChatThreadItem+ key={thread.id}+ thread={thread}+ active={thread.id === selectedThreadId}+ query={search}+ onSelect={() => onSelect(thread.id)}+ onToggleFavorite={() =>+ toggleFavorite.mutate({ threadId: thread.id, favorite: !thread.favorite })+ }+ onDelete={() => setPending(thread)}+ />+ );- if (threads.length === 0) {+ function renderList() {+ if (threadsQuery.isLoading) {+ return Array.from({ length: 5 }).map((_, i) => <AiChatThreadItemSkeleton key={i} />);+ }+ if (threads.length === 0 && favorites.length === 0) {+ return (+ <div className="px-2 py-6 text-center text-xs text-muted-foreground">+ {search ? t('noMatches') : t('noThreads')}+ </div>+ );+ }return (- <div className="min-h-0 flex-1 px-4 py-6 text-center text-xs text-muted-foreground">- {t('noThreads')}- </div>+ <>+ {favorites.length > 0 && (+ <>+ <ListLabel>{t('favorites')}</ListLabel>+ {favorites.map(renderThread)}+ {threads.length > 0 && <ListLabel>{t('otherThreads')}</ListLabel>}+ </>+ )}+ {threads.map(renderThread)}+ <div ref={sentinelRef} />+ {isFetchingNextPage && <AiChatThreadItemSkeleton />}+ </>);}return (<>- <div className="min-h-0 flex-1 space-y-0.5 overflow-y-auto p-2">- {threads.map((thread) => (- <AiChatThreadItem- key={thread.id}- thread={thread}- active={thread.id === selectedThreadId}- onSelect={() => onSelect(thread.id)}- onDelete={() => setPending(thread)}- />- ))}- <div ref={sentinelRef} />- {isFetchingNextPage && <AiChatThreadItemSkeleton />}+ <div className="relative border-b p-2">+ <Search className="pointer-events-none absolute start-4 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground" />+ <Input+ value={query}+ onChange={(event) => setQuery(event.target.value)}+ placeholder={t('searchThreads')}+ className="h-8 ps-8 text-sm"+ /></div>+ <div className="min-h-0 flex-1 space-y-0.5 overflow-y-auto p-2">{renderList()}</div>+{pending && (<ConfirmDialogtitle={t('deleteThread')}@@ -106,3 +151,9 @@ export function AiChatThreadList({</>);}++function ListLabel({ children }: { children: string }) {+ return (+ <div className="px-2.5 pt-2 pb-1 text-xs font-medium text-muted-foreground">{children}</div>+ );+}diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.tsindex afbced8d..c7174c98 100644--- a/apps/web/src/lib/api.ts+++ b/apps/web/src/lib/api.ts@@ -547,11 +547,16 @@ export type AgentRunEvent =// `contextTokens` is the size of the conversation's context after its last completed// answer: absent while no answer has completed, null where the agent reports no counts// that can be read as one.+// `favorite` is the star the caller put on the conversation. `snippet` and `match` come+// back from a search: the text around the hit, and where it was found.export interface AiChatThread {id: string;title: string | null;cliSessionId: string | null;contextTokens?: number | null;+ favorite: boolean;+ snippet?: string;+ match?: 'title' | 'user' | 'assistant';createdAt: string;updatedAt: string;}@@ -3098,9 +3103,29 @@ export const api = {`/projects/${projectKey}/agent-schedules/${scheduleId}/runs${runId != null ? `/${runId}` : ''}/cancel`,{ method: 'POST' },),- // One page of the caller's own chat threads with an agent, newest first.- listAiAgentThreads: (projectKey: string, agentId: number, page: number) =>- request<AiChatThreadPage>(`/projects/${projectKey}/ai-agents/${agentId}/threads?page=${page}`),+ // One page of the caller's own chat threads with an agent, newest first. `q` searches+ // them by title and message text instead, over every page.+ listAiAgentThreads: (projectKey: string, agentId: number, page: number, q = '') =>+ request<AiChatThreadPage>(+ `/projects/${projectKey}/ai-agents/${agentId}/threads?page=${page}` ++ (q ? `&q=${encodeURIComponent(q)}` : ''),+ ),+ // The conversations the caller starred with an agent, newest first, in one go.+ listAiAgentFavoriteThreads: (projectKey: string, agentId: number) =>+ request<AiChatThreadPage>(+ `/projects/${projectKey}/ai-agents/${agentId}/threads?favorites=true`,+ ),+ // Stars one of the caller's conversations, or takes the star off it.+ setAiAgentThreadFavorite: (+ projectKey: string,+ agentId: number,+ threadId: string,+ favorite: boolean,+ ) =>+ request<void>(+ `/projects/${projectKey}/ai-agents/${agentId}/threads/${encodeURIComponent(threadId)}/favorite`,+ { method: favorite ? 'PUT' : 'DELETE' },+ ),// The transcript of one chat thread, to restore the conversation.getAiAgentThreadMessages: (projectKey: string, agentId: number, threadId: string, page: number) =>request<AiChatMessagePage>(diff --git a/apps/web/src/services/aiAgents.service.ts b/apps/web/src/services/aiAgents.service.tsindex 055ee2d7..fe9a65bd 100644--- a/apps/web/src/services/aiAgents.service.ts+++ b/apps/web/src/services/aiAgents.service.ts@@ -7,10 +7,11 @@ import {useQuery,useQueryClient,type InfiniteData,+ type QueryClient,} from '@tanstack/react-query';import { toast } from 'sonner';import { useTranslations } from 'next-intl';-import { api, type AiChatThreadPage } from '@/lib/api';+import { api, type AiChatThread, type AiChatThreadPage } from '@/lib/api';import { qk } from '@/services/queryKeys';import { useInvalidateProject } from '@/services/projects.service';@@ -41,22 +42,102 @@ export function useAgentRuns(projectKey: string | null, agentId: number | null)}// The caller's chat threads with one agent (the chat history), newest first and a-// page at a time. Only fetched when an agent is selected.-export function useAgentThreadsQuery(projectKey: string | null, agentId: number | null) {+// page at a time. Only fetched when an agent is selected. `q` searches them instead,+// over every page, and is cached as a list of its own.+export function useAgentThreadsQuery(projectKey: string | null, agentId: number | null, q = '') {return useInfiniteQuery({- queryKey: qk.agentThreads(projectKey ?? '', agentId ?? 0),- queryFn: ({ pageParam }) => api.listAiAgentThreads(projectKey!, agentId!, pageParam),+ queryKey: qk.agentThreads(projectKey ?? '', agentId ?? 0, q),+ queryFn: ({ pageParam }) => api.listAiAgentThreads(projectKey!, agentId!, pageParam, q),initialPageParam: 0,getNextPageParam: (last) => last.nextPage ?? undefined,enabled: projectKey != null && agentId != null,});}-// The threads loaded so far, as one list. The pages the history has not reached are-// simply not in it: a tab of an older conversation falls back to its default title.+// The conversations starred with one agent, in one go. Read by the group on top of the+// history and by the star in the tabs bar, which share this one request.+export function useAgentFavoriteThreadsQuery(projectKey: string | null, agentId: number | null) {+ return useQuery({+ queryKey: qk.agentFavoriteThreads(projectKey ?? '', agentId ?? 0),+ queryFn: () => api.listAiAgentFavoriteThreads(projectKey!, agentId!),+ enabled: projectKey != null && agentId != null,+ });+}++// Stars a conversation or takes the star off it. The star flips before the request is+// answered — it is the whole feedback of the click — and rolls back if it fails.+export function useToggleAgentThreadFavorite(projectKey: string | null, agentId: number | null) {+ const qc = useQueryClient();+ const lists = () => qk.agentThreadLists(projectKey!, agentId!);+ const favorites = () => qk.agentFavoriteThreads(projectKey!, agentId!);+ return useMutation({+ mutationFn: ({ threadId, favorite }: { threadId: string; favorite: boolean }) =>+ api.setAiAgentThreadFavorite(projectKey!, agentId!, threadId, favorite),+ onMutate: async ({ threadId, favorite }) => {+ if (!projectKey || agentId == null) return;+ await Promise.all([+ qc.cancelQueries({ queryKey: lists() }),+ qc.cancelQueries({ queryKey: favorites() }),+ ]);+ const previous = [+ ...qc.getQueriesData({ queryKey: lists() }),+ ...qc.getQueriesData({ queryKey: favorites() }),+ ];+ qc.setQueriesData<InfiniteData<AiChatThreadPage>>({ queryKey: lists() }, (prev) =>+ prev+ ? {+ ...prev,+ pages: prev.pages.map((page) => ({+ ...page,+ items: page.items.map((thread) =>+ thread.id === threadId ? { ...thread, favorite } : thread,+ ),+ })),+ }+ : prev,+ );+ // The group holds the starred conversations themselves, so the one being starred+ // is moved into it and the one being unstarred out of it. A conversation no loaded+ // page holds is only added once the group is read again.+ const starred = threadsOf(qc, lists()).find((thread) => thread.id === threadId);+ qc.setQueryData<AiChatThreadPage>(favorites(), (prev) => {+ if (!prev) return prev;+ const without = prev.items.filter((thread) => thread.id !== threadId);+ if (!favorite) return { ...prev, items: without };+ return starred ? { ...prev, items: [{ ...starred, favorite: true }, ...without] } : prev;+ });+ return { previous };+ },+ onError: (_err, _vars, context) => {+ for (const [key, data] of context?.previous ?? []) qc.setQueryData(key, data);+ },+ onSettled: () => {+ if (!projectKey || agentId == null) return;+ void qc.invalidateQueries({ queryKey: favorites() });+ void qc.invalidateQueries({ queryKey: lists() });+ },+ });+}++// Every conversation the given lists hold, searches included: where a conversation is+// read from when only its id is at hand.+function threadsOf(qc: QueryClient, key: readonly unknown[]): AiChatThread[] {+ return qc+ .getQueriesData<InfiniteData<AiChatThreadPage>>({ queryKey: key })+ .flatMap(([, data]) => data?.pages.flatMap((page) => page.items) ?? []);+}++// The threads loaded so far, as one list: the pages of the history read until now plus+// the starred ones, which the history keeps out of those pages. The pages it has not+// reached are simply not in it: a tab of an older conversation falls back to its default+// title.export function useLoadedAgentThreads(projectKey: string | null, agentId: number | null) {const query = useAgentThreadsQuery(projectKey, agentId);- return query.data?.pages.flatMap((page) => page.items) ?? [];+ const favorites = useAgentFavoriteThreadsQuery(projectKey, agentId);+ return [+ ...(favorites.data?.items ?? []),+ ...(query.data?.pages.flatMap((page) => page.items) ?? []),+ ];}// The transcript of one chat thread, to restore the conversation when a thread is@@ -85,8 +166,8 @@ export function useRenameAgentThread(projectKey: string | null, agentId: numberapi.renameAiAgentThread(projectKey!, agentId!, threadId, title),onSuccess: (_res, { threadId, title }) => {if (!projectKey || agentId == null) return;- qc.setQueryData<InfiniteData<AiChatThreadPage>>(- qk.agentThreads(projectKey, agentId),+ qc.setQueriesData<InfiniteData<AiChatThreadPage>>(+ { queryKey: qk.agentThreadLists(projectKey, agentId) },(prev) =>prev && {...prev,@@ -98,6 +179,7 @@ export function useRenameAgentThread(projectKey: string | null, agentId: number})),},);+ void qc.invalidateQueries({ queryKey: qk.agentFavoriteThreads(projectKey, agentId) });},});}@@ -109,8 +191,10 @@ export function useDeleteAgentThread(projectKey: string | null, agentId: numberreturn useMutation({mutationFn: (threadId: string) => api.deleteAiAgentThread(projectKey!, agentId!, threadId),onSuccess: () => {- if (projectKey && agentId != null)- void qc.invalidateQueries({ queryKey: qk.agentThreads(projectKey, agentId) });+ if (projectKey && agentId != null) {+ void qc.invalidateQueries({ queryKey: qk.agentThreadLists(projectKey, agentId) });+ void qc.invalidateQueries({ queryKey: qk.agentFavoriteThreads(projectKey, agentId) });+ }},});}diff --git a/apps/web/src/services/queryKeys.ts b/apps/web/src/services/queryKeys.tsindex 92fb375c..c5105e67 100644--- a/apps/web/src/services/queryKeys.ts+++ b/apps/web/src/services/queryKeys.ts@@ -63,9 +63,16 @@ export const qk = {agentScheduleRuns: (projectKey: string, scheduleId: number) =>['agentSchedules', projectKey, scheduleId, 'runs'] as const,// The caller's chat threads with one agent (the AI Chat history rail) and the- // transcript of one thread (restored when a thread is opened).- agentThreads: (projectKey: string, agentId: number) =>- ['aiAgents', projectKey, agentId, 'threads'] as const,+ // transcript of one thread (restored when a thread is opened). A search is a list of+ // its own, so the unsearched list stays cached while one is typed.+ agentThreadLists: (projectKey: string, agentId: number) =>+ ['aiAgents', projectKey, agentId, 'threadList'] as const,+ agentThreads: (projectKey: string, agentId: number, q = '') =>+ ['aiAgents', projectKey, agentId, 'threadList', q] as const,+ // The conversations starred with one agent: the group on top of the history, and what+ // the star in the tabs bar reads its state from.+ agentFavoriteThreads: (projectKey: string, agentId: number) =>+ ['aiAgents', projectKey, agentId, 'favoriteThreads'] as const,agentThreadMessages: (projectKey: string, agentId: number, threadId: string) =>['aiAgents', projectKey, agentId, 'threads', threadId] as const,// Stored integration credentials, the integration catalog, and an LLM provider'sdiff --git a/packages/db/drizzle/0110_spooky_the_santerians.sql b/packages/db/drizzle/0110_spooky_the_santerians.sqlnew file mode 100644index 00000000..ce0c8de4--- /dev/null+++ b/packages/db/drizzle/0110_spooky_the_santerians.sql@@ -0,0 +1,9 @@+CREATE TABLE "agent_chat_favorite" (+ "user_id" text NOT NULL,+ "agent_id" integer NOT NULL,+ "thread_id" text NOT NULL,+ CONSTRAINT "agent_chat_favorite_user_id_thread_id_pk" PRIMARY KEY("user_id","thread_id")+);+--> statement-breakpoint+ALTER TABLE "agent_chat_favorite" ADD CONSTRAINT "agent_chat_favorite_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint+ALTER TABLE "agent_chat_favorite" ADD CONSTRAINT "agent_chat_favorite_agent_id_ai_agent_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."ai_agent"("id") ON DELETE cascade ON UPDATE no action;\ No newline at end of filediff --git a/packages/db/drizzle/meta/0110_snapshot.json b/packages/db/drizzle/meta/0110_snapshot.jsonnew file mode 100644index 00000000..66fcf6d4--- /dev/null+++ b/packages/db/drizzle/meta/0110_snapshot.json@@ -0,0 +1,7562 @@+{+ "id": "0d5231b8-d7b4-439f-b825-f20cff65306a",+ "prevId": "1d0f6a94-2f3f-4ca3-8098-4a6cb260be8c",+ "version": "7",+ "dialect": "postgresql",+ "tables": {+ "public.account": {+ "name": "account",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "account_id": {+ "name": "account_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "provider_id": {+ "name": "provider_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "access_token": {+ "name": "access_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "refresh_token": {+ "name": "refresh_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "id_token": {+ "name": "id_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "access_token_expires_at": {+ "name": "access_token_expires_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "refresh_token_expires_at": {+ "name": "refresh_token_expires_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "scope": {+ "name": "scope",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "password": {+ "name": "password",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {+ "account_userId_idx": {+ "name": "account_userId_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "account_user_id_user_id_fk": {+ "name": "account_user_id_user_id_fk",+ "tableFrom": "account",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.apikey": {+ "name": "apikey",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "config_id": {+ "name": "config_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'default'"+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "start": {+ "name": "start",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "reference_id": {+ "name": "reference_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "prefix": {+ "name": "prefix",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "key": {+ "name": "key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "refill_interval": {+ "name": "refill_interval",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "refill_amount": {+ "name": "refill_amount",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "last_refill_at": {+ "name": "last_refill_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "enabled": {+ "name": "enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": false,+ "default": true+ },+ "rate_limit_enabled": {+ "name": "rate_limit_enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": false,+ "default": true+ },+ "rate_limit_time_window": {+ "name": "rate_limit_time_window",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "default": 1000+ },+ "rate_limit_max": {+ "name": "rate_limit_max",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "default": 100+ },+ "request_count": {+ "name": "request_count",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "default": 0+ },+ "remaining": {+ "name": "remaining",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "last_request": {+ "name": "last_request",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "expires_at": {+ "name": "expires_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ },+ "permissions": {+ "name": "permissions",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "metadata": {+ "name": "metadata",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {+ "apikey_configId_idx": {+ "name": "apikey_configId_idx",+ "columns": [+ {+ "expression": "config_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "apikey_referenceId_idx": {+ "name": "apikey_referenceId_idx",+ "columns": [+ {+ "expression": "reference_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "apikey_key_idx": {+ "name": "apikey_key_idx",+ "columns": [+ {+ "expression": "key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.passkey": {+ "name": "passkey",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "public_key": {+ "name": "public_key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "credential_id": {+ "name": "credential_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "counter": {+ "name": "counter",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "device_type": {+ "name": "device_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "backed_up": {+ "name": "backed_up",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true+ },+ "transports": {+ "name": "transports",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "aaguid": {+ "name": "aaguid",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {+ "passkey_userId_idx": {+ "name": "passkey_userId_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "passkey_credentialID_idx": {+ "name": "passkey_credentialID_idx",+ "columns": [+ {+ "expression": "credential_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "passkey_user_id_user_id_fk": {+ "name": "passkey_user_id_user_id_fk",+ "tableFrom": "passkey",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.session": {+ "name": "session",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "expires_at": {+ "name": "expires_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ },+ "ip_address": {+ "name": "ip_address",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "user_agent": {+ "name": "user_agent",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {+ "session_userId_idx": {+ "name": "session_userId_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "session_user_id_user_id_fk": {+ "name": "session_user_id_user_id_fk",+ "tableFrom": "session",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "session_token_unique": {+ "name": "session_token_unique",+ "nullsNotDistinct": false,+ "columns": [+ "token"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.user": {+ "name": "user",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "email_verified": {+ "name": "email_verified",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "image": {+ "name": "image",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "username": {+ "name": "username",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "display_username": {+ "name": "display_username",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "default": "'user'"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "user_email_unique": {+ "name": "user_email_unique",+ "nullsNotDistinct": false,+ "columns": [+ "email"+ ]+ },+ "user_username_unique": {+ "name": "user_username_unique",+ "nullsNotDistinct": false,+ "columns": [+ "username"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.verification": {+ "name": "verification",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "identifier": {+ "name": "identifier",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "value": {+ "name": "value",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "expires_at": {+ "name": "expires_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "verification_identifier_idx": {+ "name": "verification_identifier_idx",+ "columns": [+ {+ "expression": "identifier",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_chat_event": {+ "name": "agent_chat_event",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "bigserial",+ "primaryKey": true,+ "notNull": true+ },+ "message_id": {+ "name": "message_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "payload": {+ "name": "payload",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "agent_chat_event_message_idx": {+ "name": "agent_chat_event_message_idx",+ "columns": [+ {+ "expression": "message_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_chat_event_message_id_agent_chat_message_id_fk": {+ "name": "agent_chat_event_message_id_agent_chat_message_id_fk",+ "tableFrom": "agent_chat_event",+ "tableTo": "agent_chat_message",+ "columnsFrom": [+ "message_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_chat_favorite": {+ "name": "agent_chat_favorite",+ "schema": "",+ "columns": {+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "thread_id": {+ "name": "thread_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {},+ "foreignKeys": {+ "agent_chat_favorite_user_id_user_id_fk": {+ "name": "agent_chat_favorite_user_id_user_id_fk",+ "tableFrom": "agent_chat_favorite",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_chat_favorite_agent_id_ai_agent_id_fk": {+ "name": "agent_chat_favorite_agent_id_ai_agent_id_fk",+ "tableFrom": "agent_chat_favorite",+ "tableTo": "ai_agent",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "agent_chat_favorite_user_id_thread_id_pk": {+ "name": "agent_chat_favorite_user_id_thread_id_pk",+ "columns": [+ "user_id",+ "thread_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_chat_message": {+ "name": "agent_chat_message",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "thread_id": {+ "name": "thread_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "content": {+ "name": "content",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "''"+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'pending'"+ },+ "attempts": {+ "name": "attempts",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "next_attempt_at": {+ "name": "next_attempt_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "last_error": {+ "name": "last_error",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "started_at": {+ "name": "started_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "finished_at": {+ "name": "finished_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "agent_chat_message_thread_idx": {+ "name": "agent_chat_message_thread_idx",+ "columns": [+ {+ "expression": "thread_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_chat_message_due_idx": {+ "name": "agent_chat_message_due_idx",+ "columns": [+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "next_attempt_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"agent_chat_message\".\"status\" IN ('pending', 'streaming')",+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_chat_message_thread_id_agent_chat_thread_id_fk": {+ "name": "agent_chat_message_thread_id_agent_chat_thread_id_fk",+ "tableFrom": "agent_chat_message",+ "tableTo": "agent_chat_thread",+ "columnsFrom": [+ "thread_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_chat_message_agent_id_ai_agent_id_fk": {+ "name": "agent_chat_message_agent_id_ai_agent_id_fk",+ "tableFrom": "agent_chat_message",+ "tableTo": "ai_agent",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {+ "agent_chat_message_role_check": {+ "name": "agent_chat_message_role_check",+ "value": "\"agent_chat_message\".\"role\" IN ('user', 'assistant')"+ },+ "agent_chat_message_status_check": {+ "name": "agent_chat_message_status_check",+ "value": "\"agent_chat_message\".\"status\" IN ('pending', 'streaming', 'success', 'failed', 'canceled')"+ }+ },+ "isRLSEnabled": false+ },+ "public.agent_chat_thread": {+ "name": "agent_chat_thread",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "cli_session_id": {+ "name": "cli_session_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "agent_chat_thread_agent_user_idx": {+ "name": "agent_chat_thread_agent_user_idx",+ "columns": [+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "updated_at",+ "isExpression": false,+ "asc": false,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_chat_thread_agent_id_ai_agent_id_fk": {+ "name": "agent_chat_thread_agent_id_ai_agent_id_fk",+ "tableFrom": "agent_chat_thread",+ "tableTo": "ai_agent",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_chat_thread_user_id_user_id_fk": {+ "name": "agent_chat_thread_user_id_user_id_fk",+ "tableFrom": "agent_chat_thread",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_chat_usage": {+ "name": "agent_chat_usage",+ "schema": "",+ "columns": {+ "thread_id": {+ "name": "thread_id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "input_tokens": {+ "name": "input_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "output_tokens": {+ "name": "output_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "agent_chat_usage_agent_idx": {+ "name": "agent_chat_usage_agent_idx",+ "columns": [+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_chat_usage_agent_id_ai_agent_id_fk": {+ "name": "agent_chat_usage_agent_id_ai_agent_id_fk",+ "tableFrom": "agent_chat_usage",+ "tableTo": "ai_agent",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_field_trigger": {+ "name": "agent_field_trigger",+ "schema": "",+ "columns": {+ "agent_id": {+ "name": "agent_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "field_id": {+ "name": "field_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "delay_sec": {+ "name": "delay_sec",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 120+ }+ },+ "indexes": {+ "agent_field_trigger_field_idx": {+ "name": "agent_field_trigger_field_idx",+ "columns": [+ {+ "expression": "field_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_field_trigger_agent_id_ai_agent_id_fk": {+ "name": "agent_field_trigger_agent_id_ai_agent_id_fk",+ "tableFrom": "agent_field_trigger",+ "tableTo": "ai_agent",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_field_trigger_field_id_custom_field_id_fk": {+ "name": "agent_field_trigger_field_id_custom_field_id_fk",+ "tableFrom": "agent_field_trigger",+ "tableTo": "custom_field",+ "columnsFrom": [+ "field_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "agent_field_trigger_agent_id_field_id_pk": {+ "name": "agent_field_trigger_agent_id_field_id_pk",+ "columns": [+ "agent_id",+ "field_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {+ "agent_field_trigger_delay_check": {+ "name": "agent_field_trigger_delay_check",+ "value": "\"agent_field_trigger\".\"delay_sec\" >= 0 AND \"agent_field_trigger\".\"delay_sec\" <= 86400"+ }+ },+ "isRLSEnabled": false+ },+ "public.agent_run": {+ "name": "agent_run",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "schedule_id": {+ "name": "schedule_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "trigger": {+ "name": "trigger",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'delegation'"+ },+ "scheduled_for": {+ "name": "scheduled_for",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "source_activity_id": {+ "name": "source_activity_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "prompt": {+ "name": "prompt",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'pending'"+ },+ "attempts": {+ "name": "attempts",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "next_attempt_at": {+ "name": "next_attempt_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "last_error": {+ "name": "last_error",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "output": {+ "name": "output",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "input_tokens": {+ "name": "input_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "output_tokens": {+ "name": "output_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "started_at": {+ "name": "started_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "finished_at": {+ "name": "finished_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "agent_run_schedule_fire_uq": {+ "name": "agent_run_schedule_fire_uq",+ "columns": [+ {+ "expression": "schedule_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "scheduled_for",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_run_due_idx": {+ "name": "agent_run_due_idx",+ "columns": [+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "next_attempt_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_run_schedule_idx": {+ "name": "agent_run_schedule_idx",+ "columns": [+ {+ "expression": "schedule_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_run_agent_id_ai_agent_id_fk": {+ "name": "agent_run_agent_id_ai_agent_id_fk",+ "tableFrom": "agent_run",+ "tableTo": "ai_agent",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_run_issue_id_issue_id_fk": {+ "name": "agent_run_issue_id_issue_id_fk",+ "tableFrom": "agent_run",+ "tableTo": "issue",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_run_schedule_id_agent_schedule_id_fk": {+ "name": "agent_run_schedule_id_agent_schedule_id_fk",+ "tableFrom": "agent_run",+ "tableTo": "agent_schedule",+ "columnsFrom": [+ "schedule_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_run_source_activity_id_issue_activity_id_fk": {+ "name": "agent_run_source_activity_id_issue_activity_id_fk",+ "tableFrom": "agent_run",+ "tableTo": "issue_activity",+ "columnsFrom": [+ "source_activity_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {+ "agent_run_status_check": {+ "name": "agent_run_status_check",+ "value": "\"agent_run\".\"status\" IN ('pending', 'success', 'failed', 'canceled')"+ },+ "agent_run_trigger_check": {+ "name": "agent_run_trigger_check",+ "value": "\"agent_run\".\"trigger\" IN ('mention', 'delegation', 'field', 'schedule', 'manual')"+ }+ },+ "isRLSEnabled": false+ },+ "public.agent_schedule": {+ "name": "agent_schedule",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "prompt": {+ "name": "prompt",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "cron": {+ "name": "cron",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "timezone": {+ "name": "timezone",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'active'"+ },+ "next_run_at": {+ "name": "next_run_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true+ },+ "last_run_at": {+ "name": "last_run_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "agent_schedule_due_idx": {+ "name": "agent_schedule_due_idx",+ "columns": [+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "next_run_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_schedule_agent_idx": {+ "name": "agent_schedule_agent_idx",+ "columns": [+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_schedule_agent_id_ai_agent_id_fk": {+ "name": "agent_schedule_agent_id_ai_agent_id_fk",+ "tableFrom": "agent_schedule",+ "tableTo": "ai_agent",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "agent_schedule_agent_id_name_unique": {+ "name": "agent_schedule_agent_id_name_unique",+ "nullsNotDistinct": false,+ "columns": [+ "agent_id",+ "name"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {+ "agent_schedule_status_check": {+ "name": "agent_schedule_status_check",+ "value": "\"agent_schedule\".\"status\" IN ('active', 'paused')"+ }+ },+ "isRLSEnabled": false+ },+ "public.agent_skill": {+ "name": "agent_skill",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "''"+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "source_url": {+ "name": "source_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "s3_prefix": {+ "name": "s3_prefix",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "files": {+ "name": "files",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'[]'::jsonb"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "agent_skill_project_idx": {+ "name": "agent_skill_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_skill_project_id_project_id_fk": {+ "name": "agent_skill_project_id_project_id_fk",+ "tableFrom": "agent_skill",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "agent_skill_project_id_name_unique": {+ "name": "agent_skill_project_id_name_unique",+ "nullsNotDistinct": false,+ "columns": [+ "project_id",+ "name"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {+ "agent_skill_source_check": {+ "name": "agent_skill_source_check",+ "value": "\"agent_skill\".\"source\" IN ('upload', 'inline', 'github')"+ }+ },+ "isRLSEnabled": false+ },+ "public.agent_skill_link": {+ "name": "agent_skill_link",+ "schema": "",+ "columns": {+ "agent_id": {+ "name": "agent_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "skill_id": {+ "name": "skill_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {+ "agent_skill_link_skill_idx": {+ "name": "agent_skill_link_skill_idx",+ "columns": [+ {+ "expression": "skill_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_skill_link_agent_id_ai_agent_id_fk": {+ "name": "agent_skill_link_agent_id_ai_agent_id_fk",+ "tableFrom": "agent_skill_link",+ "tableTo": "ai_agent",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_skill_link_skill_id_agent_skill_id_fk": {+ "name": "agent_skill_link_skill_id_agent_skill_id_fk",+ "tableFrom": "agent_skill_link",+ "tableTo": "agent_skill",+ "columnsFrom": [+ "skill_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "agent_skill_link_agent_id_skill_id_pk": {+ "name": "agent_skill_link_agent_id_skill_id_pk",+ "columns": [+ "agent_id",+ "skill_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_tool": {+ "name": "agent_tool",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "tool_key": {+ "name": "tool_key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "credential_id": {+ "name": "credential_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "agent_tool_project_idx": {+ "name": "agent_tool_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_tool_credential_idx": {+ "name": "agent_tool_credential_idx",+ "columns": [+ {+ "expression": "credential_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_tool_project_id_project_id_fk": {+ "name": "agent_tool_project_id_project_id_fk",+ "tableFrom": "agent_tool",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_tool_credential_id_integration_credential_id_fk": {+ "name": "agent_tool_credential_id_integration_credential_id_fk",+ "tableFrom": "agent_tool",+ "tableTo": "integration_credential",+ "columnsFrom": [+ "credential_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "agent_tool_project_id_tool_key_credential_id_unique": {+ "name": "agent_tool_project_id_tool_key_credential_id_unique",+ "nullsNotDistinct": false,+ "columns": [+ "project_id",+ "tool_key",+ "credential_id"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_tool_link": {+ "name": "agent_tool_link",+ "schema": "",+ "columns": {+ "agent_id": {+ "name": "agent_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "agent_tool_id": {+ "name": "agent_tool_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {+ "agent_tool_link_tool_idx": {+ "name": "agent_tool_link_tool_idx",+ "columns": [+ {+ "expression": "agent_tool_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_tool_link_agent_id_ai_agent_id_fk": {+ "name": "agent_tool_link_agent_id_ai_agent_id_fk",+ "tableFrom": "agent_tool_link",+ "tableTo": "ai_agent",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_tool_link_agent_tool_id_agent_tool_id_fk": {+ "name": "agent_tool_link_agent_tool_id_agent_tool_id_fk",+ "tableFrom": "agent_tool_link",+ "tableTo": "agent_tool",+ "columnsFrom": [+ "agent_tool_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "agent_tool_link_agent_id_agent_tool_id_pk": {+ "name": "agent_tool_link_agent_id_agent_tool_id_pk",+ "columns": [+ "agent_id",+ "agent_tool_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.ai_agent": {+ "name": "ai_agent",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "username": {+ "name": "username",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "kind": {+ "name": "kind",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "model_credential_id": {+ "name": "model_credential_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "model": {+ "name": "model",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "instructions": {+ "name": "instructions",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "tools": {+ "name": "tools",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'[]'::jsonb"+ },+ "temperature": {+ "name": "temperature",+ "type": "double precision",+ "primaryKey": false,+ "notNull": false+ },+ "max_steps": {+ "name": "max_steps",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "trigger_on_mention": {+ "name": "trigger_on_mention",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "trigger_on_assign": {+ "name": "trigger_on_assign",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "delegation_delay_sec": {+ "name": "delegation_delay_sec",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 120+ },+ "role_id": {+ "name": "role_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "api_key_ciphertext": {+ "name": "api_key_ciphertext",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "api_key_iv": {+ "name": "api_key_iv",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "api_key_auth_tag": {+ "name": "api_key_auth_tag",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "memory_enabled": {+ "name": "memory_enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "memory_last_messages": {+ "name": "memory_last_messages",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "owner_user_id": {+ "name": "owner_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "runner_scope": {+ "name": "runner_scope",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'project'"+ },+ "last_seen_at": {+ "name": "last_seen_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "ai_agent_project_username_uq": {+ "name": "ai_agent_project_username_uq",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "lower(\"username\")",+ "asc": true,+ "isExpression": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "ai_agent_project_idx": {+ "name": "ai_agent_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "ai_agent_project_id_project_id_fk": {+ "name": "ai_agent_project_id_project_id_fk",+ "tableFrom": "ai_agent",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "ai_agent_user_id_user_id_fk": {+ "name": "ai_agent_user_id_user_id_fk",+ "tableFrom": "ai_agent",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "ai_agent_model_credential_id_integration_credential_id_fk": {+ "name": "ai_agent_model_credential_id_integration_credential_id_fk",+ "tableFrom": "ai_agent",+ "tableTo": "integration_credential",+ "columnsFrom": [+ "model_credential_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "ai_agent_role_id_project_role_id_fk": {+ "name": "ai_agent_role_id_project_role_id_fk",+ "tableFrom": "ai_agent",+ "tableTo": "project_role",+ "columnsFrom": [+ "role_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "ai_agent_owner_user_id_user_id_fk": {+ "name": "ai_agent_owner_user_id_user_id_fk",+ "tableFrom": "ai_agent",+ "tableTo": "user",+ "columnsFrom": [+ "owner_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "ai_agent_user_id_unique": {+ "name": "ai_agent_user_id_unique",+ "nullsNotDistinct": false,+ "columns": [+ "user_id"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {+ "ai_agent_kind_check": {+ "name": "ai_agent_kind_check",+ "value": "\"ai_agent\".\"kind\" IN ('external', 'internal')"+ },+ "ai_agent_runner_scope_check": {+ "name": "ai_agent_runner_scope_check",+ "value": "\"ai_agent\".\"runner_scope\" IN ('owner', 'project')"+ },+ "ai_agent_delegation_delay_check": {+ "name": "ai_agent_delegation_delay_check",+ "value": "\"ai_agent\".\"delegation_delay_sec\" >= 0 AND \"ai_agent\".\"delegation_delay_sec\" <= 86400"+ }+ },+ "isRLSEnabled": false+ },+ "public.app_secret": {+ "name": "app_secret",+ "schema": "",+ "columns": {+ "key": {+ "name": "key",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "ciphertext": {+ "name": "ciphertext",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "iv": {+ "name": "iv",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "auth_tag": {+ "name": "auth_tag",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "redacted": {+ "name": "redacted",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.app_setting": {+ "name": "app_setting",+ "schema": "",+ "columns": {+ "key": {+ "name": "key",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "value": {+ "name": "value",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.chat_attachment": {+ "name": "chat_attachment",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "public_id": {+ "name": "public_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "uploaded_by_user_id": {+ "name": "uploaded_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "s3_key": {+ "name": "s3_key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "filename": {+ "name": "filename",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "content_type": {+ "name": "content_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "size_bytes": {+ "name": "size_bytes",+ "type": "bigint",+ "primaryKey": false,+ "notNull": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "chat_attachment_project_idx": {+ "name": "chat_attachment_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "chat_attachment_project_id_project_id_fk": {+ "name": "chat_attachment_project_id_project_id_fk",+ "tableFrom": "chat_attachment",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "chat_attachment_uploaded_by_user_id_user_id_fk": {+ "name": "chat_attachment_uploaded_by_user_id_user_id_fk",+ "tableFrom": "chat_attachment",+ "tableTo": "user",+ "columnsFrom": [+ "uploaded_by_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "chat_attachment_public_id_unique": {+ "name": "chat_attachment_public_id_unique",+ "nullsNotDistinct": false,+ "columns": [+ "public_id"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.custom_field": {+ "name": "custom_field",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "issue_type_id": {+ "name": "issue_type_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "field_type": {+ "name": "field_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "member_scope": {+ "name": "member_scope",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "show_in_body": {+ "name": "show_in_body",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "position": {+ "name": "position",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "custom_field_project_id_project_id_fk": {+ "name": "custom_field_project_id_project_id_fk",+ "tableFrom": "custom_field",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "custom_field_issue_type_id_issue_type_id_fk": {+ "name": "custom_field_issue_type_id_issue_type_id_fk",+ "tableFrom": "custom_field",+ "tableTo": "issue_type",+ "columnsFrom": [+ "issue_type_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {+ "custom_field_field_type_check": {+ "name": "custom_field_field_type_check",+ "value": "\"custom_field\".\"field_type\" IN ('text', 'markdown', 'url', 'number', 'boolean', 'date', 'datetime', 'datetime_range', 'select', 'multi_select', 'member')"+ },+ "custom_field_member_scope_check": {+ "name": "custom_field_member_scope_check",+ "value": "(\"custom_field\".\"field_type\" = 'member') = (\"custom_field\".\"member_scope\" IS NOT NULL) AND (\"custom_field\".\"member_scope\" IS NULL OR \"custom_field\".\"member_scope\" IN ('all', 'humans', 'agents'))"+ }+ },+ "isRLSEnabled": false+ },+ "public.custom_field_option": {+ "name": "custom_field_option",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "field_id": {+ "name": "field_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "value": {+ "name": "value",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "color": {+ "name": "color",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'#6b7280'"+ },+ "position": {+ "name": "position",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ }+ },+ "indexes": {},+ "foreignKeys": {+ "custom_field_option_field_id_custom_field_id_fk": {+ "name": "custom_field_option_field_id_custom_field_id_fk",+ "tableFrom": "custom_field_option",+ "tableTo": "custom_field",+ "columnsFrom": [+ "field_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "custom_field_option_field_id_value_unique": {+ "name": "custom_field_option_field_id_value_unique",+ "nullsNotDistinct": false,+ "columns": [+ "field_id",+ "value"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.cycle": {+ "name": "cycle",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "goal": {+ "name": "goal",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "''"+ },+ "start_date": {+ "name": "start_date",+ "type": "date",+ "primaryKey": false,+ "notNull": true+ },+ "end_date": {+ "name": "end_date",+ "type": "date",+ "primaryKey": false,+ "notNull": true+ },+ "completed_at": {+ "name": "completed_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "cycle_project_idx": {+ "name": "cycle_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "start_date",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "cycle_project_id_project_id_fk": {+ "name": "cycle_project_id_project_id_fk",+ "tableFrom": "cycle",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {+ "cycle_dates_check": {+ "name": "cycle_dates_check",+ "value": "\"cycle\".\"end_date\" >= \"cycle\".\"start_date\""+ }+ },+ "isRLSEnabled": false+ },+ "public.initiative": {+ "name": "initiative",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "''"+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'planned'"+ },+ "owner_user_id": {+ "name": "owner_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "priority": {+ "name": "priority",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "start_date": {+ "name": "start_date",+ "type": "date",+ "primaryKey": false,+ "notNull": false+ },+ "target_date": {+ "name": "target_date",+ "type": "date",+ "primaryKey": false,+ "notNull": false+ },+ "position": {+ "name": "position",+ "type": "double precision",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "initiative_project_idx": {+ "name": "initiative_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "position",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "initiative_project_id_project_id_fk": {+ "name": "initiative_project_id_project_id_fk",+ "tableFrom": "initiative",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "initiative_owner_user_id_user_id_fk": {+ "name": "initiative_owner_user_id_user_id_fk",+ "tableFrom": "initiative",+ "tableTo": "user",+ "columnsFrom": [+ "owner_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {+ "initiative_status_check": {+ "name": "initiative_status_check",+ "value": "\"initiative\".\"status\" IN ('proposed', 'planned', 'active', 'completed', 'canceled')"+ }+ },+ "isRLSEnabled": false+ },+ "public.initiative_label": {+ "name": "initiative_label",+ "schema": "",+ "columns": {+ "initiative_id": {+ "name": "initiative_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "label_id": {+ "name": "label_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {},+ "foreignKeys": {+ "initiative_label_initiative_id_initiative_id_fk": {+ "name": "initiative_label_initiative_id_initiative_id_fk",+ "tableFrom": "initiative_label",+ "tableTo": "initiative",+ "columnsFrom": [+ "initiative_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "initiative_label_label_id_label_id_fk": {+ "name": "initiative_label_label_id_label_id_fk",+ "tableFrom": "initiative_label",+ "tableTo": "label",+ "columnsFrom": [+ "label_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "initiative_label_initiative_id_label_id_pk": {+ "name": "initiative_label_initiative_id_label_id_pk",+ "columns": [+ "initiative_id",+ "label_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.integration_credential": {+ "name": "integration_credential",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "integration_key": {+ "name": "integration_key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "label": {+ "name": "label",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "ciphertext": {+ "name": "ciphertext",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "iv": {+ "name": "iv",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "auth_tag": {+ "name": "auth_tag",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "redacted": {+ "name": "redacted",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "integration_credential_project_idx": {+ "name": "integration_credential_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "integration_credential_project_id_project_id_fk": {+ "name": "integration_credential_project_id_project_id_fk",+ "tableFrom": "integration_credential",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue": {+ "name": "issue",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "sequence_number": {+ "name": "sequence_number",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "type_id": {+ "name": "type_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "initiative_id": {+ "name": "initiative_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "cycle_id": {+ "name": "cycle_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "column_id": {+ "name": "column_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "parent_id": {+ "name": "parent_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "assignee_user_id": {+ "name": "assignee_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "delegate_user_id": {+ "name": "delegate_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "''"+ },+ "priority": {+ "name": "priority",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "estimate_points": {+ "name": "estimate_points",+ "type": "numeric",+ "primaryKey": false,+ "notNull": false+ },+ "estimate_minutes": {+ "name": "estimate_minutes",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "start_date": {+ "name": "start_date",+ "type": "date",+ "primaryKey": false,+ "notNull": false+ },+ "due_date": {+ "name": "due_date",+ "type": "date",+ "primaryKey": false,+ "notNull": false+ },+ "position": {+ "name": "position",+ "type": "double precision",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "archived_at": {+ "name": "archived_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "share_token": {+ "name": "share_token",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "share_extended": {+ "name": "share_extended",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "issue_project_active_idx": {+ "name": "issue_project_active_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "column_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"issue\".\"archived_at\" IS NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_project_title_idx": {+ "name": "issue_project_title_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "lower(btrim(\"title\"))",+ "asc": true,+ "isExpression": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_parent_idx": {+ "name": "issue_parent_idx",+ "columns": [+ {+ "expression": "parent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"issue\".\"parent_id\" IS NOT NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_cycle_idx": {+ "name": "issue_cycle_idx",+ "columns": [+ {+ "expression": "cycle_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"issue\".\"cycle_id\" IS NOT NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_project_id_project_id_fk": {+ "name": "issue_project_id_project_id_fk",+ "tableFrom": "issue",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_type_id_issue_type_id_fk": {+ "name": "issue_type_id_issue_type_id_fk",+ "tableFrom": "issue",+ "tableTo": "issue_type",+ "columnsFrom": [+ "type_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "issue_initiative_id_initiative_id_fk": {+ "name": "issue_initiative_id_initiative_id_fk",+ "tableFrom": "issue",+ "tableTo": "initiative",+ "columnsFrom": [+ "initiative_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "issue_cycle_id_cycle_id_fk": {+ "name": "issue_cycle_id_cycle_id_fk",+ "tableFrom": "issue",+ "tableTo": "cycle",+ "columnsFrom": [+ "cycle_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "issue_column_id_project_column_id_fk": {+ "name": "issue_column_id_project_column_id_fk",+ "tableFrom": "issue",+ "tableTo": "project_column",+ "columnsFrom": [+ "column_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "issue_parent_id_issue_id_fk": {+ "name": "issue_parent_id_issue_id_fk",+ "tableFrom": "issue",+ "tableTo": "issue",+ "columnsFrom": [+ "parent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "issue_assignee_user_id_user_id_fk": {+ "name": "issue_assignee_user_id_user_id_fk",+ "tableFrom": "issue",+ "tableTo": "user",+ "columnsFrom": [+ "assignee_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "issue_delegate_user_id_user_id_fk": {+ "name": "issue_delegate_user_id_user_id_fk",+ "tableFrom": "issue",+ "tableTo": "user",+ "columnsFrom": [+ "delegate_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "issue_share_token_unique": {+ "name": "issue_share_token_unique",+ "nullsNotDistinct": false,+ "columns": [+ "share_token"+ ]+ },+ "issue_project_id_sequence_number_unique": {+ "name": "issue_project_id_sequence_number_unique",+ "nullsNotDistinct": false,+ "columns": [+ "project_id",+ "sequence_number"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {+ "issue_estimate_points_check": {+ "name": "issue_estimate_points_check",+ "value": "\"issue\".\"estimate_points\" >= 0"+ },+ "issue_estimate_minutes_check": {+ "name": "issue_estimate_minutes_check",+ "value": "\"issue\".\"estimate_minutes\" >= 0"+ }+ },+ "isRLSEnabled": false+ },+ "public.issue_activity": {+ "name": "issue_activity",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "initiative_id": {+ "name": "initiative_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "kind": {+ "name": "kind",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "reply_to_id": {+ "name": "reply_to_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "actor_user_id": {+ "name": "actor_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "actor_name": {+ "name": "actor_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "body": {+ "name": "body",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "action": {+ "name": "action",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "payload": {+ "name": "payload",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "issue_activity_issue_idx": {+ "name": "issue_activity_issue_idx",+ "columns": [+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": false,+ "nulls": "last"+ },+ {+ "expression": "id",+ "isExpression": false,+ "asc": false,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_activity_reply_idx": {+ "name": "issue_activity_reply_idx",+ "columns": [+ {+ "expression": "reply_to_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_activity_initiative_idx": {+ "name": "issue_activity_initiative_idx",+ "columns": [+ {+ "expression": "initiative_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": false,+ "nulls": "last"+ },+ {+ "expression": "id",+ "isExpression": false,+ "asc": false,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_activity_issue_id_issue_id_fk": {+ "name": "issue_activity_issue_id_issue_id_fk",+ "tableFrom": "issue_activity",+ "tableTo": "issue",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_activity_initiative_id_initiative_id_fk": {+ "name": "issue_activity_initiative_id_initiative_id_fk",+ "tableFrom": "issue_activity",+ "tableTo": "initiative",+ "columnsFrom": [+ "initiative_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_activity_reply_to_id_issue_activity_id_fk": {+ "name": "issue_activity_reply_to_id_issue_activity_id_fk",+ "tableFrom": "issue_activity",+ "tableTo": "issue_activity",+ "columnsFrom": [+ "reply_to_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_activity_actor_user_id_user_id_fk": {+ "name": "issue_activity_actor_user_id_user_id_fk",+ "tableFrom": "issue_activity",+ "tableTo": "user",+ "columnsFrom": [+ "actor_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {+ "issue_activity_kind_check": {+ "name": "issue_activity_kind_check",+ "value": "\"issue_activity\".\"kind\" IN ('comment', 'activity')"+ },+ "issue_activity_owner_check": {+ "name": "issue_activity_owner_check",+ "value": "(\"issue_activity\".\"issue_id\" IS NOT NULL) <> (\"issue_activity\".\"initiative_id\" IS NOT NULL)"+ }+ },+ "isRLSEnabled": false+ },+ "public.issue_attachment": {+ "name": "issue_attachment",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "public_id": {+ "name": "public_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "issue_id": {+ "name": "issue_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "s3_key": {+ "name": "s3_key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "filename": {+ "name": "filename",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "content_type": {+ "name": "content_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "size_bytes": {+ "name": "size_bytes",+ "type": "bigint",+ "primaryKey": false,+ "notNull": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "issue_attachment_issue_idx": {+ "name": "issue_attachment_issue_idx",+ "columns": [+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_attachment_issue_id_issue_id_fk": {+ "name": "issue_attachment_issue_id_issue_id_fk",+ "tableFrom": "issue_attachment",+ "tableTo": "issue",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "issue_attachment_public_id_unique": {+ "name": "issue_attachment_public_id_unique",+ "nullsNotDistinct": false,+ "columns": [+ "public_id"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_checklist": {+ "name": "issue_checklist",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "position": {+ "name": "position",+ "type": "double precision",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "issue_checklist_issue_idx": {+ "name": "issue_checklist_issue_idx",+ "columns": [+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "position",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_checklist_issue_id_issue_id_fk": {+ "name": "issue_checklist_issue_id_issue_id_fk",+ "tableFrom": "issue_checklist",+ "tableTo": "issue",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_checklist_item": {+ "name": "issue_checklist_item",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "checklist_id": {+ "name": "checklist_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "content": {+ "name": "content",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "done": {+ "name": "done",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "position": {+ "name": "position",+ "type": "double precision",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "issue_checklist_item_checklist_idx": {+ "name": "issue_checklist_item_checklist_idx",+ "columns": [+ {+ "expression": "checklist_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "position",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_checklist_item_checklist_id_issue_checklist_id_fk": {+ "name": "issue_checklist_item_checklist_id_issue_checklist_id_fk",+ "tableFrom": "issue_checklist_item",+ "tableTo": "issue_checklist",+ "columnsFrom": [+ "checklist_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_cycle": {+ "name": "issue_cycle",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "cycle_id": {+ "name": "cycle_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "entered_at": {+ "name": "entered_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "left_at": {+ "name": "left_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {+ "issue_cycle_issue_idx": {+ "name": "issue_cycle_issue_idx",+ "columns": [+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "entered_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_cycle_cycle_idx": {+ "name": "issue_cycle_cycle_idx",+ "columns": [+ {+ "expression": "cycle_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_cycle_open_idx": {+ "name": "issue_cycle_open_idx",+ "columns": [+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "cycle_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"issue_cycle\".\"left_at\" IS NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_cycle_issue_id_issue_id_fk": {+ "name": "issue_cycle_issue_id_issue_id_fk",+ "tableFrom": "issue_cycle",+ "tableTo": "issue",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_cycle_cycle_id_cycle_id_fk": {+ "name": "issue_cycle_cycle_id_cycle_id_fk",+ "tableFrom": "issue_cycle",+ "tableTo": "cycle",+ "columnsFrom": [+ "cycle_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_field_option": {+ "name": "issue_field_option",+ "schema": "",+ "columns": {+ "issue_id": {+ "name": "issue_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "field_id": {+ "name": "field_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "option_id": {+ "name": "option_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {},+ "foreignKeys": {+ "issue_field_option_issue_id_issue_id_fk": {+ "name": "issue_field_option_issue_id_issue_id_fk",+ "tableFrom": "issue_field_option",+ "tableTo": "issue",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_field_option_field_id_custom_field_id_fk": {+ "name": "issue_field_option_field_id_custom_field_id_fk",+ "tableFrom": "issue_field_option",+ "tableTo": "custom_field",+ "columnsFrom": [+ "field_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_field_option_option_id_custom_field_option_id_fk": {+ "name": "issue_field_option_option_id_custom_field_option_id_fk",+ "tableFrom": "issue_field_option",+ "tableTo": "custom_field_option",+ "columnsFrom": [+ "option_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "issue_field_option_issue_id_field_id_option_id_pk": {+ "name": "issue_field_option_issue_id_field_id_option_id_pk",+ "columns": [+ "issue_id",+ "field_id",+ "option_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_field_value": {+ "name": "issue_field_value",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "field_id": {+ "name": "field_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "value_text": {+ "name": "value_text",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "value_number": {+ "name": "value_number",+ "type": "numeric",+ "primaryKey": false,+ "notNull": false+ },+ "value_bool": {+ "name": "value_bool",+ "type": "boolean",+ "primaryKey": false,+ "notNull": false+ },+ "value_date": {+ "name": "value_date",+ "type": "date",+ "primaryKey": false,+ "notNull": false+ },+ "value_datetime": {+ "name": "value_datetime",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "value_datetime_end": {+ "name": "value_datetime_end",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "value_user_id": {+ "name": "value_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "issue_field_value_issue_id_issue_id_fk": {+ "name": "issue_field_value_issue_id_issue_id_fk",+ "tableFrom": "issue_field_value",+ "tableTo": "issue",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_field_value_field_id_custom_field_id_fk": {+ "name": "issue_field_value_field_id_custom_field_id_fk",+ "tableFrom": "issue_field_value",+ "tableTo": "custom_field",+ "columnsFrom": [+ "field_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_field_value_value_user_id_user_id_fk": {+ "name": "issue_field_value_value_user_id_user_id_fk",+ "tableFrom": "issue_field_value",+ "tableTo": "user",+ "columnsFrom": [+ "value_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "issue_field_value_issue_id_field_id_unique": {+ "name": "issue_field_value_issue_id_field_id_unique",+ "nullsNotDistinct": false,+ "columns": [+ "issue_id",+ "field_id"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_import": {+ "name": "issue_import",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "public_id": {+ "name": "public_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "attachment_id": {+ "name": "attachment_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'mapped'"+ },+ "mapping": {+ "name": "mapping",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "error_text": {+ "name": "error_text",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "issue_import_project_idx": {+ "name": "issue_import_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_import_project_id_project_id_fk": {+ "name": "issue_import_project_id_project_id_fk",+ "tableFrom": "issue_import",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_import_attachment_id_chat_attachment_id_fk": {+ "name": "issue_import_attachment_id_chat_attachment_id_fk",+ "tableFrom": "issue_import",+ "tableTo": "chat_attachment",+ "columnsFrom": [+ "attachment_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "issue_import_public_id_unique": {+ "name": "issue_import_public_id_unique",+ "nullsNotDistinct": false,+ "columns": [+ "public_id"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_label": {+ "name": "issue_label",+ "schema": "",+ "columns": {+ "issue_id": {+ "name": "issue_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "label_id": {+ "name": "label_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {},+ "foreignKeys": {+ "issue_label_issue_id_issue_id_fk": {+ "name": "issue_label_issue_id_issue_id_fk",+ "tableFrom": "issue_label",+ "tableTo": "issue",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_label_label_id_label_id_fk": {+ "name": "issue_label_label_id_label_id_fk",+ "tableFrom": "issue_label",+ "tableTo": "label",+ "columnsFrom": [+ "label_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "issue_label_issue_id_label_id_pk": {+ "name": "issue_label_issue_id_label_id_pk",+ "columns": [+ "issue_id",+ "label_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_link": {+ "name": "issue_link",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "source_issue_id": {+ "name": "source_issue_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "target_issue_id": {+ "name": "target_issue_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "kind": {+ "name": "kind",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "issue_link_pair_kind_idx": {+ "name": "issue_link_pair_kind_idx",+ "columns": [+ {+ "expression": "least(\"source_issue_id\", \"target_issue_id\")",+ "asc": true,+ "isExpression": true,+ "nulls": "last"+ },+ {+ "expression": "greatest(\"source_issue_id\", \"target_issue_id\")",+ "asc": true,+ "isExpression": true,+ "nulls": "last"+ },+ {+ "expression": "kind",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_link_source_idx": {+ "name": "issue_link_source_idx",+ "columns": [+ {+ "expression": "source_issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_link_target_idx": {+ "name": "issue_link_target_idx",+ "columns": [+ {+ "expression": "target_issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_link_source_issue_id_issue_id_fk": {+ "name": "issue_link_source_issue_id_issue_id_fk",+ "tableFrom": "issue_link",+ "tableTo": "issue",+ "columnsFrom": [+ "source_issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_link_target_issue_id_issue_id_fk": {+ "name": "issue_link_target_issue_id_issue_id_fk",+ "tableFrom": "issue_link",+ "tableTo": "issue",+ "columnsFrom": [+ "target_issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {+ "issue_link_kind_check": {+ "name": "issue_link_kind_check",+ "value": "\"issue_link\".\"kind\" IN ('blocks', 'relates', 'duplicates')"+ },+ "issue_link_self_check": {+ "name": "issue_link_self_check",+ "value": "\"issue_link\".\"source_issue_id\" <> \"issue_link\".\"target_issue_id\""+ }+ },+ "isRLSEnabled": false+ },+ "public.issue_status": {+ "name": "issue_status",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "column_id": {+ "name": "column_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "column_name": {+ "name": "column_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "state_type": {+ "name": "state_type",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "entered_at": {+ "name": "entered_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "left_at": {+ "name": "left_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {+ "issue_status_issue_idx": {+ "name": "issue_status_issue_idx",+ "columns": [+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "entered_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_status_column_idx": {+ "name": "issue_status_column_idx",+ "columns": [+ {+ "expression": "column_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"issue_status\".\"column_id\" IS NOT NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_status_open_idx": {+ "name": "issue_status_open_idx",+ "columns": [+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"issue_status\".\"left_at\" IS NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_status_issue_id_issue_id_fk": {+ "name": "issue_status_issue_id_issue_id_fk",+ "tableFrom": "issue_status",+ "tableTo": "issue",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_status_column_id_project_column_id_fk": {+ "name": "issue_status_column_id_project_column_id_fk",+ "tableFrom": "issue_status",+ "tableTo": "project_column",+ "columnsFrom": [+ "column_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_type": {+ "name": "issue_type",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "icon": {+ "name": "icon",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "''"+ },+ "color": {+ "name": "color",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'#6b7280'"+ },+ "is_default": {+ "name": "is_default",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "position": {+ "name": "position",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "issue_type_project_id_project_id_fk": {+ "name": "issue_type_project_id_project_id_fk",+ "tableFrom": "issue_type",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "issue_type_project_id_name_unique": {+ "name": "issue_type_project_id_name_unique",+ "nullsNotDistinct": false,+ "columns": [+ "project_id",+ "name"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_watcher": {+ "name": "issue_watcher",+ "schema": "",+ "columns": {+ "issue_id": {+ "name": "issue_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "subscribed": {+ "name": "subscribed",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "issue_watcher_issue_id_issue_id_fk": {+ "name": "issue_watcher_issue_id_issue_id_fk",+ "tableFrom": "issue_watcher",+ "tableTo": "issue",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_watcher_user_id_user_id_fk": {+ "name": "issue_watcher_user_id_user_id_fk",+ "tableFrom": "issue_watcher",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "issue_watcher_issue_id_user_id_pk": {+ "name": "issue_watcher_issue_id_user_id_pk",+ "columns": [+ "issue_id",+ "user_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_worklog": {+ "name": "issue_worklog",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "minutes": {+ "name": "minutes",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "spent_on": {+ "name": "spent_on",+ "type": "date",+ "primaryKey": false,+ "notNull": true+ },+ "note": {+ "name": "note",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "issue_worklog_issue_idx": {+ "name": "issue_worklog_issue_idx",+ "columns": [+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "spent_on",+ "isExpression": false,+ "asc": false,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_worklog_issue_id_issue_id_fk": {+ "name": "issue_worklog_issue_id_issue_id_fk",+ "tableFrom": "issue_worklog",+ "tableTo": "issue",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_worklog_user_id_user_id_fk": {+ "name": "issue_worklog_user_id_user_id_fk",+ "tableFrom": "issue_worklog",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {+ "issue_worklog_minutes_check": {+ "name": "issue_worklog_minutes_check",+ "value": "\"issue_worklog\".\"minutes\" > 0"+ }+ },+ "isRLSEnabled": false+ },+ "public.label": {+ "name": "label",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "group_id": {+ "name": "group_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "color": {+ "name": "color",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'#6b7280'"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "label_project_id_project_id_fk": {+ "name": "label_project_id_project_id_fk",+ "tableFrom": "label",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "label_group_id_label_group_id_fk": {+ "name": "label_group_id_label_group_id_fk",+ "tableFrom": "label",+ "tableTo": "label_group",+ "columnsFrom": [+ "group_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "label_project_id_name_unique": {+ "name": "label_project_id_name_unique",+ "nullsNotDistinct": false,+ "columns": [+ "project_id",+ "name"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.label_group": {+ "name": "label_group",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "color": {+ "name": "color",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'#6b7280'"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "label_group_project_id_project_id_fk": {+ "name": "label_group_project_id_project_id_fk",+ "tableFrom": "label_group",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "label_group_project_id_name_unique": {+ "name": "label_group_project_id_name_unique",+ "nullsNotDistinct": false,+ "columns": [+ "project_id",+ "name"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.note_board": {+ "name": "note_board",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "owner_user_id": {+ "name": "owner_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_user_id": {+ "name": "created_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "canvas": {+ "name": "canvas",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "note_board_project_idx": {+ "name": "note_board_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "updated_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "note_board_project_id_project_id_fk": {+ "name": "note_board_project_id_project_id_fk",+ "tableFrom": "note_board",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "note_board_owner_user_id_user_id_fk": {+ "name": "note_board_owner_user_id_user_id_fk",+ "tableFrom": "note_board",+ "tableTo": "user",+ "columnsFrom": [+ "owner_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "note_board_created_by_user_id_user_id_fk": {+ "name": "note_board_created_by_user_id_user_id_fk",+ "tableFrom": "note_board",+ "tableTo": "user",+ "columnsFrom": [+ "created_by_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.note_board_member": {+ "name": "note_board_member",+ "schema": "",+ "columns": {+ "board_id": {+ "name": "board_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {+ "note_board_member_user_idx": {+ "name": "note_board_member_user_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "note_board_member_board_id_note_board_id_fk": {+ "name": "note_board_member_board_id_note_board_id_fk",+ "tableFrom": "note_board_member",+ "tableTo": "note_board",+ "columnsFrom": [+ "board_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "note_board_member_user_id_user_id_fk": {+ "name": "note_board_member_user_id_user_id_fk",+ "tableFrom": "note_board_member",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "note_board_member_board_id_user_id_pk": {+ "name": "note_board_member_board_id_user_id_pk",+ "columns": [+ "board_id",+ "user_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.notification": {+ "name": "notification",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "source_activity_id": {+ "name": "source_activity_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "actor_user_id": {+ "name": "actor_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "actor_name": {+ "name": "actor_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "read_at": {+ "name": "read_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "snoozed_until": {+ "name": "snoozed_until",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "notification_user_idx": {+ "name": "notification_user_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": false,+ "nulls": "last"+ },+ {+ "expression": "id",+ "isExpression": false,+ "asc": false,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "notification_user_unread_idx": {+ "name": "notification_user_unread_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "id",+ "isExpression": false,+ "asc": false,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"notification\".\"read_at\" IS NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "notification_user_id_user_id_fk": {+ "name": "notification_user_id_user_id_fk",+ "tableFrom": "notification",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "notification_project_id_project_id_fk": {+ "name": "notification_project_id_project_id_fk",+ "tableFrom": "notification",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "notification_issue_id_issue_id_fk": {+ "name": "notification_issue_id_issue_id_fk",+ "tableFrom": "notification",+ "tableTo": "issue",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "notification_source_activity_id_issue_activity_id_fk": {+ "name": "notification_source_activity_id_issue_activity_id_fk",+ "tableFrom": "notification",+ "tableTo": "issue_activity",+ "columnsFrom": [+ "source_activity_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "notification_actor_user_id_user_id_fk": {+ "name": "notification_actor_user_id_user_id_fk",+ "tableFrom": "notification",+ "tableTo": "user",+ "columnsFrom": [+ "actor_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {+ "notification_type_check": {+ "name": "notification_type_check",+ "value": "\"notification\".\"type\" IN ('assigned', 'mentioned', 'commented', 'state_changed')"+ }+ },+ "isRLSEnabled": false+ },+ "public.notification_delivery": {+ "name": "notification_delivery",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "channel": {+ "name": "channel",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "recipient": {+ "name": "recipient",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "payload": {+ "name": "payload",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'pending'"+ },+ "attempts": {+ "name": "attempts",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "next_attempt_at": {+ "name": "next_attempt_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "last_error": {+ "name": "last_error",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "notification_delivery_due_idx": {+ "name": "notification_delivery_due_idx",+ "columns": [+ {+ "expression": "next_attempt_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"notification_delivery\".\"status\" = 'pending'",+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "notification_delivery_project_id_project_id_fk": {+ "name": "notification_delivery_project_id_project_id_fk",+ "tableFrom": "notification_delivery",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {+ "notification_delivery_channel_check": {+ "name": "notification_delivery_channel_check",+ "value": "\"notification_delivery\".\"channel\" IN ('email', 'telegram')"+ }+ },+ "isRLSEnabled": false+ },+ "public.project": {+ "name": "project",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "key": {+ "name": "key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "''"+ },+ "next_sequence": {+ "name": "next_sequence",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 1+ },+ "mcp_enabled": {+ "name": "mcp_enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "initiatives_enabled": {+ "name": "initiatives_enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "dashboards_enabled": {+ "name": "dashboards_enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "notes_enabled": {+ "name": "notes_enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "cycles_enabled": {+ "name": "cycles_enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "subtasks_enabled": {+ "name": "subtasks_enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "checklists_enabled": {+ "name": "checklists_enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "issue_stats_enabled": {+ "name": "issue_stats_enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "points_estimate_enabled": {+ "name": "points_estimate_enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "time_estimate_enabled": {+ "name": "time_estimate_enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "time_logging_enabled": {+ "name": "time_logging_enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "project_key_unique": {+ "name": "project_key_unique",+ "nullsNotDistinct": false,+ "columns": [+ "key"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.project_action": {+ "name": "project_action",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "icon": {+ "name": "icon",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "''"+ },+ "condition": {+ "name": "condition",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "effect": {+ "name": "effect",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "position": {+ "name": "position",+ "type": "double precision",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "project_action_project_idx": {+ "name": "project_action_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "position",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "project_action_project_id_project_id_fk": {+ "name": "project_action_project_id_project_id_fk",+ "tableFrom": "project_action",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.project_column": {+ "name": "project_column",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "state_type": {+ "name": "state_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'unstarted'"+ },+ "color": {+ "name": "color",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'#6b7280'"+ },+ "position": {+ "name": "position",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "wip_limit": {+ "name": "wip_limit",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "wip_mode": {+ "name": "wip_mode",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'soft'"+ },+ "auto_assign_user_id": {+ "name": "auto_assign_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "project_column_project_id_project_id_fk": {+ "name": "project_column_project_id_project_id_fk",+ "tableFrom": "project_column",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "project_column_auto_assign_user_id_user_id_fk": {+ "name": "project_column_auto_assign_user_id_user_id_fk",+ "tableFrom": "project_column",+ "tableTo": "user",+ "columnsFrom": [+ "auto_assign_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "project_column_project_id_position_unique": {+ "name": "project_column_project_id_position_unique",+ "nullsNotDistinct": false,+ "columns": [+ "project_id",+ "position"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {+ "project_column_state_type_check": {+ "name": "project_column_state_type_check",+ "value": "\"project_column\".\"state_type\" IN ('backlog', 'unstarted', 'started', 'completed', 'canceled')"+ },+ "project_column_wip_mode_check": {+ "name": "project_column_wip_mode_check",+ "value": "\"project_column\".\"wip_mode\" IN ('soft', 'hard')"+ },+ "project_column_wip_limit_check": {+ "name": "project_column_wip_limit_check",+ "value": "\"project_column\".\"wip_limit\" IS NULL OR \"project_column\".\"wip_limit\" > 0"+ }+ },+ "isRLSEnabled": false+ },+ "public.project_dashboard": {+ "name": "project_dashboard",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "icon": {+ "name": "icon",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "layout": {+ "name": "layout",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'[]'::jsonb"+ },+ "position": {+ "name": "position",+ "type": "double precision",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "project_dashboard_project_idx": {+ "name": "project_dashboard_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "position",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "project_dashboard_project_id_project_id_fk": {+ "name": "project_dashboard_project_id_project_id_fk",+ "tableFrom": "project_dashboard",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.project_invite": {+ "name": "project_invite",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "token": {+ "name": "token",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'member'"+ },+ "role_id": {+ "name": "role_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'pending'"+ },+ "invited_by_user_id": {+ "name": "invited_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "accepted_by_user_id": {+ "name": "accepted_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "responded_at": {+ "name": "responded_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {+ "project_invite_pending_uq": {+ "name": "project_invite_pending_uq",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "email",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"project_invite\".\"status\" = 'pending'",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "project_invite_project_idx": {+ "name": "project_invite_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "project_invite_project_id_project_id_fk": {+ "name": "project_invite_project_id_project_id_fk",+ "tableFrom": "project_invite",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "project_invite_role_id_project_role_id_fk": {+ "name": "project_invite_role_id_project_role_id_fk",+ "tableFrom": "project_invite",+ "tableTo": "project_role",+ "columnsFrom": [+ "role_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "project_invite_invited_by_user_id_user_id_fk": {+ "name": "project_invite_invited_by_user_id_user_id_fk",+ "tableFrom": "project_invite",+ "tableTo": "user",+ "columnsFrom": [+ "invited_by_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "project_invite_accepted_by_user_id_user_id_fk": {+ "name": "project_invite_accepted_by_user_id_user_id_fk",+ "tableFrom": "project_invite",+ "tableTo": "user",+ "columnsFrom": [+ "accepted_by_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "project_invite_token_unique": {+ "name": "project_invite_token_unique",+ "nullsNotDistinct": false,+ "columns": [+ "token"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {+ "project_invite_role_check": {+ "name": "project_invite_role_check",+ "value": "\"project_invite\".\"role\" IN ('owner', 'member')"+ },+ "project_invite_status_check": {+ "name": "project_invite_status_check",+ "value": "\"project_invite\".\"status\" IN ('pending', 'accepted', 'rejected')"+ }+ },+ "isRLSEnabled": false+ },+ "public.project_member": {+ "name": "project_member",+ "schema": "",+ "columns": {+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'member'"+ },+ "role_id": {+ "name": "role_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "''"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "project_member_user_idx": {+ "name": "project_member_user_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "project_member_project_id_project_id_fk": {+ "name": "project_member_project_id_project_id_fk",+ "tableFrom": "project_member",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "project_member_user_id_user_id_fk": {+ "name": "project_member_user_id_user_id_fk",+ "tableFrom": "project_member",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "project_member_role_id_project_role_id_fk": {+ "name": "project_member_role_id_project_role_id_fk",+ "tableFrom": "project_member",+ "tableTo": "project_role",+ "columnsFrom": [+ "role_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "project_member_project_id_user_id_pk": {+ "name": "project_member_project_id_user_id_pk",+ "columns": [+ "project_id",+ "user_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {+ "project_member_role_check": {+ "name": "project_member_role_check",+ "value": "\"project_member\".\"role\" IN ('owner', 'member')"+ }+ },+ "isRLSEnabled": false+ },+ "public.project_notification_setting": {+ "name": "project_notification_setting",+ "schema": "",+ "columns": {+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true+ },+ "ciphertext": {+ "name": "ciphertext",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "iv": {+ "name": "iv",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "auth_tag": {+ "name": "auth_tag",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "redacted": {+ "name": "redacted",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "project_notification_setting_project_id_project_id_fk": {+ "name": "project_notification_setting_project_id_project_id_fk",+ "tableFrom": "project_notification_setting",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.project_role": {+ "name": "project_role",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "is_default": {+ "name": "is_default",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "permissions": {+ "name": "permissions",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "project_role_default_uq": {+ "name": "project_role_default_uq",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"project_role\".\"is_default\"",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "project_role_project_idx": {+ "name": "project_role_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "project_role_project_id_project_id_fk": {+ "name": "project_role_project_id_project_id_fk",+ "tableFrom": "project_role",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "project_role_project_id_name_unique": {+ "name": "project_role_project_id_name_unique",+ "nullsNotDistinct": false,+ "columns": [+ "project_id",+ "name"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.project_setting": {+ "name": "project_setting",+ "schema": "",+ "columns": {+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "key": {+ "name": "key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "value": {+ "name": "value",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "project_setting_project_id_project_id_fk": {+ "name": "project_setting_project_id_project_id_fk",+ "tableFrom": "project_setting",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "project_setting_project_id_key_pk": {+ "name": "project_setting_project_id_key_pk",+ "columns": [+ "project_id",+ "key"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.project_view": {+ "name": "project_view",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "icon": {+ "name": "icon",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "filters": {+ "name": "filters",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "display": {+ "name": "display",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "position": {+ "name": "position",+ "type": "double precision",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "share_token": {+ "name": "share_token",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "share_extended": {+ "name": "share_extended",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "project_view_project_idx": {+ "name": "project_view_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "position",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "project_view_project_id_project_id_fk": {+ "name": "project_view_project_id_project_id_fk",+ "tableFrom": "project_view",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "project_view_share_token_unique": {+ "name": "project_view_share_token_unique",+ "nullsNotDistinct": false,+ "columns": [+ "share_token"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.project_view_favorite": {+ "name": "project_view_favorite",+ "schema": "",+ "columns": {+ "view_id": {+ "name": "view_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {},+ "foreignKeys": {+ "project_view_favorite_view_id_project_view_id_fk": {+ "name": "project_view_favorite_view_id_project_view_id_fk",+ "tableFrom": "project_view_favorite",+ "tableTo": "project_view",+ "columnsFrom": [+ "view_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "project_view_favorite_user_id_user_id_fk": {+ "name": "project_view_favorite_user_id_user_id_fk",+ "tableFrom": "project_view_favorite",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "project_view_favorite_view_id_user_id_pk": {+ "name": "project_view_favorite_view_id_user_id_pk",+ "columns": [+ "view_id",+ "user_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.revision": {+ "name": "revision",+ "schema": "",+ "columns": {+ "scope": {+ "name": "scope",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "rev": {+ "name": "rev",+ "type": "bigint",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ }+ },+ "indexes": {+ "revision_project_idx": {+ "name": "revision_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.user_notification_preference": {+ "name": "user_notification_preference",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "email_events": {+ "name": "email_events",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "telegram_events": {+ "name": "telegram_events",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "user_notification_preference_user_id_user_id_fk": {+ "name": "user_notification_preference_user_id_user_id_fk",+ "tableFrom": "user_notification_preference",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "user_notification_preference_project_id_project_id_fk": {+ "name": "user_notification_preference_project_id_project_id_fk",+ "tableFrom": "user_notification_preference",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "user_notification_pref_user_project_unique": {+ "name": "user_notification_pref_user_project_unique",+ "nullsNotDistinct": false,+ "columns": [+ "user_id",+ "project_id"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.user_preference": {+ "name": "user_preference",+ "schema": "",+ "columns": {+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "timezone": {+ "name": "timezone",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'UTC'"+ },+ "locale": {+ "name": "locale",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'en'"+ },+ "theme": {+ "name": "theme",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'system'"+ },+ "issue_open_mode": {+ "name": "issue_open_mode",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'panel'"+ },+ "start_page": {+ "name": "start_page",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'work-items'"+ },+ "show_chat_by_default": {+ "name": "show_chat_by_default",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "issue_stats_open": {+ "name": "issue_stats_open",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "issue_stats_view": {+ "name": "issue_stats_view",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'compact'"+ },+ "issue_activity_view": {+ "name": "issue_activity_view",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'flat'"+ },+ "auto_watch": {+ "name": "auto_watch",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "hotkeys": {+ "name": "hotkeys",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "last_project_id": {+ "name": "last_project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "user_preference_user_id_user_id_fk": {+ "name": "user_preference_user_id_user_id_fk",+ "tableFrom": "user_preference",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "user_preference_last_project_id_project_id_fk": {+ "name": "user_preference_last_project_id_project_id_fk",+ "tableFrom": "user_preference",+ "tableTo": "project",+ "columnsFrom": [+ "last_project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {+ "user_preference_theme_check": {+ "name": "user_preference_theme_check",+ "value": "\"user_preference\".\"theme\" IN ('light', 'dark', 'system')"+ },+ "user_preference_issue_open_mode_check": {+ "name": "user_preference_issue_open_mode_check",+ "value": "\"user_preference\".\"issue_open_mode\" IN ('panel', 'page')"+ },+ "user_preference_start_page_check": {+ "name": "user_preference_start_page_check",+ "value": "\"user_preference\".\"start_page\" IN ('inbox', 'dashboard', 'work-items', 'initiatives')"+ },+ "user_preference_issue_stats_view_check": {+ "name": "user_preference_issue_stats_view_check",+ "value": "\"user_preference\".\"issue_stats_view\" IN ('compact', 'timeline')"+ },+ "user_preference_issue_activity_view_check": {+ "name": "user_preference_issue_activity_view_check",+ "value": "\"user_preference\".\"issue_activity_view\" IN ('flat', 'grouped')"+ }+ },+ "isRLSEnabled": false+ },+ "public.user_telegram_account": {+ "name": "user_telegram_account",+ "schema": "",+ "columns": {+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "chat_id": {+ "name": "chat_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "username": {+ "name": "username",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "first_name": {+ "name": "first_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "link_code": {+ "name": "link_code",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "link_code_expires_at": {+ "name": "link_code_expires_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "linked_at": {+ "name": "linked_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "user_telegram_account_chat_id_unique": {+ "name": "user_telegram_account_chat_id_unique",+ "columns": [+ {+ "expression": "chat_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"user_telegram_account\".\"chat_id\" IS NOT NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "user_telegram_account_link_code_unique": {+ "name": "user_telegram_account_link_code_unique",+ "columns": [+ {+ "expression": "link_code",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"user_telegram_account\".\"link_code\" IS NOT NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "user_telegram_account_user_id_user_id_fk": {+ "name": "user_telegram_account_user_id_user_id_fk",+ "tableFrom": "user_telegram_account",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.webhook": {+ "name": "webhook",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "url": {+ "name": "url",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "secret": {+ "name": "secret",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "events": {+ "name": "events",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'[]'::jsonb"+ },+ "is_active": {+ "name": "is_active",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "consecutive_failures": {+ "name": "consecutive_failures",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "webhook_project_idx": {+ "name": "webhook_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "webhook_project_id_project_id_fk": {+ "name": "webhook_project_id_project_id_fk",+ "tableFrom": "webhook",+ "tableTo": "project",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.webhook_delivery": {+ "name": "webhook_delivery",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "serial",+ "primaryKey": true,+ "notNull": true+ },+ "webhook_id": {+ "name": "webhook_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "event_id": {+ "name": "event_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "event_type": {+ "name": "event_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "payload": {+ "name": "payload",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'pending'"+ },+ "attempts": {+ "name": "attempts",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "next_attempt_at": {+ "name": "next_attempt_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "last_error": {+ "name": "last_error",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "response_status": {+ "name": "response_status",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "response_body": {+ "name": "response_body",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "webhook_delivery_due_idx": {+ "name": "webhook_delivery_due_idx",+ "columns": [+ {+ "expression": "next_attempt_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"webhook_delivery\".\"status\" = 'pending'",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "webhook_delivery_webhook_idx": {+ "name": "webhook_delivery_webhook_idx",+ "columns": [+ {+ "expression": "webhook_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "webhook_delivery_webhook_id_webhook_id_fk": {+ "name": "webhook_delivery_webhook_id_webhook_id_fk",+ "tableFrom": "webhook_delivery",+ "tableTo": "webhook",+ "columnsFrom": [+ "webhook_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ }+ },+ "enums": {},+ "schemas": {},+ "sequences": {},+ "roles": {},+ "policies": {},+ "views": {},+ "_meta": {+ "columns": {},+ "schemas": {},+ "tables": {}+ }+}\ No newline at end of filediff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.jsonindex 353029c1..f1e152ff 100644--- a/packages/db/drizzle/meta/_journal.json+++ b/packages/db/drizzle/meta/_journal.json@@ -771,6 +771,13 @@"when": 1787913096305,"tag": "0109_curious_doctor_faustus","breakpoints": true+ },+ {+ "idx": 110,+ "version": "7",+ "when": 1787915227537,+ "tag": "0110_spooky_the_santerians",+ "breakpoints": true}]}\ No newline at end of filediff --git a/packages/db/src/schema/app.ts b/packages/db/src/schema/app.tsindex 799d9007..cca538df 100644--- a/packages/db/src/schema/app.ts+++ b/packages/db/src/schema/app.ts@@ -633,6 +633,24 @@ export const agentChatUsage = pgTable((t) => [index('agent_chat_usage_agent_idx').on(t.agentId)],);+// The conversations a member has starred, so they stay within reach in the chat+// history. Like agent_chat_usage the row carries no foreign key to the thread: an+// internal agent's thread lives in Mastra's own tables. Deleting a thread deletes its+// row; a row left behind is harmless, since the history is built from the threads.+export const agentChatFavorite = pgTable(+ 'agent_chat_favorite',+ {+ userId: text('user_id')+ .notNull()+ .references(() => user.id, { onDelete: 'cascade' }),+ agentId: integer('agent_id')+ .notNull()+ .references(() => aiAgent.id, { onDelete: 'cascade' }),+ threadId: text('thread_id').notNull(),+ },+ (t) => [primaryKey({ columns: [t.userId, t.threadId] })],+);+// Stored credentials for a project's integrations. One store for every secret: the// API keys of LLM providers (kind 'llm', addressed by an internal agent's model) and// the credentials of tool integrations (kind 'tool', bound to configured tools).