diff --git a/CHANGELOG.md b/CHANGELOG.md index 47582fb0d..6ed59ca3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,11 @@ This project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Packages without a separate changelog are covered by the cross-package notes below. -## [Unreleased] +## [Unreleased - Patch] + +### Fixed + +- Channel and DM message history (`GET /v1/channels/:name/messages`, `GET /v1/dm/:conversation_id/messages` and the workspace-key `GET /v1/dm/conversations/:conversation_id/messages`) now lists messages newest first in true numeric id order, and `before`/`after` cursors no longer skip messages. Message ids grew from 17 to 18 digits in October 2025, and history spanning that change was misordered. ## [12.13.1] - 2026-11-20 diff --git a/packages/engine/CHANGELOG.md b/packages/engine/CHANGELOG.md index 067b57e73..9c33fa9ad 100644 --- a/packages/engine/CHANGELOG.md +++ b/packages/engine/CHANGELOG.md @@ -7,7 +7,11 @@ See the [root changelog](../../CHANGELOG.md) for cross-package release highlight The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [Unreleased - Patch] + +### Fixed + +- `getMessages`, `getDmMessages` and `getDmMessagesForWorkspace` order and compare message ids numerically, by `(length(id), id)`, instead of as text. Snowflake ids are decimal TEXT that widened from 17 to 18 digits in October 2025, so history spanning that change was misordered and `before`/`after` cursors skipped messages across it. A `before` page is read in at most two index seeks. The new `idx_messages_channel_length_id` index `(channel_id, length(id), id)` replaces `idx_messages_channel_time` (SQLite migration 0087, Postgres 0008, where the id is indexed `COLLATE "C"`). ## [12.13.1] - 2026-11-20 diff --git a/packages/engine/src/__tests__/conformance/mixedWidthHistory.test.ts b/packages/engine/src/__tests__/conformance/mixedWidthHistory.test.ts new file mode 100644 index 000000000..74b3e6b78 --- /dev/null +++ b/packages/engine/src/__tests__/conformance/mixedWidthHistory.test.ts @@ -0,0 +1,122 @@ +import { eq } from 'drizzle-orm'; +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; +import { dmConversations, messages } from '../../db/tables.js'; +import { createWorkspace, makeNodeStack, registerAgent, type TestStack } from './harness.js'; +import { conformancePgDb } from './pgMode.js'; + +/** + * Snowflake ids are decimal TEXT that widened from 17 to 18 digits in 2025-10. + * History spanning that change must page in numeric order: bare text order + * puts every `9…` 17-digit id after (newer than) any `1…` 18-digit id, and + * text `before`/`after` cursors skip across the boundary. + */ +const NARROW = ['98000000000000001', '98000000000000002', '98000000000000003']; // 17 digits, older +const WIDE = ['100000000000000001', '100000000000000002', '100000000000000003']; // 18 digits, newer + +describe('message history across the snowflake width change', () => { + let stack: TestStack; + beforeEach(() => { stack = makeNodeStack(); }); + afterEach(async () => { await stack.close(); }); + + const get = async (token: string, path: string) => { + const res = await stack.app.request(path, { headers: { authorization: `Bearer ${token}` } }); + expect(res.status).toBe(200); + return ((await res.json()).data as Array<{ id: string }>).map((m) => m.id); + }; + + async function seed(workspaceId: string, channelId: string, agentId: string) { + const ids = [...NARROW, ...WIDE]; + await stack.runtime.deps.db.insert(messages).values(ids.map((id, i) => ({ + id, + workspaceId, + channelId, + agentId, + body: `m-${id}`, + createdAt: new Date(Date.UTC(2025, 9, 1, 0, 0, i)), + }))); + } + + /** Every cursor shape a client uses, against one history endpoint. */ + async function expectNumericPaging(token: string, path: string, newest: string[]) { + const all = [...newest, ...[...WIDE].reverse(), ...[...NARROW].reverse()]; + const q = (params: string) => get(token, `${path}?${params}`); + + expect(await q('limit=100')).toEqual(all); + // `before` crossing the width boundary, entirely and mid-page. + expect(await q(`limit=100&before=${WIDE[0]}`)).toEqual([...NARROW].reverse()); + expect(await q(`limit=2&before=${WIDE[1]}`)).toEqual([WIDE[0], NARROW[2]]); + // `after` crossing it (newest-first page of everything newer). + expect(await q(`limit=100&after=${NARROW[2]}`)).toEqual([...newest, ...[...WIDE].reverse()]); + expect(await q(`limit=100&after=${NARROW[0]}&before=${WIDE[1]}`)).toEqual([WIDE[0], NARROW[2], NARROW[1]]); + // Equal-width cursors are unchanged. + expect(await q(`limit=1&before=${WIDE[2]}`)).toEqual([WIDE[1]]); + expect(await q(`limit=100&before=${NARROW[2]}`)).toEqual([NARROW[1], NARROW[0]]); + expect(await q(`limit=100&after=${WIDE[0]}`)).toEqual([...newest, WIDE[2], WIDE[1]]); + + // Walking `before` pages visits every message exactly once, in order. + const walked: string[] = []; + let page = await q('limit=2'); + while (page.length > 0) { + walked.push(...page); + page = await q(`limit=2&before=${page[page.length - 1]}`); + } + expect(walked).toEqual(all); + } + + it('pages channel history numerically through the channel length-id index', async () => { + const ws = await createWorkspace(stack.app, 'mixed-width-channel'); + const agent = await registerAgent(stack.app, ws.workspaceKey, 'author'); + const created = await stack.app.request('/v1/channels', { + method: 'POST', + headers: { authorization: `Bearer ${agent.token}`, 'content-type': 'application/json' }, + body: JSON.stringify({ name: 'history' }), + }); + expect(created.status).toBe(201); + const channelId = (await created.json()).data.id as string; + await seed(ws.workspaceId, channelId, agent.agentId); + + await expectNumericPaging(agent.token, '/v1/channels/history/messages', []); + + if (conformancePgDb()) return; + // Both page shapes seek the channel index without a sort. + const sqlite = stack.runtime.handle.sqlite; + const plan = (where: string, order: string) => (sqlite.prepare(` + EXPLAIN QUERY PLAN SELECT messages.id FROM messages INDEXED BY idx_messages_channel_length_id + WHERE messages.channel_id = ? AND messages.workspace_id = ? AND messages.thread_id IS NULL AND ${where} + ORDER BY ${order} LIMIT 50 + `).all(channelId, ws.workspaceId) as Array<{ detail: string }>).map((s) => s.detail).join('\n'); + const sameWidth = plan(`length(messages.id) = 18 AND messages.id < '${WIDE[1]}'`, 'messages.id DESC'); + expect(sameWidth).toContain('idx_messages_channel_length_id (channel_id=? AND =? AND id { + const ws = await createWorkspace(stack.app, 'mixed-width-dm'); + const alice = await registerAgent(stack.app, ws.workspaceKey, 'alice'); + await registerAgent(stack.app, ws.workspaceKey, 'bob'); + const sent = await stack.app.request('/v1/dm', { + method: 'POST', + headers: { authorization: `Bearer ${alice.token}`, 'content-type': 'application/json' }, + body: JSON.stringify({ to: 'bob', text: 'opener' }), + }); + expect(sent.status).toBe(201); + const opener = (await sent.json()).data as { id: string; conversation_id: string }; + // The opener has a real, current (18+ digit) id: newest of all. + expect(opener.id.length).toBeGreaterThanOrEqual(18); + const [conv] = await stack.runtime.deps.db + .select({ channelId: dmConversations.channelId }) + .from(dmConversations) + .where(eq(dmConversations.id, opener.conversation_id)); + await seed(ws.workspaceId, conv.channelId, alice.agentId); + + await expectNumericPaging(alice.token, `/v1/dm/${opener.conversation_id}/messages`, [opener.id]); + await expectNumericPaging( + ws.workspaceKey, + `/v1/dm/conversations/${opener.conversation_id}/messages`, + [opener.id], + ); + }); +}); diff --git a/packages/engine/src/adapters/actor/migrations.generated.ts b/packages/engine/src/adapters/actor/migrations.generated.ts index 7d9476683..8da384813 100644 --- a/packages/engine/src/adapters/actor/migrations.generated.ts +++ b/packages/engine/src/adapters/actor/migrations.generated.ts @@ -880,6 +880,13 @@ export const ACTOR_MIGRATIONS: readonly (readonly [string, readonly string[]])[] [ "ALTER TABLE workspaces\n ADD COLUMN leaders text" ] + ], + [ + "0087_messages_channel_length_id_index.sql", + [ + "CREATE INDEX IF NOT EXISTS idx_messages_channel_length_id\n ON messages(channel_id, length(id), id)", + "DROP INDEX IF EXISTS idx_messages_channel_time" + ] ] ]; diff --git a/packages/engine/src/adapters/postgres/__tests__/migrate.test.ts b/packages/engine/src/adapters/postgres/__tests__/migrate.test.ts index 04b7221f6..4e3618315 100644 --- a/packages/engine/src/adapters/postgres/__tests__/migrate.test.ts +++ b/packages/engine/src/adapters/postgres/__tests__/migrate.test.ts @@ -193,6 +193,7 @@ describe("loadBundledPostgresMigrations", () => { "0005_delivery_confirmation.sql", "0006_action_invocation_requester.sql", "0007_workspace_leaders.sql", + "0008_messages_channel_length_id.sql", ]); expect(bundled.every((m) => m.statements.length > 0)).toBe(true); }); diff --git a/packages/engine/src/db/__tests__/dmReadCursorMigration.test.ts b/packages/engine/src/db/__tests__/dmReadCursorMigration.test.ts index f62dec8b6..641dc5125 100644 --- a/packages/engine/src/db/__tests__/dmReadCursorMigration.test.ts +++ b/packages/engine/src/db/__tests__/dmReadCursorMigration.test.ts @@ -27,7 +27,7 @@ it('seeds DM read cursors from the newest read receipt, ordered numerically', () INSERT INTO read_receipts(message_id,agent_id) VALUES ('${older}','bob'),('${newer}','bob'),('2${'0'.repeat(17)}','alice');`); - expect(runMigrations(handle).applied).toEqual(['0078_dm_participant_read_cursor.sql', '0079_credential_upgrades.sql', '0080_nodes_context_reachable_index.sql', '0081_delivery_confirmation.sql', '0082_pending_events_settled_retention.sql', '0083_strict_spawn_placement_token.sql', '0084_strict_spawn_dispatch_generation.sql', '0085_action_invocation_requester.sql', '0086_workspace_leaders.sql']); + expect(runMigrations(handle).applied).toEqual(['0078_dm_participant_read_cursor.sql', '0079_credential_upgrades.sql', '0080_nodes_context_reachable_index.sql', '0081_delivery_confirmation.sql', '0082_pending_events_settled_retention.sql', '0083_strict_spawn_placement_token.sql', '0084_strict_spawn_dispatch_generation.sql', '0085_action_invocation_requester.sql', '0086_workspace_leaders.sql', '0087_messages_channel_length_id_index.sql']); const cursors = db.prepare('SELECT agent_id, last_read_id FROM dm_participants ORDER BY agent_id').all(); // A receipt in another channel does not seed a DM cursor. diff --git a/packages/engine/src/db/__tests__/handlerSnapshotBackfillMigration.test.ts b/packages/engine/src/db/__tests__/handlerSnapshotBackfillMigration.test.ts index f1fd2359f..35c3eb133 100644 --- a/packages/engine/src/db/__tests__/handlerSnapshotBackfillMigration.test.ts +++ b/packages/engine/src/db/__tests__/handlerSnapshotBackfillMigration.test.ts @@ -46,6 +46,7 @@ describe('registered invocation handler snapshot backfill', () => { '0084_strict_spawn_dispatch_generation.sql', '0085_action_invocation_requester.sql', '0086_workspace_leaders.sql', + '0087_messages_channel_length_id_index.sql', ]); expect(handle.sqlite.prepare(` SELECT id, handler_agent_id, handler_node_id, spawn_dispatch_generation diff --git a/packages/engine/src/db/__tests__/taskMigration.test.ts b/packages/engine/src/db/__tests__/taskMigration.test.ts index 7b2ac086b..720e015ed 100644 --- a/packages/engine/src/db/__tests__/taskMigration.test.ts +++ b/packages/engine/src/db/__tests__/taskMigration.test.ts @@ -50,6 +50,7 @@ it('upgrades existing actions and results additively, preserving rows and every '0084_strict_spawn_dispatch_generation.sql', '0085_action_invocation_requester.sql', '0086_workspace_leaders.sql', + '0087_messages_channel_length_id_index.sql', ]); for (const table of before) { const columns = db.pragma(`table_info(${table.name})`) as { name: string }[]; diff --git a/packages/engine/src/db/migrations-pg/0008_messages_channel_length_id.sql b/packages/engine/src/db/migrations-pg/0008_messages_channel_length_id.sql new file mode 100644 index 000000000..20b4f5982 --- /dev/null +++ b/packages/engine/src/db/migrations-pg/0008_messages_channel_length_id.sql @@ -0,0 +1,2 @@ +DROP INDEX "idx_messages_channel_time";--> statement-breakpoint +CREATE INDEX "idx_messages_channel_length_id" ON "messages" USING btree ("channel_id",length("id"),"id" COLLATE "C"); \ No newline at end of file diff --git a/packages/engine/src/db/migrations-pg/meta/0008_snapshot.json b/packages/engine/src/db/migrations-pg/meta/0008_snapshot.json new file mode 100644 index 000000000..f559c702d --- /dev/null +++ b/packages/engine/src/db/migrations-pg/meta/0008_snapshot.json @@ -0,0 +1,9890 @@ +{ + "id": "d9a06432-3169-4102-9ef4-204360de4739", + "prevId": "ce74bbac-d4f6-46c1-b075-653b6da3c982", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.a2a_agents": { + "name": "a2a_agents", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "a2a_agents_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "relay_agent_id": { + "name": "relay_agent_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_card": { + "name": "agent_card", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "external_url": { + "name": "external_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "auth_scheme": { + "name": "auth_scheme", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "auth_credential": { + "name": "auth_credential", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "messages_sent": { + "name": "messages_sent", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "messages_recv": { + "name": "messages_recv", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_health": { + "name": "last_health", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "health_failures": { + "name": "health_failures", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "a2a_agents_rowid_unique": { + "name": "a2a_agents_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_a2a_agents_workspace": { + "name": "idx_a2a_agents_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_a2a_agents_relay_agent": { + "name": "idx_a2a_agents_relay_agent", + "columns": [ + { + "expression": "relay_agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "a2a_agents_workspace_id_workspaces_id_fk": { + "name": "a2a_agents_workspace_id_workspaces_id_fk", + "tableFrom": "a2a_agents", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "a2a_agents_relay_agent_id_agents_id_fk": { + "name": "a2a_agents_relay_agent_id_agents_id_fk", + "tableFrom": "a2a_agents", + "tableTo": "agents", + "columnsFrom": [ + "relay_agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.a2a_egress": { + "name": "a2a_egress", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "a2a_egress_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_id": { + "name": "target_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "external_url": { + "name": "external_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "fingerprint": { + "name": "fingerprint", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "claim_token": { + "name": "claim_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lease_until": { + "name": "lease_until", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error_status": { + "name": "error_status", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "error_code": { + "name": "error_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "a2a_egress_rowid_unique": { + "name": "a2a_egress_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_a2a_egress_workspace": { + "name": "idx_a2a_egress_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_a2a_egress_due": { + "name": "idx_a2a_egress_due", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lease_until", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_a2a_egress_retention": { + "name": "idx_a2a_egress_retention", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "a2a_egress_workspace_id_workspaces_id_fk": { + "name": "a2a_egress_workspace_id_workspaces_id_fk", + "tableFrom": "a2a_egress", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.a2a_egress_context": { + "name": "a2a_egress_context", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "a2a_egress_context_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "response": { + "name": "response", + "type": "json", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "a2a_egress_context_rowid_unique": { + "name": "a2a_egress_context_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_a2a_egress_context_message": { + "name": "idx_a2a_egress_context_message", + "columns": [ + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "a2a_egress_context_id_a2a_egress_id_fk": { + "name": "a2a_egress_context_id_a2a_egress_id_fk", + "tableFrom": "a2a_egress_context", + "tableTo": "a2a_egress", + "columnsFrom": [ + "id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "a2a_egress_context_message_id_messages_id_fk": { + "name": "a2a_egress_context_message_id_messages_id_fk", + "tableFrom": "a2a_egress_context", + "tableTo": "messages", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.a2a_inbound": { + "name": "a2a_inbound", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "a2a_inbound_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "fingerprint": { + "name": "fingerprint", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "response": { + "name": "response", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "a2a_inbound_rowid_unique": { + "name": "a2a_inbound_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_a2a_inbound_workspace": { + "name": "idx_a2a_inbound_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_a2a_inbound_message": { + "name": "idx_a2a_inbound_message", + "columns": [ + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_a2a_inbound_retention": { + "name": "idx_a2a_inbound_retention", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "a2a_inbound_workspace_id_workspaces_id_fk": { + "name": "a2a_inbound_workspace_id_workspaces_id_fk", + "tableFrom": "a2a_inbound", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "a2a_inbound_message_id_messages_id_fk": { + "name": "a2a_inbound_message_id_messages_id_fk", + "tableFrom": "a2a_inbound", + "tableTo": "messages", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.action_invocations": { + "name": "action_invocations", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "action_invocations_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "action_id": { + "name": "action_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action_name": { + "name": "action_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "invocation_origin": { + "name": "invocation_origin", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'legacy_unknown'" + }, + "caller_id": { + "name": "caller_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "caller_name": { + "name": "caller_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "requester_agent_id": { + "name": "requester_agent_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "requester_name": { + "name": "requester_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "handler_agent_id": { + "name": "handler_agent_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "handler_node_id": { + "name": "handler_node_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "spawn_placement_token": { + "name": "spawn_placement_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "input": { + "name": "input", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "task_state": { + "name": "task_state", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "output": { + "name": "output", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "dispatched_node_id": { + "name": "dispatched_node_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "dispatched_at": { + "name": "dispatched_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "spawn_dispatch_generation": { + "name": "spawn_dispatch_generation", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "node_liveness_revision": { + "name": "node_liveness_revision", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "provider_accepted_attempt": { + "name": "provider_accepted_attempt", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "spawn_reserved_at": { + "name": "spawn_reserved_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "attempted_node_ids": { + "name": "attempted_node_ids", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "dispatch_attempts": { + "name": "dispatch_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "dispatched_provider": { + "name": "dispatched_provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "retry_after_at": { + "name": "retry_after_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "handler_unreachable_since": { + "name": "handler_unreachable_since", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "completed_at": { + "name": "completed_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "action_invocations_rowid_unique": { + "name": "action_invocations_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_action_invocations_workspace": { + "name": "idx_action_invocations_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_action_invocations_action": { + "name": "idx_action_invocations_action", + "columns": [ + { + "expression": "action_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_action_invocations_caller": { + "name": "idx_action_invocations_caller", + "columns": [ + { + "expression": "caller_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_action_invocations_dispatched_node": { + "name": "idx_action_invocations_dispatched_node", + "columns": [ + { + "expression": "dispatched_node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_action_invocations_dispatched_node_liveness_revision": { + "name": "idx_action_invocations_dispatched_node_liveness_revision", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "dispatched_node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "node_liveness_revision", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"action_invocations\".\"dispatched_node_id\" IS NOT NULL AND \"action_invocations\".\"status\" IN ('pending', 'dispatched', 'invoked')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_action_invocations_pending_workspace": { + "name": "idx_action_invocations_pending_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"action_invocations\".\"status\" = 'pending'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_action_invocations_spawn_canceled": { + "name": "idx_action_invocations_spawn_canceled", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "dispatched_node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_action_invocations_status_dispatched": { + "name": "idx_action_invocations_status_dispatched", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "dispatched_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_action_invocations_status_retry_after": { + "name": "idx_action_invocations_status_retry_after", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "retry_after_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_action_invocations_status_task_deadline": { + "name": "idx_action_invocations_status_task_deadline", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "((\"task_state\" ->> 'deadline') COLLATE \"C\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"action_invocations\".\"task_state\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_action_invocations_task_deadline": { + "name": "idx_action_invocations_task_deadline", + "columns": [ + { + "expression": "((\"task_state\" ->> 'deadline') COLLATE \"C\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"action_invocations\".\"task_state\" IS NOT NULL AND \"action_invocations\".\"status\" IN ('pending', 'dispatched', 'running')", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "action_invocations_workspace_id_workspaces_id_fk": { + "name": "action_invocations_workspace_id_workspaces_id_fk", + "tableFrom": "action_invocations", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "action_invocations_action_id_actions_id_fk": { + "name": "action_invocations_action_id_actions_id_fk", + "tableFrom": "action_invocations", + "tableTo": "actions", + "columnsFrom": [ + "action_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "action_invocations_caller_id_agents_id_fk": { + "name": "action_invocations_caller_id_agents_id_fk", + "tableFrom": "action_invocations", + "tableTo": "agents", + "columnsFrom": [ + "caller_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "action_invocations_requester_agent_id_agents_id_fk": { + "name": "action_invocations_requester_agent_id_agents_id_fk", + "tableFrom": "action_invocations", + "tableTo": "agents", + "columnsFrom": [ + "requester_agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "action_invocations_dispatched_node_id_nodes_id_fk": { + "name": "action_invocations_dispatched_node_id_nodes_id_fk", + "tableFrom": "action_invocations", + "tableTo": "nodes", + "columnsFrom": [ + "dispatched_node_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "action_invocations_invocation_origin_check": { + "name": "action_invocations_invocation_origin_check", + "value": "\"action_invocations\".\"invocation_origin\" IN ('legacy_unknown', 'registered_action', 'builtin')" + } + }, + "isRLSEnabled": false + }, + "public.actions": { + "name": "actions", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "actions_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "handler_agent_id": { + "name": "handler_agent_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "handler_node_id": { + "name": "handler_node_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "handler_provider": { + "name": "handler_provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_global": { + "name": "is_global", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "queue": { + "name": "queue", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "execution_mode": { + "name": "execution_mode", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'short'" + }, + "input_schema": { + "name": "input_schema", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "output_schema": { + "name": "output_schema", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "available_to": { + "name": "available_to", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "actions_rowid_unique": { + "name": "actions_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "actions_workspace_node_name_unique": { + "name": "actions_workspace_node_name_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "handler_node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "actions_workspace_agent_name_unique": { + "name": "actions_workspace_agent_name_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"actions\".\"handler_node_id\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "actions_workspace_global_name_unique": { + "name": "actions_workspace_global_name_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"actions\".\"is_global\" = true", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_actions_workspace": { + "name": "idx_actions_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_actions_handler": { + "name": "idx_actions_handler", + "columns": [ + { + "expression": "handler_agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_actions_node_handler": { + "name": "idx_actions_node_handler", + "columns": [ + { + "expression": "handler_node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "actions_workspace_id_workspaces_id_fk": { + "name": "actions_workspace_id_workspaces_id_fk", + "tableFrom": "actions", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "actions_handler_agent_id_agents_id_fk": { + "name": "actions_handler_agent_id_agents_id_fk", + "tableFrom": "actions", + "tableTo": "agents", + "columnsFrom": [ + "handler_agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "actions_handler_node_id_nodes_id_fk": { + "name": "actions_handler_node_id_nodes_id_fk", + "tableFrom": "actions", + "tableTo": "nodes", + "columnsFrom": [ + "handler_node_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.agent_identity_audit": { + "name": "agent_identity_audit", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "agent_identity_audit_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_id": { + "name": "agent_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_name": { + "name": "agent_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "authority": { + "name": "authority", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "actor": { + "name": "actor", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "session_ref": { + "name": "session_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "node_id": { + "name": "node_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "origin_actor": { + "name": "origin_actor", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "agent_identity_audit_rowid_unique": { + "name": "agent_identity_audit_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_agent_identity_audit_workspace": { + "name": "idx_agent_identity_audit_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_agent_identity_audit_agent": { + "name": "idx_agent_identity_audit_agent", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "agent_identity_audit_workspace_id_workspaces_id_fk": { + "name": "agent_identity_audit_workspace_id_workspaces_id_fk", + "tableFrom": "agent_identity_audit", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.agent_node_bindings": { + "name": "agent_node_bindings", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "agent_node_bindings_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_id": { + "name": "agent_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "node_id": { + "name": "node_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "session_ref": { + "name": "session_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "priority": { + "name": "priority", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "agent_node_bindings_rowid_unique": { + "name": "agent_node_bindings_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "agent_node_bindings_agent_node_unique": { + "name": "agent_node_bindings_agent_node_unique", + "columns": [ + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_agent_node_bindings_workspace": { + "name": "idx_agent_node_bindings_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_agent_node_bindings_agent": { + "name": "idx_agent_node_bindings_agent", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_agent_node_bindings_node": { + "name": "idx_agent_node_bindings_node", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_agent_node_bindings_node_fk": { + "name": "idx_agent_node_bindings_node_fk", + "columns": [ + { + "expression": "node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "agent_node_bindings_workspace_id_workspaces_id_fk": { + "name": "agent_node_bindings_workspace_id_workspaces_id_fk", + "tableFrom": "agent_node_bindings", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "agent_node_bindings_agent_id_agents_id_fk": { + "name": "agent_node_bindings_agent_id_agents_id_fk", + "tableFrom": "agent_node_bindings", + "tableTo": "agents", + "columnsFrom": [ + "agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "agent_node_bindings_node_id_nodes_id_fk": { + "name": "agent_node_bindings_node_id_nodes_id_fk", + "tableFrom": "agent_node_bindings", + "tableTo": "nodes", + "columnsFrom": [ + "node_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "agent_node_bindings_agent_workspace_fk": { + "name": "agent_node_bindings_agent_workspace_fk", + "tableFrom": "agent_node_bindings", + "tableTo": "agents", + "columnsFrom": [ + "workspace_id", + "agent_id" + ], + "columnsTo": [ + "workspace_id", + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "agent_node_bindings_node_workspace_fk": { + "name": "agent_node_bindings_node_workspace_fk", + "tableFrom": "agent_node_bindings", + "tableTo": "nodes", + "columnsFrom": [ + "workspace_id", + "node_id" + ], + "columnsTo": [ + "workspace_id", + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.agent_recovery_credentials": { + "name": "agent_recovery_credentials", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "agent_recovery_credentials_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_id": { + "name": "agent_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "proof_kind": { + "name": "proof_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "verifier_hash": { + "name": "verifier_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "work_unit_id": { + "name": "work_unit_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "agent_recovery_credentials_rowid_unique": { + "name": "agent_recovery_credentials_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "agent_recovery_credentials_agent_unique": { + "name": "agent_recovery_credentials_agent_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "agent_recovery_credentials_verifier_unique": { + "name": "agent_recovery_credentials_verifier_unique", + "columns": [ + { + "expression": "verifier_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "agent_recovery_credentials_workspace_id_workspaces_id_fk": { + "name": "agent_recovery_credentials_workspace_id_workspaces_id_fk", + "tableFrom": "agent_recovery_credentials", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "agent_recovery_credentials_agent_fk": { + "name": "agent_recovery_credentials_agent_fk", + "tableFrom": "agent_recovery_credentials", + "tableTo": "agents", + "columnsFrom": [ + "workspace_id", + "agent_id" + ], + "columnsTo": [ + "workspace_id", + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.agents": { + "name": "agents", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "agents_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'agent'" + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "previous_token_hash": { + "name": "previous_token_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "previous_token_expires_at": { + "name": "previous_token_expires_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'online'" + }, + "handle": { + "name": "handle", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "persona": { + "name": "persona", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "capabilities": { + "name": "capabilities", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "location_type": { + "name": "location_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'self_connected'" + }, + "location_node_id": { + "name": "location_node_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_name": { + "name": "provider_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'default'" + }, + "resumable": { + "name": "resumable", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "session_ref": { + "name": "session_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "origin_node_id": { + "name": "origin_node_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_ack_seq": { + "name": "delivery_ack_seq", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "delivery_seq": { + "name": "delivery_seq", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "last_seen": { + "name": "last_seen", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "status_updated_at": { + "name": "status_updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "status_before_liveness_loss": { + "name": "status_before_liveness_loss", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "node_liveness_revision": { + "name": "node_liveness_revision", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": { + "agents_rowid_unique": { + "name": "agents_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "agents_workspace_name_unique": { + "name": "agents_workspace_name_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_agents_workspace": { + "name": "idx_agents_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_agents_roster": { + "name": "idx_agents_roster", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_seen", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"agents\".\"status\" <> 'released'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_agents_location_node_fk": { + "name": "idx_agents_location_node_fk", + "columns": [ + { + "expression": "location_node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"agents\".\"location_node_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_agents_location_node_liveness_revision": { + "name": "idx_agents_location_node_liveness_revision", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "location_node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "node_liveness_revision", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"agents\".\"location_type\" = 'via_node' AND \"agents\".\"location_node_id\" IS NOT NULL AND \"agents\".\"status\" NOT IN ('offline', 'released')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_agents_origin_node_fk": { + "name": "idx_agents_origin_node_fk", + "columns": [ + { + "expression": "origin_node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"agents\".\"origin_node_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_agents_token": { + "name": "idx_agents_token", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_agents_previous_token": { + "name": "idx_agents_previous_token", + "columns": [ + { + "expression": "previous_token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_agents_active_last_seen": { + "name": "idx_agents_active_last_seen", + "columns": [ + { + "expression": "last_seen", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"agents\".\"status\" IN ('active', 'online')", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "agents_workspace_id_workspaces_id_fk": { + "name": "agents_workspace_id_workspaces_id_fk", + "tableFrom": "agents", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "agents_location_node_id_nodes_id_fk": { + "name": "agents_location_node_id_nodes_id_fk", + "tableFrom": "agents", + "tableTo": "nodes", + "columnsFrom": [ + "location_node_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "agents_origin_node_id_nodes_id_fk": { + "name": "agents_origin_node_id_nodes_id_fk", + "tableFrom": "agents", + "tableTo": "nodes", + "columnsFrom": [ + "origin_node_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "agents_token_hash_unique": { + "name": "agents_token_hash_unique", + "nullsNotDistinct": false, + "columns": [ + "token_hash" + ] + }, + "agents_workspace_id_unique": { + "name": "agents_workspace_id_unique", + "nullsNotDistinct": false, + "columns": [ + "workspace_id", + "id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.certifications": { + "name": "certifications", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "certifications_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_url": { + "name": "agent_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "level": { + "name": "level", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "passed": { + "name": "passed", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "passed_tests": { + "name": "passed_tests", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_tests": { + "name": "total_tests", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "monitor_enabled": { + "name": "monitor_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "monitor_interval_minutes": { + "name": "monitor_interval_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 60 + }, + "last_run_at": { + "name": "last_run_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "results": { + "name": "results", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'[]'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "certifications_rowid_unique": { + "name": "certifications_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_certifications_workspace": { + "name": "idx_certifications_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_certifications_agent_url": { + "name": "idx_certifications_agent_url", + "columns": [ + { + "expression": "agent_url", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_certifications_monitor_enabled": { + "name": "idx_certifications_monitor_enabled", + "columns": [ + { + "expression": "monitor_enabled", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "certifications_workspace_id_workspaces_id_fk": { + "name": "certifications_workspace_id_workspaces_id_fk", + "tableFrom": "certifications", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.channel_members": { + "name": "channel_members", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "channel_members_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "channel_id": { + "name": "channel_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_id": { + "name": "agent_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'member'" + }, + "joined_at": { + "name": "joined_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "last_read_id": { + "name": "last_read_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_muted": { + "name": "is_muted", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": { + "channel_members_rowid_unique": { + "name": "channel_members_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_channel_members_agent": { + "name": "idx_channel_members_agent", + "columns": [ + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "channel_members_channel_id_channels_id_fk": { + "name": "channel_members_channel_id_channels_id_fk", + "tableFrom": "channel_members", + "tableTo": "channels", + "columnsFrom": [ + "channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "channel_members_agent_id_agents_id_fk": { + "name": "channel_members_agent_id_agents_id_fk", + "tableFrom": "channel_members", + "tableTo": "agents", + "columnsFrom": [ + "agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "channel_members_channel_id_agent_id_pk": { + "name": "channel_members_channel_id_agent_id_pk", + "columns": [ + "channel_id", + "agent_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.channels": { + "name": "channels", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "channels_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel_type": { + "name": "channel_type", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "topic": { + "name": "topic", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "is_archived": { + "name": "is_archived", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": { + "channels_rowid_unique": { + "name": "channels_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "channels_workspace_name_unique": { + "name": "channels_workspace_name_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_channels_workspace": { + "name": "idx_channels_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_channels_creator": { + "name": "idx_channels_creator", + "columns": [ + { + "expression": "created_by", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "channels_workspace_id_workspaces_id_fk": { + "name": "channels_workspace_id_workspaces_id_fk", + "tableFrom": "channels", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "channels_created_by_agents_id_fk": { + "name": "channels_created_by_agents_id_fk", + "tableFrom": "channels", + "tableTo": "agents", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.credential_upgrades": { + "name": "credential_upgrades", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "credential_upgrades_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "legacy_hash": { + "name": "legacy_hash", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "principal_id": { + "name": "principal_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "ar_hash": { + "name": "ar_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sealed_credential": { + "name": "sealed_credential", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "expires_at": { + "name": "expires_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "credential_upgrades_rowid_unique": { + "name": "credential_upgrades_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_credential_upgrades_workspace": { + "name": "idx_credential_upgrades_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "credential_upgrades_workspace_id_workspaces_id_fk": { + "name": "credential_upgrades_workspace_id_workspaces_id_fk", + "tableFrom": "credential_upgrades", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.deliveries": { + "name": "deliveries", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "deliveries_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_id": { + "name": "agent_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mode": { + "name": "mode", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'immediate'" + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "priority": { + "name": "priority", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'normal'" + }, + "deadline": { + "name": "deadline", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "seq": { + "name": "seq", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "location_type": { + "name": "location_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'self_connected'" + }, + "location_node_id": { + "name": "location_node_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "route_node_id": { + "name": "route_node_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "route_node_kind": { + "name": "route_node_kind", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "route_node_role": { + "name": "route_node_role", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_adapter": { + "name": "delivery_adapter", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "dispatch_attempts": { + "name": "dispatch_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "next_attempt_at": { + "name": "next_attempt_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "last_dispatch_error": { + "name": "last_dispatch_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "delivered_at": { + "name": "delivered_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "accepted_at": { + "name": "accepted_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "acked_at": { + "name": "acked_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "replied_at": { + "name": "replied_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "reply_message_id": { + "name": "reply_message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "dead_lettered_at": { + "name": "dead_lettered_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "retryable": { + "name": "retryable", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "available_at": { + "name": "available_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "idempotency_key": { + "name": "idempotency_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "deliveries_rowid_unique": { + "name": "deliveries_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "deliveries_message_agent_unique": { + "name": "deliveries_message_agent_unique", + "columns": [ + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_location_node_fk": { + "name": "idx_deliveries_location_node_fk", + "columns": [ + { + "expression": "location_node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"deliveries\".\"location_node_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_route_node_fk": { + "name": "idx_deliveries_route_node_fk", + "columns": [ + { + "expression": "route_node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"deliveries\".\"route_node_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_active_location_node": { + "name": "idx_deliveries_active_location_node", + "columns": [ + { + "expression": "location_node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"deliveries\".\"status\" IN ('queued', 'delivered') AND \"deliveries\".\"location_node_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_id_lookup": { + "name": "idx_deliveries_id_lookup", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "deliveries_agent_seq_unique": { + "name": "deliveries_agent_seq_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "seq", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_agent": { + "name": "idx_deliveries_agent", + "columns": [ + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_agent_status_seq": { + "name": "idx_deliveries_agent_status_seq", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "seq", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_agent_active_seq": { + "name": "idx_deliveries_agent_active_seq", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "seq", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"deliveries\".\"status\" IN ('queued', 'delivered')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_agent_active_expiry": { + "name": "idx_deliveries_agent_active_expiry", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"deliveries\".\"status\" IN ('queued', 'delivered')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_settled_retention": { + "name": "idx_deliveries_settled_retention", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"deliveries\".\"status\" IN ('acked', 'failed', 'dead_lettered')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_agent_active_created": { + "name": "idx_deliveries_agent_active_created", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"deliveries\".\"status\" IN ('queued', 'delivered')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_expires": { + "name": "idx_deliveries_expires", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_active_expiry": { + "name": "idx_deliveries_active_expiry", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"deliveries\".\"status\" IN ('queued', 'delivered') AND \"deliveries\".\"expires_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_retry_due": { + "name": "idx_deliveries_retry_due", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "next_attempt_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"deliveries\".\"next_attempt_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_node_initial": { + "name": "idx_deliveries_node_initial", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"deliveries\".\"status\" = 'queued' AND \"deliveries\".\"route_node_kind\" IN ('http_push', 'ws', 'fleet_ws', 'direct_ws') AND \"deliveries\".\"next_attempt_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_node_initial_workspace": { + "name": "idx_deliveries_node_initial_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"deliveries\".\"status\" = 'queued' AND \"deliveries\".\"route_node_kind\" IN ('http_push', 'ws', 'fleet_ws', 'direct_ws') AND \"deliveries\".\"next_attempt_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_node_retry": { + "name": "idx_deliveries_node_retry", + "columns": [ + { + "expression": "next_attempt_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"deliveries\".\"status\" = 'queued' AND \"deliveries\".\"route_node_kind\" IN ('http_push', 'ws', 'fleet_ws', 'direct_ws') AND \"deliveries\".\"next_attempt_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_node_retry_workspace": { + "name": "idx_deliveries_node_retry_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "next_attempt_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"deliveries\".\"status\" = 'queued' AND \"deliveries\".\"route_node_kind\" IN ('http_push', 'ws', 'fleet_ws', 'direct_ws') AND \"deliveries\".\"next_attempt_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_status": { + "name": "idx_deliveries_status", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_deliveries_agent_status_created": { + "name": "idx_deliveries_agent_status_created", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "deliveries_workspace_id_workspaces_id_fk": { + "name": "deliveries_workspace_id_workspaces_id_fk", + "tableFrom": "deliveries", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "deliveries_message_id_messages_id_fk": { + "name": "deliveries_message_id_messages_id_fk", + "tableFrom": "deliveries", + "tableTo": "messages", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "deliveries_agent_id_agents_id_fk": { + "name": "deliveries_agent_id_agents_id_fk", + "tableFrom": "deliveries", + "tableTo": "agents", + "columnsFrom": [ + "agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "deliveries_location_node_id_nodes_id_fk": { + "name": "deliveries_location_node_id_nodes_id_fk", + "tableFrom": "deliveries", + "tableTo": "nodes", + "columnsFrom": [ + "location_node_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "deliveries_route_node_id_nodes_id_fk": { + "name": "deliveries_route_node_id_nodes_id_fk", + "tableFrom": "deliveries", + "tableTo": "nodes", + "columnsFrom": [ + "route_node_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.direct_dm_idempotency": { + "name": "direct_dm_idempotency", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "direct_dm_idempotency_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "fingerprint": { + "name": "fingerprint", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "response": { + "name": "response", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "direct_dm_idempotency_rowid_unique": { + "name": "direct_dm_idempotency_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_direct_dm_idempotency_workspace_created": { + "name": "idx_direct_dm_idempotency_workspace_created", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_direct_dm_idempotency_retention": { + "name": "idx_direct_dm_idempotency_retention", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "direct_dm_idempotency_workspace_id_workspaces_id_fk": { + "name": "direct_dm_idempotency_workspace_id_workspaces_id_fk", + "tableFrom": "direct_dm_idempotency", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.directory_agents": { + "name": "directory_agents", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "directory_agents_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_agent_id": { + "name": "source_agent_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "endpoint_url": { + "name": "endpoint_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "documentation_url": { + "name": "documentation_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tags": { + "name": "tags", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "capabilities": { + "name": "capabilities", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "rating_sum": { + "name": "rating_sum", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "rating_count": { + "name": "rating_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "directory_agents_rowid_unique": { + "name": "directory_agents_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "directory_agents_workspace_slug_unique": { + "name": "directory_agents_workspace_slug_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_directory_agents_workspace": { + "name": "idx_directory_agents_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_directory_agents_source_agent": { + "name": "idx_directory_agents_source_agent", + "columns": [ + { + "expression": "source_agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_directory_agents_status": { + "name": "idx_directory_agents_status", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "directory_agents_workspace_id_workspaces_id_fk": { + "name": "directory_agents_workspace_id_workspaces_id_fk", + "tableFrom": "directory_agents", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "directory_agents_source_agent_id_agents_id_fk": { + "name": "directory_agents_source_agent_id_agents_id_fk", + "tableFrom": "directory_agents", + "tableTo": "agents", + "columnsFrom": [ + "source_agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.directory_ratings": { + "name": "directory_ratings", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "directory_ratings_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "directory_agent_id": { + "name": "directory_agent_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "rater_agent_id": { + "name": "rater_agent_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "score": { + "name": "score", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "review": { + "name": "review", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "directory_ratings_rowid_unique": { + "name": "directory_ratings_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "directory_ratings_agent_rater_unique": { + "name": "directory_ratings_agent_rater_unique", + "columns": [ + { + "expression": "directory_agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "rater_agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_directory_ratings_workspace": { + "name": "idx_directory_ratings_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_directory_ratings_rater": { + "name": "idx_directory_ratings_rater", + "columns": [ + { + "expression": "rater_agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_directory_ratings_directory_agent": { + "name": "idx_directory_ratings_directory_agent", + "columns": [ + { + "expression": "directory_agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "directory_ratings_workspace_id_workspaces_id_fk": { + "name": "directory_ratings_workspace_id_workspaces_id_fk", + "tableFrom": "directory_ratings", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "directory_ratings_directory_agent_id_directory_agents_id_fk": { + "name": "directory_ratings_directory_agent_id_directory_agents_id_fk", + "tableFrom": "directory_ratings", + "tableTo": "directory_agents", + "columnsFrom": [ + "directory_agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "directory_ratings_rater_agent_id_agents_id_fk": { + "name": "directory_ratings_rater_agent_id_agents_id_fk", + "tableFrom": "directory_ratings", + "tableTo": "agents", + "columnsFrom": [ + "rater_agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.directory_skills": { + "name": "directory_skills", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "directory_skills_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "directory_agent_id": { + "name": "directory_agent_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "skill_id": { + "name": "skill_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tags": { + "name": "tags", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "directory_skills_rowid_unique": { + "name": "directory_skills_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_directory_skills_agent": { + "name": "idx_directory_skills_agent", + "columns": [ + { + "expression": "directory_agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "position", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_directory_skills_workspace": { + "name": "idx_directory_skills_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "directory_skills_workspace_id_workspaces_id_fk": { + "name": "directory_skills_workspace_id_workspaces_id_fk", + "tableFrom": "directory_skills", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "directory_skills_directory_agent_id_directory_agents_id_fk": { + "name": "directory_skills_directory_agent_id_directory_agents_id_fk", + "tableFrom": "directory_skills", + "tableTo": "directory_agents", + "columnsFrom": [ + "directory_agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dm_conversation_reservations": { + "name": "dm_conversation_reservations", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "dm_conversation_reservations_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "conversation_id": { + "name": "conversation_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "participant_one_id": { + "name": "participant_one_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "participant_two_id": { + "name": "participant_two_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "dm_conversation_reservations_rowid_unique": { + "name": "dm_conversation_reservations_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "dm_conversation_reservations_pair_unique": { + "name": "dm_conversation_reservations_pair_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "participant_one_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "participant_two_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "dm_conversation_reservations_workspace_id_workspaces_id_fk": { + "name": "dm_conversation_reservations_workspace_id_workspaces_id_fk", + "tableFrom": "dm_conversation_reservations", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "dm_conversation_reservations_sorted_pair_check": { + "name": "dm_conversation_reservations_sorted_pair_check", + "value": "\"dm_conversation_reservations\".\"participant_one_id\" <= \"dm_conversation_reservations\".\"participant_two_id\"" + } + }, + "isRLSEnabled": false + }, + "public.dm_conversations": { + "name": "dm_conversations", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "dm_conversations_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "dm_type": { + "name": "dm_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'1:1'" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "dm_conversations_rowid_unique": { + "name": "dm_conversations_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_dm_conversations_workspace": { + "name": "idx_dm_conversations_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_dm_conversations_channel": { + "name": "idx_dm_conversations_channel", + "columns": [ + { + "expression": "channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "dm_conversations_workspace_id_workspaces_id_fk": { + "name": "dm_conversations_workspace_id_workspaces_id_fk", + "tableFrom": "dm_conversations", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "dm_conversations_channel_id_channels_id_fk": { + "name": "dm_conversations_channel_id_channels_id_fk", + "tableFrom": "dm_conversations", + "tableTo": "channels", + "columnsFrom": [ + "channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dm_participants": { + "name": "dm_participants", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "dm_participants_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "conversation_id": { + "name": "conversation_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_id": { + "name": "agent_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "joined_at": { + "name": "joined_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "left_at": { + "name": "left_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "last_read_id": { + "name": "last_read_id", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "dm_participants_rowid_unique": { + "name": "dm_participants_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_dm_participants_agent": { + "name": "idx_dm_participants_agent", + "columns": [ + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "dm_participants_conversation_id_dm_conversations_id_fk": { + "name": "dm_participants_conversation_id_dm_conversations_id_fk", + "tableFrom": "dm_participants", + "tableTo": "dm_conversations", + "columnsFrom": [ + "conversation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "dm_participants_agent_id_agents_id_fk": { + "name": "dm_participants_agent_id_agents_id_fk", + "tableFrom": "dm_participants", + "tableTo": "agents", + "columnsFrom": [ + "agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "dm_participants_conversation_id_agent_id_pk": { + "name": "dm_participants_conversation_id_agent_id_pk", + "columns": [ + "conversation_id", + "agent_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.event_subscriptions": { + "name": "event_subscriptions", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "event_subscriptions_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "events": { + "name": "events", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "filter": { + "name": "filter", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "headers": { + "name": "headers", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "secret": { + "name": "secret", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "signature_scheme": { + "name": "signature_scheme", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'legacy'" + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "event_subscriptions_rowid_unique": { + "name": "event_subscriptions_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_event_subscriptions_workspace": { + "name": "idx_event_subscriptions_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "event_subscriptions_workspace_id_workspaces_id_fk": { + "name": "event_subscriptions_workspace_id_workspaces_id_fk", + "tableFrom": "event_subscriptions", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.file_cleanup_queue": { + "name": "file_cleanup_queue", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "file_cleanup_queue_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "storage_key": { + "name": "storage_key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "delete_after": { + "name": "delete_after", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "process_after": { + "name": "process_after", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "file_cleanup_queue_rowid_unique": { + "name": "file_cleanup_queue_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_file_cleanup_due": { + "name": "idx_file_cleanup_due", + "columns": [ + { + "expression": "process_after", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "storage_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.files": { + "name": "files", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "files_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "uploaded_by": { + "name": "uploaded_by", + "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 + }, + "storage_key": { + "name": "storage_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "upload_expires_at": { + "name": "upload_expires_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "files_rowid_unique": { + "name": "files_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_files_workspace": { + "name": "idx_files_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_files_uploader": { + "name": "idx_files_uploader", + "columns": [ + { + "expression": "uploaded_by", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "files_workspace_id_workspaces_id_fk": { + "name": "files_workspace_id_workspaces_id_fk", + "tableFrom": "files", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "files_uploaded_by_agents_id_fk": { + "name": "files_uploaded_by_agents_id_fk", + "tableFrom": "files", + "tableTo": "agents", + "columnsFrom": [ + "uploaded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.maintenance_cursors": { + "name": "maintenance_cursors", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "maintenance_cursors_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "cursor": { + "name": "cursor", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "maintenance_cursors_rowid_unique": { + "name": "maintenance_cursors_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.message_attachments": { + "name": "message_attachments", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "message_attachments_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_id": { + "name": "file_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": { + "message_attachments_rowid_unique": { + "name": "message_attachments_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_message_attachments_file": { + "name": "idx_message_attachments_file", + "columns": [ + { + "expression": "file_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "message_attachments_message_id_messages_id_fk": { + "name": "message_attachments_message_id_messages_id_fk", + "tableFrom": "message_attachments", + "tableTo": "messages", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "message_attachments_file_id_files_id_fk": { + "name": "message_attachments_file_id_files_id_fk", + "tableFrom": "message_attachments", + "tableTo": "files", + "columnsFrom": [ + "file_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "message_attachments_message_id_file_id_pk": { + "name": "message_attachments_message_id_file_id_pk", + "columns": [ + "message_id", + "file_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.message_logs": { + "name": "message_logs", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "message_logs_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_id": { + "name": "agent_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "conversation_id": { + "name": "conversation_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_kind": { + "name": "delivery_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content_type": { + "name": "content_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "attachment_count": { + "name": "attachment_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "mention_count": { + "name": "mention_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "latency_ms": { + "name": "latency_ms", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "message_logs_rowid_unique": { + "name": "message_logs_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "message_logs_message_unique": { + "name": "message_logs_message_unique", + "columns": [ + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_message_logs_workspace_time": { + "name": "idx_message_logs_workspace_time", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_message_logs_retention": { + "name": "idx_message_logs_retention", + "columns": [ + { + "expression": "length(\"id\")", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "\"id\" COLLATE \"C\"", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_message_logs_agent_time": { + "name": "idx_message_logs_agent_time", + "columns": [ + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_message_logs_channel_time": { + "name": "idx_message_logs_channel_time", + "columns": [ + { + "expression": "channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_message_logs_conversation_time": { + "name": "idx_message_logs_conversation_time", + "columns": [ + { + "expression": "conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "message_logs_workspace_id_workspaces_id_fk": { + "name": "message_logs_workspace_id_workspaces_id_fk", + "tableFrom": "message_logs", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "message_logs_message_id_messages_id_fk": { + "name": "message_logs_message_id_messages_id_fk", + "tableFrom": "message_logs", + "tableTo": "messages", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "message_logs_channel_id_channels_id_fk": { + "name": "message_logs_channel_id_channels_id_fk", + "tableFrom": "message_logs", + "tableTo": "channels", + "columnsFrom": [ + "channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "message_logs_agent_id_agents_id_fk": { + "name": "message_logs_agent_id_agents_id_fk", + "tableFrom": "message_logs", + "tableTo": "agents", + "columnsFrom": [ + "agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.message_sessions": { + "name": "message_sessions", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "message_sessions_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "session_ref": { + "name": "session_ref", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "first_message_at": { + "name": "first_message_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "last_message_at": { + "name": "last_message_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "start_is_known": { + "name": "start_is_known", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + } + }, + "indexes": { + "message_sessions_rowid_unique": { + "name": "message_sessions_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_message_sessions_workspace_last": { + "name": "idx_message_sessions_workspace_last", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_message_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "message_sessions_workspace_id_workspaces_id_fk": { + "name": "message_sessions_workspace_id_workspaces_id_fk", + "tableFrom": "message_sessions", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "message_sessions_workspace_id_session_ref_pk": { + "name": "message_sessions_workspace_id_session_ref_pk", + "columns": [ + "workspace_id", + "session_ref" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.messages": { + "name": "messages", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "messages_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_id": { + "name": "agent_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "thread_id": { + "name": "thread_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reply_to_message_id": { + "name": "reply_to_message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "blocks": { + "name": "blocks", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "session_ref": { + "name": "session_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "has_attachments": { + "name": "has_attachments", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "messages_rowid_unique": { + "name": "messages_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_messages_retention": { + "name": "idx_messages_retention", + "columns": [ + { + "expression": "length(\"id\")", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "\"id\" COLLATE \"C\"", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_messages_channel_length_id": { + "name": "idx_messages_channel_length_id", + "columns": [ + { + "expression": "channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "length(\"id\")", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "\"id\" COLLATE \"C\"", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_messages_thread": { + "name": "idx_messages_thread", + "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": {} + }, + "idx_messages_workspace": { + "name": "idx_messages_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_messages_workspace_length_id": { + "name": "idx_messages_workspace_length_id", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "length(\"id\")", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "\"id\" COLLATE \"C\"", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_messages_agent": { + "name": "idx_messages_agent", + "columns": [ + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_messages_workspace_session": { + "name": "idx_messages_workspace_session", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "session_ref", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "length(\"id\")", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "\"id\" COLLATE \"C\"", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "messages_workspace_id_workspaces_id_fk": { + "name": "messages_workspace_id_workspaces_id_fk", + "tableFrom": "messages", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "messages_channel_id_channels_id_fk": { + "name": "messages_channel_id_channels_id_fk", + "tableFrom": "messages", + "tableTo": "channels", + "columnsFrom": [ + "channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "messages_agent_id_agents_id_fk": { + "name": "messages_agent_id_agents_id_fk", + "tableFrom": "messages", + "tableTo": "agents", + "columnsFrom": [ + "agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "messages_thread_id_messages_id_fk": { + "name": "messages_thread_id_messages_id_fk", + "tableFrom": "messages", + "tableTo": "messages", + "columnsFrom": [ + "thread_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.node_providers": { + "name": "node_providers", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "node_providers_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "node_id": { + "name": "node_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "instance_id": { + "name": "instance_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "capabilities": { + "name": "capabilities", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "max_agents": { + "name": "max_agents", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "active_agents": { + "name": "active_agents", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "load": { + "name": "load", + "type": "double precision", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "load_reported": { + "name": "load_reported", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "handlers_live": { + "name": "handlers_live", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'offline'" + }, + "version": { + "name": "version", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'unknown'" + }, + "last_heartbeat_at": { + "name": "last_heartbeat_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "liveness_revision": { + "name": "liveness_revision", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "node_providers_rowid_unique": { + "name": "node_providers_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "node_providers_node_name_unique": { + "name": "node_providers_node_name_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_node_providers_node": { + "name": "idx_node_providers_node", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_node_providers_liveness_revision": { + "name": "idx_node_providers_liveness_revision", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "liveness_revision", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_node_providers_node_fk": { + "name": "idx_node_providers_node_fk", + "columns": [ + { + "expression": "node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "node_providers_workspace_id_workspaces_id_fk": { + "name": "node_providers_workspace_id_workspaces_id_fk", + "tableFrom": "node_providers", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "node_providers_node_id_nodes_id_fk": { + "name": "node_providers_node_id_nodes_id_fk", + "tableFrom": "node_providers", + "tableTo": "nodes", + "columnsFrom": [ + "node_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.nodes": { + "name": "nodes", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "nodes_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "previous_token_hash": { + "name": "previous_token_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "previous_token_expires_at": { + "name": "previous_token_expires_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "rotation_idempotency_key_hash": { + "name": "rotation_idempotency_key_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rotation_request_digest": { + "name": "rotation_request_digest", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "machine_id": { + "name": "machine_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'fleet_ws'" + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'broker'" + }, + "delivery_adapter": { + "name": "delivery_adapter", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'fleet.ws.v1'" + }, + "delivery_config": { + "name": "delivery_config", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "capabilities": { + "name": "capabilities", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "max_agents": { + "name": "max_agents", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "active_agents": { + "name": "active_agents", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "reserved_agents": { + "name": "reserved_agents", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "tags": { + "name": "tags", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "version": { + "name": "version", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'unknown'" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'offline'" + }, + "handlers_live": { + "name": "handlers_live", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "load": { + "name": "load", + "type": "double precision", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "load_reported": { + "name": "load_reported", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "last_heartbeat_at": { + "name": "last_heartbeat_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "proven_live_at": { + "name": "proven_live_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "liveness_revision": { + "name": "liveness_revision", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "nodes_rowid_unique": { + "name": "nodes_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "nodes_workspace_name_unique": { + "name": "nodes_workspace_name_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_nodes_workspace": { + "name": "idx_nodes_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_nodes_token": { + "name": "idx_nodes_token", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_nodes_status": { + "name": "idx_nodes_status", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_nodes_status_heartbeat": { + "name": "idx_nodes_status_heartbeat", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_heartbeat_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_nodes_workspace_machine": { + "name": "idx_nodes_workspace_machine", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "machine_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_nodes_workspace_machine_proven": { + "name": "idx_nodes_workspace_machine_proven", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "machine_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "proven_live_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_nodes_workspace_previous_token": { + "name": "idx_nodes_workspace_previous_token", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "previous_token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_nodes_online_liveness": { + "name": "idx_nodes_online_liveness", + "columns": [ + { + "expression": "last_heartbeat_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"nodes\".\"status\" = 'online'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_nodes_context_reachable": { + "name": "idx_nodes_context_reachable", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"nodes\".\"kind\" = 'http_push' OR (\"nodes\".\"kind\" IN ('ws', 'fleet_ws', 'direct_ws') AND \"nodes\".\"status\" <> 'offline')", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "nodes_workspace_id_workspaces_id_fk": { + "name": "nodes_workspace_id_workspaces_id_fk", + "tableFrom": "nodes", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "nodes_token_hash_unique": { + "name": "nodes_token_hash_unique", + "nullsNotDistinct": false, + "columns": [ + "token_hash" + ] + }, + "nodes_workspace_id_unique": { + "name": "nodes_workspace_id_unique", + "nullsNotDistinct": false, + "columns": [ + "workspace_id", + "id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.observer_tokens": { + "name": "observer_tokens", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "observer_tokens_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scopes": { + "name": "scopes", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "filters": { + "name": "filters", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "expires_at": { + "name": "expires_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by_type": { + "name": "created_by_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'workspace'" + }, + "last_used_at": { + "name": "last_used_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "revoked_at": { + "name": "revoked_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "observer_tokens_rowid_unique": { + "name": "observer_tokens_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "observer_tokens_workspace_name_unique": { + "name": "observer_tokens_workspace_name_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "observer_tokens_token_hash_unique": { + "name": "observer_tokens_token_hash_unique", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_observer_tokens_workspace_status": { + "name": "idx_observer_tokens_workspace_status", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_observer_tokens_expires_at": { + "name": "idx_observer_tokens_expires_at", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "observer_tokens_workspace_id_workspaces_id_fk": { + "name": "observer_tokens_workspace_id_workspaces_id_fk", + "tableFrom": "observer_tokens", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pending_events": { + "name": "pending_events", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "pending_events_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "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 + }, + "max_attempts": { + "name": "max_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 5 + }, + "webhook_initialized": { + "name": "webhook_initialized", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "process_after": { + "name": "process_after", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "completed_at": { + "name": "completed_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "pending_events_rowid_unique": { + "name": "pending_events_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_pending_events_status": { + "name": "idx_pending_events_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "process_after", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_pending_events_settled_retention": { + "name": "idx_pending_events_settled_retention", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "completed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_pending_events_workspace": { + "name": "idx_pending_events_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pending_events_workspace_id_workspaces_id_fk": { + "name": "pending_events_workspace_id_workspaces_id_fk", + "tableFrom": "pending_events", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.reactions": { + "name": "reactions", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "reactions_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_id": { + "name": "agent_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "emoji": { + "name": "emoji", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "reactions_rowid_unique": { + "name": "reactions_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "reactions_message_agent_emoji_unique": { + "name": "reactions_message_agent_emoji_unique", + "columns": [ + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "emoji", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_reactions_message": { + "name": "idx_reactions_message", + "columns": [ + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_reactions_agent": { + "name": "idx_reactions_agent", + "columns": [ + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "reactions_message_id_messages_id_fk": { + "name": "reactions_message_id_messages_id_fk", + "tableFrom": "reactions", + "tableTo": "messages", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reactions_agent_id_agents_id_fk": { + "name": "reactions_agent_id_agents_id_fk", + "tableFrom": "reactions", + "tableTo": "agents", + "columnsFrom": [ + "agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.read_receipts": { + "name": "read_receipts", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "read_receipts_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_id": { + "name": "agent_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "read_at": { + "name": "read_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "read_receipts_rowid_unique": { + "name": "read_receipts_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_read_receipts_retention": { + "name": "idx_read_receipts_retention", + "columns": [ + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_read_receipts_agent": { + "name": "idx_read_receipts_agent", + "columns": [ + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "read_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "read_receipts_message_id_messages_id_fk": { + "name": "read_receipts_message_id_messages_id_fk", + "tableFrom": "read_receipts", + "tableTo": "messages", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "read_receipts_agent_id_agents_id_fk": { + "name": "read_receipts_agent_id_agents_id_fk", + "tableFrom": "read_receipts", + "tableTo": "agents", + "columnsFrom": [ + "agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "read_receipts_message_id_agent_id_pk": { + "name": "read_receipts_message_id_agent_id_pk", + "columns": [ + "message_id", + "agent_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.routing_configs": { + "name": "routing_configs", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "routing_configs_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "weights": { + "name": "weights", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "circuit_breaker_threshold": { + "name": "circuit_breaker_threshold", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 3 + }, + "circuit_breaker_cooldown_seconds": { + "name": "circuit_breaker_cooldown_seconds", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 300 + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "routing_configs_rowid_unique": { + "name": "routing_configs_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_routing_configs_updated_at": { + "name": "idx_routing_configs_updated_at", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "routing_configs_workspace_id_workspaces_id_fk": { + "name": "routing_configs_workspace_id_workspaces_id_fk", + "tableFrom": "routing_configs", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.routing_failures": { + "name": "routing_failures", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "routing_failures_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_id": { + "name": "agent_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "consecutive_failures": { + "name": "consecutive_failures", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_failures": { + "name": "total_failures", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_successes": { + "name": "total_successes", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_failure_at": { + "name": "last_failure_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "last_success_at": { + "name": "last_success_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "circuit_open_until": { + "name": "circuit_open_until", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "routing_failures_rowid_unique": { + "name": "routing_failures_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_routing_failures_workspace": { + "name": "idx_routing_failures_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_routing_failures_agent": { + "name": "idx_routing_failures_agent", + "columns": [ + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_routing_failures_circuit": { + "name": "idx_routing_failures_circuit", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "circuit_open_until", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "routing_failures_workspace_id_workspaces_id_fk": { + "name": "routing_failures_workspace_id_workspaces_id_fk", + "tableFrom": "routing_failures", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "routing_failures_agent_id_agents_id_fk": { + "name": "routing_failures_agent_id_agents_id_fk", + "tableFrom": "routing_failures", + "tableTo": "agents", + "columnsFrom": [ + "agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "routing_failures_workspace_id_agent_id_pk": { + "name": "routing_failures_workspace_id_agent_id_pk", + "columns": [ + "workspace_id", + "agent_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.session_events": { + "name": "session_events", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "session_events_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_id": { + "name": "agent_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "idempotency_key_hash": { + "name": "idempotency_key_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "request_digest": { + "name": "request_digest", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sequence": { + "name": "sequence", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "status_applied_at": { + "name": "status_applied_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "status_legacy_pending": { + "name": "status_legacy_pending", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": { + "session_events_rowid_unique": { + "name": "session_events_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "session_events_agent_sequence_unique": { + "name": "session_events_agent_sequence_unique", + "columns": [ + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sequence", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "session_events_agent_idempotency_unique": { + "name": "session_events_agent_idempotency_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "idempotency_key_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_session_events_agent": { + "name": "idx_session_events_agent", + "columns": [ + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_session_events_workspace": { + "name": "idx_session_events_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_session_events_type": { + "name": "idx_session_events_type", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "session_events_workspace_id_workspaces_id_fk": { + "name": "session_events_workspace_id_workspaces_id_fk", + "tableFrom": "session_events", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "session_events_agent_id_agents_id_fk": { + "name": "session_events_agent_id_agents_id_fk", + "tableFrom": "session_events", + "tableTo": "agents", + "columnsFrom": [ + "agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.triggers": { + "name": "triggers", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "triggers_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pattern": { + "name": "pattern", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mention": { + "name": "mention", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "action_name": { + "name": "action_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "last_triggered_at": { + "name": "last_triggered_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "triggers_rowid_unique": { + "name": "triggers_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_triggers_workspace": { + "name": "idx_triggers_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_triggers_enabled": { + "name": "idx_triggers_enabled", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "enabled", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_triggers_action": { + "name": "idx_triggers_action", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "action_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "triggers_workspace_id_workspaces_id_fk": { + "name": "triggers_workspace_id_workspaces_id_fk", + "tableFrom": "triggers", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.usage_records": { + "name": "usage_records", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "usage_records_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "period_start": { + "name": "period_start", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "period_end": { + "name": "period_end", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "messages_sent": { + "name": "messages_sent", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "api_calls": { + "name": "api_calls", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "files_uploaded": { + "name": "files_uploaded", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "file_bytes": { + "name": "file_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "ws_minutes": { + "name": "ws_minutes", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "usage_records_rowid_unique": { + "name": "usage_records_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_usage_workspace_period": { + "name": "idx_usage_workspace_period", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "period_start", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "usage_records_workspace_id_workspaces_id_fk": { + "name": "usage_records_workspace_id_workspaces_id_fk", + "tableFrom": "usage_records", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.webhook_deliveries": { + "name": "webhook_deliveries", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "webhook_deliveries_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "event_id": { + "name": "event_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subscription_id": { + "name": "subscription_id", + "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": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_status": { + "name": "last_status", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "completed_at": { + "name": "completed_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "webhook_deliveries_rowid_unique": { + "name": "webhook_deliveries_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "webhook_deliveries_event_subscription_unique": { + "name": "webhook_deliveries_event_subscription_unique", + "columns": [ + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "subscription_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_webhook_deliveries_due": { + "name": "idx_webhook_deliveries_due", + "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": {} + }, + "idx_webhook_deliveries_subscription": { + "name": "idx_webhook_deliveries_subscription", + "columns": [ + { + "expression": "subscription_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "webhook_deliveries_event_id_pending_events_id_fk": { + "name": "webhook_deliveries_event_id_pending_events_id_fk", + "tableFrom": "webhook_deliveries", + "tableTo": "pending_events", + "columnsFrom": [ + "event_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "webhook_deliveries_subscription_id_event_subscriptions_id_fk": { + "name": "webhook_deliveries_subscription_id_event_subscriptions_id_fk", + "tableFrom": "webhook_deliveries", + "tableTo": "event_subscriptions", + "columnsFrom": [ + "subscription_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.webhooks": { + "name": "webhooks", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "webhooks_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "webhooks_rowid_unique": { + "name": "webhooks_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "webhooks_workspace_name_unique": { + "name": "webhooks_workspace_name_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_webhooks_workspace": { + "name": "idx_webhooks_workspace", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_webhooks_creator": { + "name": "idx_webhooks_creator", + "columns": [ + { + "expression": "created_by", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_webhooks_token": { + "name": "idx_webhooks_token", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "webhooks_workspace_id_workspaces_id_fk": { + "name": "webhooks_workspace_id_workspaces_id_fk", + "tableFrom": "webhooks", + "tableTo": "workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "webhooks_channel_id_channels_id_fk": { + "name": "webhooks_channel_id_channels_id_fk", + "tableFrom": "webhooks", + "tableTo": "channels", + "columnsFrom": [ + "channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "webhooks_created_by_agents_id_fk": { + "name": "webhooks_created_by_agents_id_fk", + "tableFrom": "webhooks", + "tableTo": "agents", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_create_idempotency": { + "name": "workspace_create_idempotency", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "workspace_create_idempotency_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "owner_scope_hash": { + "name": "owner_scope_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "idempotency_key_hash": { + "name": "idempotency_key_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "request_digest": { + "name": "request_digest", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "terminalized_at": { + "name": "terminalized_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "workspace_create_idempotency_rowid_unique": { + "name": "workspace_create_idempotency_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_create_idempotency_workspace_unique": { + "name": "workspace_create_idempotency_workspace_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "workspace_create_idempotency_owner_scope_hash_idempotency_key_hash_pk": { + "name": "workspace_create_idempotency_owner_scope_hash_idempotency_key_hash_pk", + "columns": [ + "owner_scope_hash", + "idempotency_key_hash" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_events": { + "name": "workspace_events", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "workspace_events_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "seq": { + "name": "seq", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "payload": { + "name": "payload", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + } + }, + "indexes": { + "workspace_events_rowid_unique": { + "name": "workspace_events_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_workspace_events_created": { + "name": "idx_workspace_events_created", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_workspace_events_retention": { + "name": "idx_workspace_events_retention", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "seq", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "workspace_events_workspace_id_seq_pk": { + "name": "workspace_events_workspace_id_seq_pk", + "columns": [ + "workspace_id", + "seq" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "workspace_events_seq_positive_check": { + "name": "workspace_events_seq_positive_check", + "value": "\"workspace_events\".\"seq\" > 0" + } + }, + "isRLSEnabled": false + }, + "public.workspaces": { + "name": "workspaces", + "schema": "", + "columns": { + "rowid": { + "name": "rowid", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "workspaces_rowid_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "api_key_hash": { + "name": "api_key_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "previous_api_key_hash": { + "name": "previous_api_key_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "previous_api_key_expires_at": { + "name": "previous_api_key_expires_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "api_key_generation": { + "name": "api_key_generation", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "system_prompt": { + "name": "system_prompt", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "floor(extract(epoch from statement_timestamp()))::bigint" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "retention": { + "name": "retention", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "leaders": { + "name": "leaders", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "provenance": { + "name": "provenance", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "usage_classification": { + "name": "usage_classification", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'unknown'" + }, + "classification_source": { + "name": "classification_source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'unclassified'" + }, + "classification_reason": { + "name": "classification_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "classified_at": { + "name": "classified_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "workspaces_rowid_unique": { + "name": "workspaces_rowid_unique", + "columns": [ + { + "expression": "rowid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_workspaces_expires_at": { + "name": "idx_workspaces_expires_at", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_workspaces_previous_api_key": { + "name": "idx_workspaces_previous_api_key", + "columns": [ + { + "expression": "previous_api_key_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_workspaces_usage_classification": { + "name": "idx_workspaces_usage_classification", + "columns": [ + { + "expression": "usage_classification", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "workspaces_api_key_hash_unique": { + "name": "workspaces_api_key_hash_unique", + "nullsNotDistinct": false, + "columns": [ + "api_key_hash" + ] + } + }, + "policies": {}, + "checkConstraints": { + "workspaces_usage_classification_source_check": { + "name": "workspaces_usage_classification_source_check", + "value": "(\n (\"workspaces\".\"usage_classification\" = 'unknown' AND \"workspaces\".\"classification_source\" = 'unclassified')\n OR (\n \"workspaces\".\"usage_classification\" IN ('internal', 'external')\n AND \"workspaces\".\"classification_source\" IN ('creator', 'operator')\n )\n )" + } + }, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/packages/engine/src/db/migrations-pg/meta/_journal.json b/packages/engine/src/db/migrations-pg/meta/_journal.json index bfd7b06e1..46bac7dca 100644 --- a/packages/engine/src/db/migrations-pg/meta/_journal.json +++ b/packages/engine/src/db/migrations-pg/meta/_journal.json @@ -57,6 +57,13 @@ "when": 1794904190079, "tag": "0007_workspace_leaders", "breakpoints": true + }, + { + "idx": 8, + "version": "7", + "when": 1795244596035, + "tag": "0008_messages_channel_length_id", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/engine/src/db/migrations/0087_messages_channel_length_id_index.sql b/packages/engine/src/db/migrations/0087_messages_channel_length_id_index.sql new file mode 100644 index 000000000..52b39eca0 --- /dev/null +++ b/packages/engine/src/db/migrations/0087_messages_channel_length_id_index.sql @@ -0,0 +1,10 @@ +-- Channel and DM history pages newest-first by numeric snowflake order, +-- (length(id), id): ids are decimal TEXT that widened from 17 to 18 digits in +-- 2025-10, so plain `id` text order misorders history spanning that change. +-- This index keeps each page an index seek. It replaces +-- idx_messages_channel_time (channel_id, id): every channel_id lookup that +-- index served is a prefix of this one, and no query orders a channel by bare +-- text id any more. No data changes. +CREATE INDEX IF NOT EXISTS idx_messages_channel_length_id + ON messages(channel_id, length(id), id); +DROP INDEX IF EXISTS idx_messages_channel_time; diff --git a/packages/engine/src/db/schema.pg.ts b/packages/engine/src/db/schema.pg.ts index 70f0889f7..5698b45da 100644 --- a/packages/engine/src/db/schema.pg.ts +++ b/packages/engine/src/db/schema.pg.ts @@ -883,11 +883,11 @@ export const messages = pgTable( }, (table) => [ uniqueIndex('messages_rowid_unique').on(table.rowid), - index('idx_messages_channel_time').on(table.channelId, table.id), // (length(id), id) orderings: `id` is indexed COLLATE "C" so the index // order is SQLite's binary text order. Queries must order/compare with // the same expression - `length(id), id COLLATE "C"` - to use it. index('idx_messages_retention').on(sql`length(${table.id})`, idCollateC(table.id)), + index('idx_messages_channel_length_id').on(table.channelId, sql`length(${table.id})`, idCollateC(table.id)), index('idx_messages_thread').on(table.threadId, table.id), index('idx_messages_workspace').on(table.workspaceId, table.id), index('idx_messages_workspace_length_id').on( diff --git a/packages/engine/src/db/schema.ts b/packages/engine/src/db/schema.ts index b090ce128..da672dda1 100644 --- a/packages/engine/src/db/schema.ts +++ b/packages/engine/src/db/schema.ts @@ -745,7 +745,8 @@ export const messages = sqliteTable( // FTS5 search handled via separate virtual table + triggers }, (table) => [ - index('idx_messages_channel_time').on(table.channelId, table.id), + // Channel/DM history pages by numeric snowflake order (length(id), id). + index('idx_messages_channel_length_id').on(table.channelId, sql`length(${table.id})`, table.id), index('idx_messages_retention').on(sql`length(${table.id})`, table.id), index('idx_messages_thread').on(table.threadId, table.id), index('idx_messages_workspace').on(table.workspaceId, table.id), diff --git a/packages/engine/src/db/sqlx.ts b/packages/engine/src/db/sqlx.ts index 70f8281c3..b532527e4 100644 --- a/packages/engine/src/db/sqlx.ts +++ b/packages/engine/src/db/sqlx.ts @@ -556,6 +556,18 @@ export function indexedBy(source: DialectSource, index: string): SQL { }); } +/** + * `expr` compared as binary text: bare on SQLite (TEXT already compares + * bytewise), `expr COLLATE "C"` on PostgreSQL so comparisons and orderings + * match the `COLLATE "C"` index expressions in schema.pg.ts. + */ +export function binaryText(source: DialectSource, expr: Fragment): SQL { + return pick(source, { + sqlite: () => sql`${expr}`, + pg: () => sql`${expr} COLLATE "C"`, + }); +} + /** `NOT INDEXED` planner hint; empty on PostgreSQL. */ export function notIndexed(source: DialectSource): SQL { return pick(source, { diff --git a/packages/engine/src/engine/dm.ts b/packages/engine/src/engine/dm.ts index feebec726..817227854 100644 --- a/packages/engine/src/engine/dm.ts +++ b/packages/engine/src/engine/dm.ts @@ -1,6 +1,6 @@ import * as sqlx from '../db/sqlx.js'; import { z } from 'zod'; -import { eq, and, sql, lt, lte, gt, isNull, inArray, desc } from 'drizzle-orm'; +import { eq, and, sql, lte, isNull, inArray, desc } from 'drizzle-orm'; import type { DmMessage } from '@relaycast/types'; import type { getDb } from '../db/index.js'; import { @@ -55,6 +55,7 @@ import { import { buildMessageSessionWrite, requireSessionRefFromMetadata } from './sessionMessages.js'; import { fetchAttachmentsBatch, resolveSendAttachments, type AttachmentRow } from './attachments.js'; import { canonicalJson, canonicalUserMessageMetadata, publicMessageMetadata, sanitizeUserMessageMetadata } from './messageMetadata.js'; +import { newestSnowflakePage } from './snowflakePage.js'; import { queryInChunks } from '../lib/queryChunks.js'; type Db = ReturnType; @@ -1129,33 +1130,24 @@ export async function getDmMessages( throw codedError('Conversation not found', 'not_found', 404); } - const conditions = [eq(messages.channelId, conv.channelId)]; - - // Compare/sort on the indexed text PK directly: snowflake ids are fixed-width - // (19 digits) so lexical order matches numeric order, and this keeps the PK - // index usable for range scans (a CAST would force a full scan). - if (opts.before) { - conditions.push(lt(messages.id, opts.before)); - } - if (opts.after) { - conditions.push(gt(messages.id, opts.after)); - } - - const rows = await db - .select({ - id: messages.id, - agentId: messages.agentId, - agentName: agents.name, - body: messages.body, - metadata: messages.metadata, - replyToMessageId: messages.replyToMessageId, - createdAt: messages.createdAt, - }) - .from(messages) - .innerJoin(agents, eq(messages.agentId, agents.id)) - .where(and(...conditions)) - .orderBy(sql`${messages.id} DESC`) - .limit(limit); + // Snowflake ids are variable-width decimal TEXT: page numerically over + // idx_messages_channel_length_id (channel_id, length(id), id). + const rows = await newestSnowflakePage(db, messages.id, { ...opts, limit }, (cursor, orderBy, pageLimit) => + db + .select({ + id: messages.id, + agentId: messages.agentId, + agentName: agents.name, + body: messages.body, + metadata: messages.metadata, + replyToMessageId: messages.replyToMessageId, + createdAt: messages.createdAt, + }) + .from(messages) + .innerJoin(agents, eq(messages.agentId, agents.id)) + .where(and(eq(messages.channelId, conv.channelId), cursor)) + .orderBy(orderBy) + .limit(pageLimit)); const attachmentMap = await fetchAttachmentsBatch(db, workspaceId, rows.map((r) => r.id)); diff --git a/packages/engine/src/engine/dmAll.ts b/packages/engine/src/engine/dmAll.ts index 97b414e11..7c9fcafc0 100644 --- a/packages/engine/src/engine/dmAll.ts +++ b/packages/engine/src/engine/dmAll.ts @@ -1,4 +1,4 @@ -import { eq, and, sql, lt, gt, gte, inArray } from 'drizzle-orm'; +import { eq, and, sql, gt, gte, inArray } from 'drizzle-orm'; import type { DmMessage, WorkspaceDmConversation } from '@relaycast/types'; import type { getDb } from '../db/index.js'; import { @@ -10,6 +10,7 @@ import { import { codedError } from '../lib/httpError.js'; import { D1_SAFE_IN_QUERY_CHUNK_SIZE, queryInChunks } from '../lib/queryChunks.js'; import { publicMessageMetadata } from './messageMetadata.js'; +import { newestSnowflakePage } from './snowflakePage.js'; type Db = ReturnType; @@ -214,27 +215,23 @@ export async function getDmMessagesForWorkspace( throw codedError('Conversation not found', 'not_found', 404); } - // Compare/sort on the indexed text PK directly: snowflake ids are fixed-width - // (19 digits) so lexical order matches numeric order, keeping the PK index - // usable for range scans (a CAST would force a full scan). - const conditions = [eq(messages.channelId, conv.channelId)]; - if (opts.before) conditions.push(lt(messages.id, opts.before)); - if (opts.after) conditions.push(gt(messages.id, opts.after)); - - const rows = await db - .select({ - id: messages.id, - agentId: messages.agentId, - agentName: agents.name, - body: messages.body, - metadata: messages.metadata, - createdAt: messages.createdAt, - }) - .from(messages) - .innerJoin(agents, eq(messages.agentId, agents.id)) - .where(and(...conditions)) - .orderBy(sql`${messages.id} DESC`) - .limit(limit); + // Snowflake ids are variable-width decimal TEXT: page numerically over + // idx_messages_channel_length_id (channel_id, length(id), id). + const rows = await newestSnowflakePage(db, messages.id, { ...opts, limit }, (cursor, orderBy, pageLimit) => + db + .select({ + id: messages.id, + agentId: messages.agentId, + agentName: agents.name, + body: messages.body, + metadata: messages.metadata, + createdAt: messages.createdAt, + }) + .from(messages) + .innerJoin(agents, eq(messages.agentId, agents.id)) + .where(and(eq(messages.channelId, conv.channelId), cursor)) + .orderBy(orderBy) + .limit(pageLimit)); return rows.map((r) => ({ id: r.id, diff --git a/packages/engine/src/engine/message.ts b/packages/engine/src/engine/message.ts index fa4204ea4..dd2822efe 100644 --- a/packages/engine/src/engine/message.ts +++ b/packages/engine/src/engine/message.ts @@ -1,10 +1,12 @@ import { prepareAuthorityFanout } from './deliveryWrites.js'; import { parseMessageMentions } from './mentions.js'; -import { eq, and, sql, isNull, lt, gt, inArray } from 'drizzle-orm'; +import { eq, and, sql, isNull, inArray } from 'drizzle-orm'; import type { getDb } from '../db/index.js'; import { messages, agents, reactions, readReceipts, messageAttachments } from '../db/tables.js'; import { runAtomicWrites, type AtomicWrite } from '../ports/database.js'; +import * as sqlx from '../db/sqlx.js'; import { generateId } from './snowflake.js'; +import { newestSnowflakePage } from './snowflakePage.js'; import { buildMessageLogWrite } from './console.js'; import { buildChannelDeliveryWrite, @@ -177,34 +179,31 @@ export async function getMessages( isNull(messages.threadId), ]; - if (opts.before) { - conditions.push(lt(messages.id, opts.before)); - } - if (opts.after) { - conditions.push(gt(messages.id, opts.after)); - } - - const rows = await db - .select({ - id: messages.id, - workspaceId: messages.workspaceId, - channelId: messages.channelId, - agentId: messages.agentId, - agentName: agents.name, - threadId: messages.threadId, - replyToMessageId: messages.replyToMessageId, - body: messages.body, - blocks: messages.blocks, - metadata: messages.metadata, - hasAttachments: messages.hasAttachments, - createdAt: messages.createdAt, - updatedAt: messages.updatedAt, - }) - .from(messages) - .leftJoin(agents, eq(messages.agentId, agents.id)) - .where(and(...conditions)) - .orderBy(sql`${messages.id} DESC`) - .limit(limit); + // Snowflake ids are variable-width decimal TEXT: page numerically. Pin the + // channel index so SQLite cannot pick the workspace index and sort the whole + // workspace history. + const rows = await newestSnowflakePage(db, messages.id, { ...opts, limit }, (cursor, orderBy, pageLimit) => + db + .select({ + id: sql`${messages.id}`.mapWith(messages.id), + workspaceId: sql`${messages.workspaceId}`.mapWith(messages.workspaceId), + channelId: sql`${messages.channelId}`.mapWith(messages.channelId), + agentId: sql`${messages.agentId}`.mapWith(messages.agentId), + agentName: agents.name, + threadId: sql`${messages.threadId}`.mapWith(messages.threadId), + replyToMessageId: sql`${messages.replyToMessageId}`.mapWith(messages.replyToMessageId), + body: sql`${messages.body}`.mapWith(messages.body), + blocks: sql`${messages.blocks}`.mapWith(messages.blocks), + metadata: sql`${messages.metadata}`.mapWith(messages.metadata), + hasAttachments: sql`${messages.hasAttachments}`.mapWith(messages.hasAttachments), + createdAt: sql`${messages.createdAt}`.mapWith(messages.createdAt), + updatedAt: sql`${messages.updatedAt}`.mapWith(messages.updatedAt), + }) + .from(sql`${messages} ${sqlx.indexedBy(db, 'idx_messages_channel_length_id')}`) + .leftJoin(agents, eq(messages.agentId, agents.id)) + .where(and(...conditions, cursor)) + .orderBy(orderBy) + .limit(pageLimit)); if (rows.length === 0) return []; diff --git a/packages/engine/src/engine/retention.ts b/packages/engine/src/engine/retention.ts index cf24f830c..b4d35d816 100644 --- a/packages/engine/src/engine/retention.ts +++ b/packages/engine/src/engine/retention.ts @@ -2,6 +2,7 @@ import { eq, sql, type Column, type SQL } from 'drizzle-orm'; import { pruneBounded } from './boundedRetention.js'; import type { EffectiveMessageRetention } from '@relaycast/types'; import type { getDb } from '../db/index.js'; +import * as sqlx from '../db/sqlx.js'; import { workspaces } from '../db/tables.js'; import { snowflakeIdLowerBound } from './snowflake.js'; import { pruneRowidPages, type RetentionCursorStore } from './rowidRetention.js'; @@ -142,9 +143,30 @@ export function atOrAfterSnowflake(column: Column, cutoffMs: number): SQL { return sql`(length(${column}), ${column}) >= (${bound.length}, ${bound})`; } +/** + * Snowflake ids are decimal TEXT whose width grows over time (17 digits until + * 2025-10, 18 after), so plain text order is not numeric order. The helpers + * below compare and order by `(length(id), id)`. Pass the handle (`source`) + * so PostgreSQL compares `id COLLATE "C"` and can use the matching + * `(…, length(id), id COLLATE "C")` indexes; omitting it emits the bare column. + */ +function snowflakeText(column: Column, source?: sqlx.DialectSource): SQL { + return source === undefined ? sql`${column}` : sqlx.binaryText(source, column); +} + /** Numeric `column > cursor` for decimal TEXT snowflake ids. */ -export function afterSnowflake(column: Column, cursor: string): SQL { - return sql`(length(${column}), ${column}) > (${cursor.length}, ${cursor})`; +export function afterSnowflake(column: Column, cursor: string, source?: sqlx.DialectSource): SQL { + return sql`(length(${column}), ${snowflakeText(column, source)}) > (${cursor.length}, ${cursor})`; +} + +/** Numeric `column < cursor` for decimal TEXT snowflake ids. */ +export function beforeSnowflake(column: Column, cursor: string, source?: sqlx.DialectSource): SQL { + return sql`(length(${column}), ${snowflakeText(column, source)}) < (${cursor.length}, ${cursor})`; +} + +/** Newest-first (numeric descending) ORDER BY terms for decimal TEXT snowflake ids. */ +export function snowflakeDesc(column: Column, source?: sqlx.DialectSource): SQL { + return sql`length(${column}) DESC, ${snowflakeText(column, source)} DESC`; } /** Bounded, resumable retention; preserves TTL overrides and event high-water marks. */ diff --git a/packages/engine/src/engine/snowflakePage.ts b/packages/engine/src/engine/snowflakePage.ts new file mode 100644 index 000000000..4cd5cfc34 --- /dev/null +++ b/packages/engine/src/engine/snowflakePage.ts @@ -0,0 +1,42 @@ +import { and, sql, type Column, type SQL } from 'drizzle-orm'; +import * as sqlx from '../db/sqlx.js'; +import { afterSnowflake, snowflakeDesc } from './retention.js'; + +/** One page query: `where` is the cursor bound (combine with the caller's filters). */ +export type SnowflakePageQuery = (where: SQL | undefined, orderBy: SQL, limit: number) => PromiseLike; + +/** + * Newest-first keyset page over a decimal TEXT snowflake id column, ordered + * numerically (`length(id), id`), honouring optional exclusive `before` and + * `after` cursors. + * + * Ids widen over time (17 digits until 2025-10, 18 after), so text order is + * not numeric order. A `before` page is read in at most two index seeks over a + * `(…, length(id), id)` index: first the cursor's own width (`length(id) = L + * AND id < before`, an index range), then, only if that page is short, the + * narrower widths. A single `(length(id), id) < (L, before)` row-value bound + * cannot seek in SQLite's expression index, so it would read every newer row + * of the same width before reaching the page. + */ +export async function newestSnowflakePage( + source: sqlx.DialectSource, + column: Column, + opts: { before?: string; after?: string; limit: number }, + query: SnowflakePageQuery, +): Promise { + const after = opts.after ? afterSnowflake(column, opts.after, source) : undefined; + const desc = snowflakeDesc(column, source); + if (!opts.before) return query(after, desc, opts.limit); + + const width = opts.before.length; + const id = sqlx.binaryText(source, column); + const rows = await query( + and(sql`length(${column}) = ${width}`, sql`${id} < ${opts.before}`, after), + sql`${id} DESC`, + opts.limit, + ); + // Narrower ids are all older; none can follow an `after` cursor this wide. + if (rows.length >= opts.limit || (opts.after && opts.after.length >= width)) return rows; + const older = await query(and(sql`length(${column}) < ${width}`, after), desc, opts.limit - rows.length); + return [...rows, ...older]; +}