From 1315ce448790b33188f273bfbf1e909476df4a71 Mon Sep 17 00:00:00 2001 From: chitcommit <208086304+chitcommit@users.noreply.github.com> Date: Tue, 24 Mar 2026 17:55:06 +0000 Subject: [PATCH 1/5] fix: align evidence client types with actual ChittyEvidence API shapes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Schema Overlord audit findings (6 fixes): - EvidenceFact: entity_type not type, amount_value not value, nullable fields from LEFT JOINs (confidence, verification_status, fact_type) - EvidenceDocument: file_name not filename, created_at not uploaded_at - searchDocuments: GET→POST (ChittyEvidence /search is POST) - getContradictions: pointed to facts?conflicts_only=true (no dedicated contradictions endpoint exists) - timeline.ts: map entity_type→type and amount_value→value for consumers - mcp.ts + litigation.ts: fix a.value→a.amount_value references Co-Authored-By: Claude Opus 4.6 --- src/lib/integrations.ts | 39 +++++++++++++++++++++++++++------------ src/routes/litigation.ts | 2 +- src/routes/mcp.ts | 2 +- src/routes/timeline.ts | 10 +++++----- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/lib/integrations.ts b/src/lib/integrations.ts index 68695d4..4dbb746 100644 --- a/src/lib/integrations.ts +++ b/src/lib/integrations.ts @@ -104,21 +104,24 @@ export interface EvidenceFact { id: string; fact_text: string; fact_date?: string; - fact_type: string; - confidence: number; + fact_type?: string; + confidence?: number; source_quote?: string; - verification_status: string; + verification_status?: string; document_id?: string; - entities?: Array<{ name: string; type: string; role: string }>; - amounts?: Array<{ value: number; currency: string; description: string }>; + fact_number?: number; + case_id?: string; + // ChittyEvidence returns entity_type (not type) and amount_value (not value) + entities?: Array<{ id: string; name: string; entity_type: string; role: string; confidence: number }>; + amounts?: Array<{ id: string; fact_id: string; amount_value: number; currency: string; description: string; confidence: number }>; } export interface EvidenceDocument { id: string; - filename: string; + file_name: string; document_type?: string; processing_status: string; - uploaded_at: string; + created_at: string; content_hash?: string; } @@ -160,17 +163,29 @@ export function evidenceClient(env: Env) { getPendingFacts: (caseId?: string, limit = 50) => get(`/facts/pending?${new URLSearchParams({ ...(caseId ? { caseId } : {}), limit: String(limit) })}`), - /** Get documents for search */ - searchDocuments: (query: string) => - get(`/search?q=${encodeURIComponent(query)}`), + /** Search documents (POST /search) */ + searchDocuments: async (query: string): Promise => { + try { + const res = await fetch(`${baseUrl}/search`, { + method: 'POST', + headers: { ...headers, 'Content-Type': 'application/json' }, + body: JSON.stringify({ query }), + }); + if (!res.ok) return null; + return await res.json() as EvidenceDocument[]; + } catch (err) { + console.error('[evidence] /search error:', err); + return null; + } + }, /** Get entities */ getEntities: () => get>('/entities'), - /** Get contradictions (via legal constitution) */ + /** Get fact conflicts for a case (via statement of facts has_conflict flag) */ getContradictions: (caseId: string) => - get[]>(`/legal/cases/${encodeURIComponent(caseId)}/contradictions`), + get[]>(`/legal/cases/${encodeURIComponent(caseId)}/facts?conflicts_only=true`), }; } diff --git a/src/routes/litigation.ts b/src/routes/litigation.ts index ad35dc3..4964a9a 100644 --- a/src/routes/litigation.ts +++ b/src/routes/litigation.ts @@ -105,7 +105,7 @@ litigationRoutes.post('/synthesize-from-case', async (c) => { : '[UNKNOWN]'; const datePrefix = fact.fact_date ? `(${fact.fact_date}) ` : ''; const entities = fact.entities?.map(e => `${e.name} [${e.role}]`).join(', ') || ''; - const amounts = fact.amounts?.map(a => `${a.currency}${a.value} — ${a.description}`).join('; ') || ''; + const amounts = fact.amounts?.map(a => `${a.currency}${a.amount_value} — ${a.description}`).join('; ') || ''; let line = `${tag} ${datePrefix}${fact.fact_text}`; if (entities) line += ` | Parties: ${entities}`; diff --git a/src/routes/mcp.ts b/src/routes/mcp.ts index d235827..3f92a96 100644 --- a/src/routes/mcp.ts +++ b/src/routes/mcp.ts @@ -1198,7 +1198,7 @@ async function executeTool(env: Env, sql: NeonQueryFunction, toolN : '[UNKNOWN]'; const date = f.fact_date ? `(${f.fact_date}) ` : ''; const entities = f.entities?.map(e => `${e.name} [${e.role}]`).join(', '); - const amounts = f.amounts?.map(a => `${a.currency}${a.value}`).join(', '); + const amounts = f.amounts?.map(a => `${a.currency}${a.amount_value}`).join(', '); return { tag, date: f.fact_date || null, diff --git a/src/routes/timeline.ts b/src/routes/timeline.ts index 5b8052f..22843ff 100644 --- a/src/routes/timeline.ts +++ b/src/routes/timeline.ts @@ -43,11 +43,11 @@ timelineRoutes.get('/cases/:caseId/timeline', async (c) => { description: fact.source_quote || undefined, source: 'chittyevidence', metadata: { - factType: fact.fact_type, - confidence: fact.confidence, - verificationStatus: fact.verification_status, - entities: fact.entities, - amounts: fact.amounts, + factType: fact.fact_type || null, + confidence: fact.confidence ?? null, + verificationStatus: fact.verification_status || null, + entities: fact.entities?.map(e => ({ name: e.name, type: e.entity_type, role: e.role })), + amounts: fact.amounts?.map(a => ({ value: a.amount_value, currency: a.currency, description: a.description })), documentId: fact.document_id, }, }); From b02fe1319ce504d18a73bccad325c4321c847a5a Mon Sep 17 00:00:00 2001 From: chitcommit <208086304+chitcommit@users.noreply.github.com> Date: Tue, 24 Mar 2026 17:57:14 +0000 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20update=20MCP=20tool=20count=20in=20t?= =?UTF-8?q?est=20(43=E2=86=9248)=20and=20CLAUDE.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added 5 evidence tools: get_case_timeline, get_case_facts, get_case_contradictions, get_pending_facts, synthesize_case_facts Co-Authored-By: Claude Opus 4.6 --- CLAUDE.md | 5 +++-- tests/mcp.test.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 1366b12..e84aad1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -92,7 +92,7 @@ Three modes: - `src/lib/dispute-sync.ts` — Dispute ↔ Notion ↔ TriageAgent sync coordinator - `src/routes/bridge/index.ts` — Inter-service bridge (scrape, ledger, finance, Plaid) - `src/routes/bridge/disputes.ts` — Dispute-Notion manual sync bridge -- `src/routes/mcp.ts` — MCP server for Claude integration (32 tools) +- `src/routes/mcp.ts` — MCP server for Claude integration (48 tools) - `src/routes/meta.ts` — Public canon/schema/beacon + authenticated whoami - `src/routes/connect.ts` — ChittyConnect discovery proxy (rate-limited) - `src/routes/ledger.ts` — ChittyLedger evidence/custody passthrough @@ -137,7 +137,7 @@ Example client-side MCP configuration (conceptual): } ``` -The server exposes 43 tools across 10 domains: +The server exposes 48 tools across 12 domains: **Core meta** — `get_canon_info`, `get_registry_status`, `get_schema_refs`, `whoami`, `get_context_summary` **Financial** — `query_obligations`, `query_accounts`, `query_disputes`, `get_recommendations`, `get_cash_position`, `get_cashflow_projections`, `query_revenue_sources`, `get_payment_plan` @@ -152,5 +152,6 @@ The server exposes 43 tools across 10 domains: **Legal** — `query_legal_deadlines` **Documents** — `query_documents` **Sync** — `get_sync_status`, `trigger_sync` +**Evidence** — `get_case_timeline`, `get_case_facts`, `get_case_contradictions`, `get_pending_facts`, `synthesize_case_facts` Tools return structured JSON using MCP `content: [{ type: "json", json: ... }]` where applicable, enabling Claude Code to consume results without text parsing. diff --git a/tests/mcp.test.ts b/tests/mcp.test.ts index 8806f32..aae586b 100644 --- a/tests/mcp.test.ts +++ b/tests/mcp.test.ts @@ -147,7 +147,7 @@ describe('MCP — tools/list', () => { const json = await res.json() as Record; const result = json.result as Record; const tools = result.tools as unknown[]; - expect(tools.length).toBe(43); + expect(tools.length).toBe(48); }); it('each tool has a name and inputSchema', async () => { From 15cea3f9f5079e76139553ccd874a48d4c92b87a Mon Sep 17 00:00:00 2001 From: chitcommit <208086304+chitcommit@users.noreply.github.com> Date: Tue, 24 Mar 2026 18:00:58 +0000 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20cardinal=20audit=20=E2=80=94=20@cano?= =?UTF-8?q?n=20annotations,=20JSDoc,=20MCP/REST=20parity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add @canon governance annotations to entity_type fields in integrations.ts - Fix MCP JSDoc: "38 tools across 9 domains" → "48 tools across 12 domains" - Add date filtering to deadlines query in MCP get_case_timeline - Add ChittyLedger document fetching to MCP get_case_timeline for REST parity Co-Authored-By: Claude Opus 4.6 --- src/lib/integrations.ts | 3 ++- src/routes/mcp.ts | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/lib/integrations.ts b/src/lib/integrations.ts index 4dbb746..f85720f 100644 --- a/src/lib/integrations.ts +++ b/src/lib/integrations.ts @@ -112,6 +112,7 @@ export interface EvidenceFact { fact_number?: number; case_id?: string; // ChittyEvidence returns entity_type (not type) and amount_value (not value) + // @canon: chittycanon://gov/governance#core-types — entity_type is canonical P/L/T/E/A entities?: Array<{ id: string; name: string; entity_type: string; role: string; confidence: number }>; amounts?: Array<{ id: string; fact_id: string; amount_value: number; currency: string; description: string; confidence: number }>; } @@ -179,7 +180,7 @@ export function evidenceClient(env: Env) { } }, - /** Get entities */ + /** Get entities — entity_type is canonical P/L/T/E/A @canon: chittycanon://gov/governance#core-types */ getEntities: () => get>('/entities'), diff --git a/src/routes/mcp.ts b/src/routes/mcp.ts index 3f92a96..7cc7c86 100644 --- a/src/routes/mcp.ts +++ b/src/routes/mcp.ts @@ -11,7 +11,7 @@ import { evidenceClient, ledgerClient } from '../lib/integrations'; * MCP (Model Context Protocol) server for ChittyCommand. * * Implements JSON-RPC 2.0 over HTTP (Streamable HTTP transport). - * Provides 38 tools across 9 domains for Claude Code sessions. + * Provides 48 tools across 12 domains for Claude Code sessions. */ export const mcpRoutes = new Hono<{ Bindings: Env; Variables: AuthVariables }>(); @@ -1244,8 +1244,8 @@ async function executeTool(env: Env, sql: NeonQueryFunction, toolN } } - // Deadlines from DB - const deadlines = await sql`SELECT id, title, deadline_date, deadline_type, status FROM cc_legal_deadlines WHERE case_ref = ${caseId} ORDER BY deadline_date ASC`; + // Deadlines from DB (with date filtering) + const deadlines = await sql`SELECT id, title, deadline_date, deadline_type, status FROM cc_legal_deadlines WHERE case_ref = ${caseId} ${startDate ? sql`AND deadline_date >= ${startDate}` : sql``} ${endDate ? sql`AND deadline_date <= ${endDate}` : sql``} ORDER BY deadline_date ASC`; for (const d of deadlines) { events.push({ id: `deadline:${d.id}`, date: d.deadline_date, type: 'deadline', title: d.title, deadlineType: d.deadline_type, status: d.status }); } @@ -1256,6 +1256,21 @@ async function executeTool(env: Env, sql: NeonQueryFunction, toolN events.push({ id: `dispute:${d.id}`, date: d.created_at, type: 'dispute', title: d.title, status: d.status, domain: d.domain }); } + // Documents from ChittyLedger + const ledger = ledgerClient(env); + if (ledger) { + try { + const docs = await ledger.getEvidenceByCase(caseId); + for (const doc of docs) { + const uploadDate = (doc.created_at || doc.uploaded_at || '') as string; + if (!uploadDate) continue; + events.push({ id: `doc:${doc.id}`, date: uploadDate, type: 'document', title: `Document: ${doc.filename || doc.title || 'Untitled'}`, source: 'chittyledger' }); + } + } catch (err) { + console.error('[mcp/timeline] ledger docs error:', err); + } + } + events.sort((a, b) => String(a.date).localeCompare(String(b.date))); return { caseId, eventCount: events.length, events }; } From 46d588fea6752f9b045905c3fd49da6834e72124 Mon Sep 17 00:00:00 2001 From: chitcommit <208086304+chitcommit@users.noreply.github.com> Date: Tue, 24 Mar 2026 18:01:53 +0000 Subject: [PATCH 4/5] docs: update compliance triad with evidence/timeline/litigation/jobs endpoints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CHARTER.md: add ChittyEvidence dependency, timeline/litigation/jobs endpoints, update MCP tool count (28→48), add case timeline and litigation scope items - CHITTY.md: add same endpoints, update MCP tool count (32→48), add ChittyEvidence to direct API data sources Co-Authored-By: Claude Opus 4.6 --- CHARTER.md | 19 ++++++++++++++++--- CHITTY.md | 13 +++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/CHARTER.md b/CHARTER.md index 48976e2..432106c 100644 --- a/CHARTER.md +++ b/CHARTER.md @@ -53,7 +53,10 @@ Provide a unified life management and action dashboard that ingests data from 15 - Cron-scheduled data sync across all sources - Bridge API for inter-service data exchange (ChittyScrape, ChittyLedger) - Proxy passthrough for ChittySchema validation, ChittyCert verification, ChittyRegister requirements -- MCP server for Claude-driven queries (28 tools: financial, ledger, schema, cert, connect, chat) +- MCP server for Claude-driven queries (48 tools across 12 domains) +- Case timeline aggregation from ChittyEvidence, ChittyLedger, and local DB +- Litigation support (fact synthesis, drafting, QC) via ChittyConnect prompts or AI Gateway fallback +- Scrape job dispatch with retry, dead-letter, and fan-out to downstream agents ### IS NOT Responsible For - Identity generation (ChittyID) @@ -76,6 +79,7 @@ Provide a unified life management and action dashboard that ingests data from 15 | Upstream | ChittyCharge | Billing data | | Upstream | ChittyScrape | Browser-based scraping for portals without APIs | | Upstream | ChittyLedger | Evidence and document ledger sync | +| Upstream | ChittyEvidence | Evidence facts, documents, entities for case timelines | | Upstream | ChittyConnect | Inter-service connectivity and discovery | | Upstream | ChittyRouter | Unified ingestion gateway (scrape, email routing) | | Upstream | ChittySchema | Canonical schema validation and drift detection | @@ -116,8 +120,17 @@ Provide a unified life management and action dashboard that ingests data from 15 | `/api/recommendations` | GET | Bearer | AI action recommendations | | `/api/sync` | POST | Bearer | Manual data sync trigger | | `/api/cashflow` | GET | Bearer | Cash flow analysis | +| `/api/v1/timeline/:caseId` | GET | Bearer | Unified case timeline (facts, deadlines, disputes, docs) | +| `/api/v1/litigation/synthesize` | POST | Bearer | AI fact synthesis from raw notes | +| `/api/v1/litigation/synthesize-from-case` | POST | Bearer | AI fact synthesis auto-pulled from ChittyEvidence | +| `/api/v1/litigation/draft` | POST | Bearer | AI email drafting from synthesized facts | +| `/api/v1/litigation/qc` | POST | Bearer | AI risk scan of draft vs source notes | +| `/api/v1/jobs` | GET/POST | Bearer | Scrape job queue management | +| `/api/v1/jobs/:id` | GET | Bearer | Scrape job details | +| `/api/v1/jobs/:id/retry` | POST | Bearer | Retry failed scrape job | +| `/api/v1/jobs/dead-letters` | GET | Bearer | Dead letter queue | | `/api/bridge/*` | Various | Service/Bearer | Inter-service bridge routes | -| `/mcp/*` | Various | Service | MCP server for Claude integration | +| `/mcp/*` | Various | Service | MCP server (48 tools across 12 domains) | ### Cron Schedule | Schedule | Purpose | @@ -170,4 +183,4 @@ This charter is part of a synchronized documentation triad. Changes to shared fi - [x] CHITTY.md present --- -*Charter Version: 1.1.0 | Last Updated: 2026-03-03* +*Charter Version: 1.2.0 | Last Updated: 2026-03-24* diff --git a/CHITTY.md b/CHITTY.md index 4cf9e5e..4579ac0 100644 --- a/CHITTY.md +++ b/CHITTY.md @@ -51,7 +51,7 @@ Cloudflare Worker at command.chitty.cc with Neon PostgreSQL via Hyperdrive, R2 f | Category | Sources | |----------|---------| | Financial (auto-sync) | Mercury, Stripe, Plaid, ChittyFinance | -| Direct API | ChittyBooks, ChittyAssets, ChittyCharge, ChittyLedger | +| Direct API | ChittyBooks, ChittyAssets, ChittyCharge, ChittyLedger, ChittyEvidence | | Scrape (via ChittyScrape) | Mr. Cooper mortgage, Cook County property tax, Court docket | | Email Parse | ComEd, Peoples Gas, Xfinity, Citi, Home Depot, Lowe's | @@ -121,7 +121,16 @@ See [CHARTER.md](CHARTER.md) (Dependencies section) — canonical source for the | `/auth/*` | Various | No | Login/verify flows | | `/api/bridge/*` | Various | Service | Inter-service bridge routes | | `/api/bridge/credentials/get` | POST | Service | Allowlisted credential proxy via ChittyConnect | -| `/mcp/*` | Various | Service | MCP server (32 tools) | +| `/api/v1/timeline/:caseId` | GET | Bearer | Unified case timeline (facts, deadlines, disputes, docs) | +| `/api/v1/litigation/synthesize` | POST | Bearer | AI fact synthesis from raw notes | +| `/api/v1/litigation/synthesize-from-case` | POST | Bearer | AI fact synthesis from ChittyEvidence | +| `/api/v1/litigation/draft` | POST | Bearer | AI email drafting from synthesized facts | +| `/api/v1/litigation/qc` | POST | Bearer | AI risk scan of draft vs source notes | +| `/api/v1/jobs` | GET/POST | Bearer | Scrape job queue management | +| `/api/v1/jobs/:id` | GET | Bearer | Scrape job details | +| `/api/v1/jobs/:id/retry` | POST | Bearer | Retry failed scrape job | +| `/api/v1/jobs/dead-letters` | GET | Bearer | Dead letter queue | +| `/mcp/*` | Various | Service | MCP server (48 tools across 12 domains) | ## Document Triad From c5ffccaee44fd0a6d6f3df228847d926448e9a1e Mon Sep 17 00:00:00 2001 From: chitcommit <208086304+chitcommit@users.noreply.github.com> Date: Tue, 24 Mar 2026 18:02:23 +0000 Subject: [PATCH 5/5] fix: reconcile Drizzle schema with live Neon DB (11 cols + 2 tables) Adds missing columns from migrations 0008/0009 to schema.ts: - ccObligations: escalation tracking (5 cols) - ccRecommendations: planner-aware fields (6 cols) - ccEmailConnections + ccUserNamespaces: 2 new tables Also adds drizzle.config.ts and updates drizzle-orm to match drizzle-kit. Co-Authored-By: Claude Opus 4.6 --- drizzle.config.ts | 7 + migrations/0000_aromatic_diamondback.sql | 409 ++++ migrations/0001_dashing_bulldozer.sql | 41 + migrations/meta/0000_snapshot.json | 2416 +++++++++++++++++++ migrations/meta/0001_snapshot.json | 2727 ++++++++++++++++++++++ migrations/meta/_journal.json | 20 + package-lock.json | 38 +- package.json | 2 +- src/db/schema.ts | 42 + 9 files changed, 5684 insertions(+), 18 deletions(-) create mode 100644 drizzle.config.ts create mode 100644 migrations/0000_aromatic_diamondback.sql create mode 100644 migrations/0001_dashing_bulldozer.sql create mode 100644 migrations/meta/0000_snapshot.json create mode 100644 migrations/meta/0001_snapshot.json create mode 100644 migrations/meta/_journal.json diff --git a/drizzle.config.ts b/drizzle.config.ts new file mode 100644 index 0000000..64284d9 --- /dev/null +++ b/drizzle.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'drizzle-kit'; + +export default defineConfig({ + schema: './src/db/schema.ts', + out: './migrations', + dialect: 'postgresql', +}); diff --git a/migrations/0000_aromatic_diamondback.sql b/migrations/0000_aromatic_diamondback.sql new file mode 100644 index 0000000..107f70a --- /dev/null +++ b/migrations/0000_aromatic_diamondback.sql @@ -0,0 +1,409 @@ +CREATE TABLE IF NOT EXISTS "cc_accounts" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "source" text NOT NULL, + "source_id" text, + "account_name" text NOT NULL, + "account_type" text NOT NULL, + "institution" text NOT NULL, + "current_balance" numeric(12, 2), + "credit_limit" numeric(12, 2), + "interest_rate" numeric(5, 3), + "metadata" jsonb DEFAULT '{}'::jsonb, + "last_synced_at" timestamp with time zone, + "created_at" timestamp with time zone DEFAULT now(), + "updated_at" timestamp with time zone DEFAULT now() +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "cc_actions_log" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "action_type" text NOT NULL, + "target_type" text NOT NULL, + "target_id" uuid, + "description" text NOT NULL, + "request_payload" jsonb, + "response_payload" jsonb, + "status" text NOT NULL, + "error_message" text, + "metadata" jsonb DEFAULT '{}'::jsonb, + "executed_at" timestamp with time zone DEFAULT now() +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "cc_cashflow_projections" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "projection_date" date NOT NULL, + "projected_inflow" numeric(12, 2) DEFAULT '0', + "projected_outflow" numeric(12, 2) DEFAULT '0', + "projected_balance" numeric(12, 2) DEFAULT '0', + "obligations" jsonb, + "confidence" numeric(3, 2), + "generated_at" timestamp with time zone DEFAULT now() +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "cc_decision_feedback" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "recommendation_id" uuid, + "obligation_id" uuid, + "decision" text NOT NULL, + "original_action" text, + "modified_action" text, + "confidence_at_decision" numeric(3, 2), + "outcome_status" text, + "outcome_recorded_at" timestamp with time zone, + "session_id" uuid, + "metadata" jsonb DEFAULT '{}'::jsonb, + "created_at" timestamp with time zone DEFAULT now() +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "cc_dispute_correspondence" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "dispute_id" uuid, + "direction" text NOT NULL, + "channel" text NOT NULL, + "subject" text, + "content" text, + "attachments" jsonb DEFAULT '[]'::jsonb, + "sent_at" timestamp with time zone DEFAULT now(), + "metadata" jsonb DEFAULT '{}'::jsonb +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "cc_disputes" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "title" text NOT NULL, + "counterparty" text NOT NULL, + "dispute_type" text NOT NULL, + "amount_claimed" numeric(12, 2), + "amount_at_stake" numeric(12, 2), + "stage" text DEFAULT 'filed' NOT NULL, + "status" text DEFAULT 'open', + "priority" integer DEFAULT 5, + "description" text, + "next_action" text, + "next_action_date" date, + "resolution_target" text, + "metadata" jsonb DEFAULT '{}'::jsonb, + "created_at" timestamp with time zone DEFAULT now(), + "updated_at" timestamp with time zone DEFAULT now() +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "cc_documents" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "chitty_id" varchar(64), + "doc_type" text NOT NULL, + "source" text NOT NULL, + "filename" text, + "r2_key" text, + "content_text" text, + "parsed_data" jsonb, + "linked_obligation_id" uuid, + "linked_account_id" uuid, + "linked_dispute_id" uuid, + "processing_status" text DEFAULT 'pending', + "metadata" jsonb DEFAULT '{}'::jsonb, + "created_at" timestamp with time zone DEFAULT now() +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "cc_legal_deadlines" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "chitty_id" varchar(64), + "case_ref" text NOT NULL, + "case_system" text, + "deadline_type" text NOT NULL, + "title" text NOT NULL, + "description" text, + "deadline_date" timestamp with time zone NOT NULL, + "reminder_days" integer[] DEFAULT '{7,3,1}', + "status" text DEFAULT 'upcoming', + "urgency_score" integer, + "evidence_db_ref" text, + "metadata" jsonb DEFAULT '{}'::jsonb, + "created_at" timestamp with time zone DEFAULT now(), + "updated_at" timestamp with time zone DEFAULT now() +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "cc_obligations" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "chitty_id" varchar(64), + "account_id" uuid, + "category" text NOT NULL, + "subcategory" text, + "payee" text NOT NULL, + "amount_due" numeric(12, 2), + "amount_minimum" numeric(12, 2), + "due_date" date NOT NULL, + "recurrence" text, + "recurrence_day" integer, + "status" text DEFAULT 'pending', + "auto_pay" boolean DEFAULT false, + "negotiable" boolean DEFAULT false, + "late_fee" numeric(8, 2), + "grace_period_days" integer DEFAULT 0, + "urgency_score" integer, + "action_type" text, + "action_payload" jsonb, + "source_doc_id" uuid, + "metadata" jsonb DEFAULT '{}'::jsonb, + "created_at" timestamp with time zone DEFAULT now(), + "updated_at" timestamp with time zone DEFAULT now() +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "cc_payment_plans" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "plan_type" text NOT NULL, + "horizon_days" integer DEFAULT 90, + "starting_balance" numeric(12, 2), + "ending_balance" numeric(12, 2), + "lowest_balance" numeric(12, 2), + "lowest_balance_date" date, + "total_inflows" numeric(12, 2), + "total_outflows" numeric(12, 2), + "total_late_fees_avoided" numeric(12, 2) DEFAULT '0', + "total_late_fees_risked" numeric(12, 2) DEFAULT '0', + "schedule" jsonb NOT NULL, + "warnings" jsonb DEFAULT '[]'::jsonb, + "status" text DEFAULT 'draft', + "metadata" jsonb DEFAULT '{}'::jsonb, + "created_at" timestamp with time zone DEFAULT now() +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "cc_properties" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "chitty_id" varchar(64), + "property_name" text, + "address" text NOT NULL, + "unit" text, + "doorloop_id" text, + "property_type" text, + "monthly_hoa" numeric(8, 2), + "hoa_payee" text, + "annual_tax" numeric(12, 2), + "tax_pin" text, + "mortgage_account_id" uuid, + "mortgage_servicer" text, + "mortgage_account" text, + "metadata" jsonb DEFAULT '{}'::jsonb, + "created_at" timestamp with time zone DEFAULT now(), + "updated_at" timestamp with time zone DEFAULT now(), + CONSTRAINT "cc_properties_tax_pin_unique" UNIQUE("tax_pin") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "cc_recommendations" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "obligation_id" uuid, + "dispute_id" uuid, + "rec_type" text NOT NULL, + "priority" integer NOT NULL, + "title" text NOT NULL, + "reasoning" text NOT NULL, + "estimated_savings" numeric(10, 2), + "action_type" text, + "action_payload" jsonb, + "action_url" text, + "status" text DEFAULT 'active', + "expires_at" timestamp with time zone, + "model_version" text, + "created_at" timestamp with time zone DEFAULT now(), + "acted_on_at" timestamp with time zone +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "cc_revenue_sources" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "source" text NOT NULL, + "source_id" text, + "description" text NOT NULL, + "amount" numeric(12, 2) NOT NULL, + "recurrence" text, + "recurrence_day" integer, + "next_expected_date" date, + "confidence" numeric(3, 2) DEFAULT '0.50', + "verified_by" text, + "contract_ref" text, + "account_id" uuid, + "status" text DEFAULT 'active', + "metadata" jsonb DEFAULT '{}'::jsonb, + "created_at" timestamp with time zone DEFAULT now(), + "updated_at" timestamp with time zone DEFAULT now() +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "cc_scrape_jobs" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "chitty_id" varchar(64), + "job_type" varchar(50) NOT NULL, + "target" jsonb NOT NULL, + "status" varchar(20) DEFAULT 'queued' NOT NULL, + "attempt" integer DEFAULT 0 NOT NULL, + "max_attempts" integer DEFAULT 3 NOT NULL, + "scheduled_at" timestamp with time zone DEFAULT now(), + "started_at" timestamp with time zone, + "completed_at" timestamp with time zone, + "result" jsonb, + "error_message" text, + "parent_job_id" uuid, + "cron_source" varchar(30), + "created_at" timestamp with time zone DEFAULT now() +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "cc_sync_log" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "chitty_id" varchar(64), + "source" text NOT NULL, + "sync_type" text NOT NULL, + "status" text NOT NULL, + "records_synced" integer DEFAULT 0, + "error_message" text, + "started_at" timestamp with time zone DEFAULT now(), + "completed_at" timestamp with time zone +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "cc_tasks" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "external_id" text NOT NULL, + "notion_page_id" text, + "title" text NOT NULL, + "description" text, + "task_type" text DEFAULT 'general' NOT NULL, + "source" text DEFAULT 'notion' NOT NULL, + "priority" integer DEFAULT 5, + "backend_status" text DEFAULT 'queued' NOT NULL, + "assigned_to" text, + "due_date" date, + "verification_type" text DEFAULT 'soft' NOT NULL, + "verification_artifact" text, + "verification_notes" text, + "verified_at" timestamp with time zone, + "spawned_recommendation_id" uuid, + "ledger_record_id" text, + "metadata" jsonb DEFAULT '{}'::jsonb, + "created_at" timestamp with time zone DEFAULT now(), + "updated_at" timestamp with time zone DEFAULT now(), + CONSTRAINT "cc_tasks_external_id_unique" UNIQUE("external_id"), + CONSTRAINT "cc_tasks_notion_page_id_unique" UNIQUE("notion_page_id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "cc_transactions" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "account_id" uuid, + "obligation_id" uuid, + "source" text NOT NULL, + "source_id" text, + "counterparty" text, + "amount" numeric(12, 2) NOT NULL, + "direction" text NOT NULL, + "description" text, + "category" text, + "tx_date" date NOT NULL, + "posted_at" timestamp with time zone, + "metadata" jsonb DEFAULT '{}'::jsonb, + "created_at" timestamp with time zone DEFAULT now() +); +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "cc_decision_feedback" ADD CONSTRAINT "cc_decision_feedback_recommendation_id_cc_recommendations_id_fk" FOREIGN KEY ("recommendation_id") REFERENCES "public"."cc_recommendations"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "cc_decision_feedback" ADD CONSTRAINT "cc_decision_feedback_obligation_id_cc_obligations_id_fk" FOREIGN KEY ("obligation_id") REFERENCES "public"."cc_obligations"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "cc_dispute_correspondence" ADD CONSTRAINT "cc_dispute_correspondence_dispute_id_cc_disputes_id_fk" FOREIGN KEY ("dispute_id") REFERENCES "public"."cc_disputes"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "cc_documents" ADD CONSTRAINT "cc_documents_linked_obligation_id_cc_obligations_id_fk" FOREIGN KEY ("linked_obligation_id") REFERENCES "public"."cc_obligations"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "cc_documents" ADD CONSTRAINT "cc_documents_linked_account_id_cc_accounts_id_fk" FOREIGN KEY ("linked_account_id") REFERENCES "public"."cc_accounts"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "cc_documents" ADD CONSTRAINT "cc_documents_linked_dispute_id_cc_disputes_id_fk" FOREIGN KEY ("linked_dispute_id") REFERENCES "public"."cc_disputes"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "cc_obligations" ADD CONSTRAINT "cc_obligations_account_id_cc_accounts_id_fk" FOREIGN KEY ("account_id") REFERENCES "public"."cc_accounts"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "cc_properties" ADD CONSTRAINT "cc_properties_mortgage_account_id_cc_accounts_id_fk" FOREIGN KEY ("mortgage_account_id") REFERENCES "public"."cc_accounts"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "cc_recommendations" ADD CONSTRAINT "cc_recommendations_obligation_id_cc_obligations_id_fk" FOREIGN KEY ("obligation_id") REFERENCES "public"."cc_obligations"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "cc_recommendations" ADD CONSTRAINT "cc_recommendations_dispute_id_cc_disputes_id_fk" FOREIGN KEY ("dispute_id") REFERENCES "public"."cc_disputes"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "cc_revenue_sources" ADD CONSTRAINT "cc_revenue_sources_account_id_cc_accounts_id_fk" FOREIGN KEY ("account_id") REFERENCES "public"."cc_accounts"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "cc_tasks" ADD CONSTRAINT "cc_tasks_spawned_recommendation_id_cc_recommendations_id_fk" FOREIGN KEY ("spawned_recommendation_id") REFERENCES "public"."cc_recommendations"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "cc_transactions" ADD CONSTRAINT "cc_transactions_account_id_cc_accounts_id_fk" FOREIGN KEY ("account_id") REFERENCES "public"."cc_accounts"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "cc_transactions" ADD CONSTRAINT "cc_transactions_obligation_id_cc_obligations_id_fk" FOREIGN KEY ("obligation_id") REFERENCES "public"."cc_obligations"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_actions_log_date" ON "cc_actions_log" USING btree ("executed_at");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_cashflow_date" ON "cc_cashflow_projections" USING btree ("projection_date");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_decision_feedback_rec" ON "cc_decision_feedback" USING btree ("recommendation_id");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_decision_feedback_ob" ON "cc_decision_feedback" USING btree ("obligation_id");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_decision_feedback_created" ON "cc_decision_feedback" USING btree ("created_at");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_dispute_corr_dispute" ON "cc_dispute_correspondence" USING btree ("dispute_id");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_legal_deadlines_date" ON "cc_legal_deadlines" USING btree ("deadline_date");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_obligations_due" ON "cc_obligations" USING btree ("due_date");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_obligations_status" ON "cc_obligations" USING btree ("status");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_obligations_urgency" ON "cc_obligations" USING btree ("urgency_score");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_payment_plans_status" ON "cc_payment_plans" USING btree ("status");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_recommendations_priority" ON "cc_recommendations" USING btree ("priority");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_recommendations_status" ON "cc_recommendations" USING btree ("status");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_revenue_sources_next" ON "cc_revenue_sources" USING btree ("next_expected_date");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_revenue_sources_status" ON "cc_revenue_sources" USING btree ("status");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_scrape_jobs_status" ON "cc_scrape_jobs" USING btree ("status","scheduled_at");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_scrape_jobs_type" ON "cc_scrape_jobs" USING btree ("job_type");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_scrape_jobs_chitty" ON "cc_scrape_jobs" USING btree ("chitty_id");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_tasks_status" ON "cc_tasks" USING btree ("backend_status");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_tasks_external_id" ON "cc_tasks" USING btree ("external_id");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_tasks_notion_page_id" ON "cc_tasks" USING btree ("notion_page_id");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_tasks_due_date" ON "cc_tasks" USING btree ("due_date");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_tasks_priority" ON "cc_tasks" USING btree ("priority");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_tasks_type" ON "cc_tasks" USING btree ("task_type");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_transactions_date" ON "cc_transactions" USING btree ("tx_date");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_transactions_account" ON "cc_transactions" USING btree ("account_id");--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "idx_cc_transactions_source" ON "cc_transactions" USING btree ("source","source_id"); \ No newline at end of file diff --git a/migrations/0001_dashing_bulldozer.sql b/migrations/0001_dashing_bulldozer.sql new file mode 100644 index 0000000..ee83e92 --- /dev/null +++ b/migrations/0001_dashing_bulldozer.sql @@ -0,0 +1,41 @@ +CREATE TABLE "cc_email_connections" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "user_id" text NOT NULL, + "provider" text NOT NULL, + "email_address" text NOT NULL, + "display_name" text, + "connect_ref" text, + "namespace" text, + "status" text DEFAULT 'pending', + "last_synced_at" timestamp with time zone, + "error_message" text, + "config" jsonb DEFAULT '{}'::jsonb, + "created_at" timestamp with time zone DEFAULT now(), + "updated_at" timestamp with time zone DEFAULT now() +); +--> statement-breakpoint +CREATE TABLE "cc_user_namespaces" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "user_id" text NOT NULL, + "namespace" text NOT NULL, + "created_at" timestamp with time zone DEFAULT now(), + CONSTRAINT "cc_user_namespaces_user_id_unique" UNIQUE("user_id"), + CONSTRAINT "cc_user_namespaces_namespace_unique" UNIQUE("namespace") +); +--> statement-breakpoint +ALTER TABLE "cc_obligations" ADD COLUMN "escalation_type" text;--> statement-breakpoint +ALTER TABLE "cc_obligations" ADD COLUMN "escalation_threshold_days" integer;--> statement-breakpoint +ALTER TABLE "cc_obligations" ADD COLUMN "escalation_amount" numeric(8, 2);--> statement-breakpoint +ALTER TABLE "cc_obligations" ADD COLUMN "credit_impact_score" integer;--> statement-breakpoint +ALTER TABLE "cc_obligations" ADD COLUMN "preferred_account_id" uuid;--> statement-breakpoint +ALTER TABLE "cc_recommendations" ADD COLUMN "confidence" numeric(3, 2);--> statement-breakpoint +ALTER TABLE "cc_recommendations" ADD COLUMN "suggested_account_id" uuid;--> statement-breakpoint +ALTER TABLE "cc_recommendations" ADD COLUMN "suggested_amount" numeric(12, 2);--> statement-breakpoint +ALTER TABLE "cc_recommendations" ADD COLUMN "payment_sequence" integer;--> statement-breakpoint +ALTER TABLE "cc_recommendations" ADD COLUMN "escalation_risk" text;--> statement-breakpoint +ALTER TABLE "cc_recommendations" ADD COLUMN "scenario_impact" jsonb;--> statement-breakpoint +CREATE INDEX "idx_cc_email_conn_email_user" ON "cc_email_connections" USING btree ("email_address","user_id");--> statement-breakpoint +CREATE INDEX "idx_cc_email_conn_user" ON "cc_email_connections" USING btree ("user_id");--> statement-breakpoint +CREATE INDEX "idx_cc_email_conn_namespace" ON "cc_email_connections" USING btree ("namespace");--> statement-breakpoint +ALTER TABLE "cc_obligations" ADD CONSTRAINT "cc_obligations_preferred_account_id_cc_accounts_id_fk" FOREIGN KEY ("preferred_account_id") REFERENCES "public"."cc_accounts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "cc_recommendations" ADD CONSTRAINT "cc_recommendations_suggested_account_id_cc_accounts_id_fk" FOREIGN KEY ("suggested_account_id") REFERENCES "public"."cc_accounts"("id") ON DELETE no action ON UPDATE no action; \ No newline at end of file diff --git a/migrations/meta/0000_snapshot.json b/migrations/meta/0000_snapshot.json new file mode 100644 index 0000000..2ba3809 --- /dev/null +++ b/migrations/meta/0000_snapshot.json @@ -0,0 +1,2416 @@ +{ + "id": "2ba8676b-6c8d-4a65-b8d6-952a997c65ea", + "prevId": "00000000-0000-0000-0000-000000000000", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.cc_accounts": { + "name": "cc_accounts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_id": { + "name": "source_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "account_name": { + "name": "account_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "account_type": { + "name": "account_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "institution": { + "name": "institution", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "current_balance": { + "name": "current_balance", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "credit_limit": { + "name": "credit_limit", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "interest_rate": { + "name": "interest_rate", + "type": "numeric(5, 3)", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "last_synced_at": { + "name": "last_synced_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {} + }, + "public.cc_actions_log": { + "name": "cc_actions_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "action_type": { + "name": "action_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_id": { + "name": "target_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "request_payload": { + "name": "request_payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "response_payload": { + "name": "response_payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "executed_at": { + "name": "executed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_actions_log_date": { + "name": "idx_cc_actions_log_date", + "columns": [ + { + "expression": "executed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {} + }, + "public.cc_cashflow_projections": { + "name": "cc_cashflow_projections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "projection_date": { + "name": "projection_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "projected_inflow": { + "name": "projected_inflow", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "projected_outflow": { + "name": "projected_outflow", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "projected_balance": { + "name": "projected_balance", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "obligations": { + "name": "obligations", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "confidence": { + "name": "confidence", + "type": "numeric(3, 2)", + "primaryKey": false, + "notNull": false + }, + "generated_at": { + "name": "generated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_cashflow_date": { + "name": "idx_cc_cashflow_date", + "columns": [ + { + "expression": "projection_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {} + }, + "public.cc_decision_feedback": { + "name": "cc_decision_feedback", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "recommendation_id": { + "name": "recommendation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "obligation_id": { + "name": "obligation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "decision": { + "name": "decision", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "original_action": { + "name": "original_action", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "modified_action": { + "name": "modified_action", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "confidence_at_decision": { + "name": "confidence_at_decision", + "type": "numeric(3, 2)", + "primaryKey": false, + "notNull": false + }, + "outcome_status": { + "name": "outcome_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "outcome_recorded_at": { + "name": "outcome_recorded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_decision_feedback_rec": { + "name": "idx_cc_decision_feedback_rec", + "columns": [ + { + "expression": "recommendation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_decision_feedback_ob": { + "name": "idx_cc_decision_feedback_ob", + "columns": [ + { + "expression": "obligation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_decision_feedback_created": { + "name": "idx_cc_decision_feedback_created", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cc_decision_feedback_recommendation_id_cc_recommendations_id_fk": { + "name": "cc_decision_feedback_recommendation_id_cc_recommendations_id_fk", + "tableFrom": "cc_decision_feedback", + "tableTo": "cc_recommendations", + "columnsFrom": [ + "recommendation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "cc_decision_feedback_obligation_id_cc_obligations_id_fk": { + "name": "cc_decision_feedback_obligation_id_cc_obligations_id_fk", + "tableFrom": "cc_decision_feedback", + "tableTo": "cc_obligations", + "columnsFrom": [ + "obligation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {} + }, + "public.cc_dispute_correspondence": { + "name": "cc_dispute_correspondence", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "dispute_id": { + "name": "dispute_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "direction": { + "name": "direction", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "attachments": { + "name": "attachments", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'[]'::jsonb" + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + } + }, + "indexes": { + "idx_cc_dispute_corr_dispute": { + "name": "idx_cc_dispute_corr_dispute", + "columns": [ + { + "expression": "dispute_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cc_dispute_correspondence_dispute_id_cc_disputes_id_fk": { + "name": "cc_dispute_correspondence_dispute_id_cc_disputes_id_fk", + "tableFrom": "cc_dispute_correspondence", + "tableTo": "cc_disputes", + "columnsFrom": [ + "dispute_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {} + }, + "public.cc_disputes": { + "name": "cc_disputes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "counterparty": { + "name": "counterparty", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "dispute_type": { + "name": "dispute_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "amount_claimed": { + "name": "amount_claimed", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "amount_at_stake": { + "name": "amount_at_stake", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "stage": { + "name": "stage", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'filed'" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'open'" + }, + "priority": { + "name": "priority", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 5 + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "next_action": { + "name": "next_action", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "next_action_date": { + "name": "next_action_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "resolution_target": { + "name": "resolution_target", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {} + }, + "public.cc_documents": { + "name": "cc_documents", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "chitty_id": { + "name": "chitty_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "doc_type": { + "name": "doc_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "filename": { + "name": "filename", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "r2_key": { + "name": "r2_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "content_text": { + "name": "content_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "parsed_data": { + "name": "parsed_data", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "linked_obligation_id": { + "name": "linked_obligation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "linked_account_id": { + "name": "linked_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "linked_dispute_id": { + "name": "linked_dispute_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "processing_status": { + "name": "processing_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'pending'" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "cc_documents_linked_obligation_id_cc_obligations_id_fk": { + "name": "cc_documents_linked_obligation_id_cc_obligations_id_fk", + "tableFrom": "cc_documents", + "tableTo": "cc_obligations", + "columnsFrom": [ + "linked_obligation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "cc_documents_linked_account_id_cc_accounts_id_fk": { + "name": "cc_documents_linked_account_id_cc_accounts_id_fk", + "tableFrom": "cc_documents", + "tableTo": "cc_accounts", + "columnsFrom": [ + "linked_account_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "cc_documents_linked_dispute_id_cc_disputes_id_fk": { + "name": "cc_documents_linked_dispute_id_cc_disputes_id_fk", + "tableFrom": "cc_documents", + "tableTo": "cc_disputes", + "columnsFrom": [ + "linked_dispute_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {} + }, + "public.cc_legal_deadlines": { + "name": "cc_legal_deadlines", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "chitty_id": { + "name": "chitty_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "case_ref": { + "name": "case_ref", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "case_system": { + "name": "case_system", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_type": { + "name": "deadline_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_date": { + "name": "deadline_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "reminder_days": { + "name": "reminder_days", + "type": "integer[]", + "primaryKey": false, + "notNull": false, + "default": "'{7,3,1}'" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'upcoming'" + }, + "urgency_score": { + "name": "urgency_score", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evidence_db_ref": { + "name": "evidence_db_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_legal_deadlines_date": { + "name": "idx_cc_legal_deadlines_date", + "columns": [ + { + "expression": "deadline_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {} + }, + "public.cc_obligations": { + "name": "cc_obligations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "chitty_id": { + "name": "chitty_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subcategory": { + "name": "subcategory", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "payee": { + "name": "payee", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "amount_due": { + "name": "amount_due", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "amount_minimum": { + "name": "amount_minimum", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "recurrence": { + "name": "recurrence", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "recurrence_day": { + "name": "recurrence_day", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'pending'" + }, + "auto_pay": { + "name": "auto_pay", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "negotiable": { + "name": "negotiable", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "late_fee": { + "name": "late_fee", + "type": "numeric(8, 2)", + "primaryKey": false, + "notNull": false + }, + "grace_period_days": { + "name": "grace_period_days", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "urgency_score": { + "name": "urgency_score", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "action_type": { + "name": "action_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action_payload": { + "name": "action_payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "source_doc_id": { + "name": "source_doc_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_obligations_due": { + "name": "idx_cc_obligations_due", + "columns": [ + { + "expression": "due_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_obligations_status": { + "name": "idx_cc_obligations_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_obligations_urgency": { + "name": "idx_cc_obligations_urgency", + "columns": [ + { + "expression": "urgency_score", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cc_obligations_account_id_cc_accounts_id_fk": { + "name": "cc_obligations_account_id_cc_accounts_id_fk", + "tableFrom": "cc_obligations", + "tableTo": "cc_accounts", + "columnsFrom": [ + "account_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {} + }, + "public.cc_payment_plans": { + "name": "cc_payment_plans", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "plan_type": { + "name": "plan_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "horizon_days": { + "name": "horizon_days", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 90 + }, + "starting_balance": { + "name": "starting_balance", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "ending_balance": { + "name": "ending_balance", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "lowest_balance": { + "name": "lowest_balance", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "lowest_balance_date": { + "name": "lowest_balance_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "total_inflows": { + "name": "total_inflows", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "total_outflows": { + "name": "total_outflows", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "total_late_fees_avoided": { + "name": "total_late_fees_avoided", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "total_late_fees_risked": { + "name": "total_late_fees_risked", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "schedule": { + "name": "schedule", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "warnings": { + "name": "warnings", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'[]'::jsonb" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'draft'" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_payment_plans_status": { + "name": "idx_cc_payment_plans_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {} + }, + "public.cc_properties": { + "name": "cc_properties", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "chitty_id": { + "name": "chitty_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "property_name": { + "name": "property_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "unit": { + "name": "unit", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "doorloop_id": { + "name": "doorloop_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "property_type": { + "name": "property_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "monthly_hoa": { + "name": "monthly_hoa", + "type": "numeric(8, 2)", + "primaryKey": false, + "notNull": false + }, + "hoa_payee": { + "name": "hoa_payee", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "annual_tax": { + "name": "annual_tax", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "tax_pin": { + "name": "tax_pin", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mortgage_account_id": { + "name": "mortgage_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "mortgage_servicer": { + "name": "mortgage_servicer", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mortgage_account": { + "name": "mortgage_account", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "cc_properties_mortgage_account_id_cc_accounts_id_fk": { + "name": "cc_properties_mortgage_account_id_cc_accounts_id_fk", + "tableFrom": "cc_properties", + "tableTo": "cc_accounts", + "columnsFrom": [ + "mortgage_account_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "cc_properties_tax_pin_unique": { + "name": "cc_properties_tax_pin_unique", + "nullsNotDistinct": false, + "columns": [ + "tax_pin" + ] + } + }, + "policies": {}, + "checkConstraints": {} + }, + "public.cc_recommendations": { + "name": "cc_recommendations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "obligation_id": { + "name": "obligation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "dispute_id": { + "name": "dispute_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "rec_type": { + "name": "rec_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "priority": { + "name": "priority", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reasoning": { + "name": "reasoning", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "estimated_savings": { + "name": "estimated_savings", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": false + }, + "action_type": { + "name": "action_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action_payload": { + "name": "action_payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "action_url": { + "name": "action_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'active'" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "model_version": { + "name": "model_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "acted_on_at": { + "name": "acted_on_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_cc_recommendations_priority": { + "name": "idx_cc_recommendations_priority", + "columns": [ + { + "expression": "priority", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_recommendations_status": { + "name": "idx_cc_recommendations_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cc_recommendations_obligation_id_cc_obligations_id_fk": { + "name": "cc_recommendations_obligation_id_cc_obligations_id_fk", + "tableFrom": "cc_recommendations", + "tableTo": "cc_obligations", + "columnsFrom": [ + "obligation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "cc_recommendations_dispute_id_cc_disputes_id_fk": { + "name": "cc_recommendations_dispute_id_cc_disputes_id_fk", + "tableFrom": "cc_recommendations", + "tableTo": "cc_disputes", + "columnsFrom": [ + "dispute_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {} + }, + "public.cc_revenue_sources": { + "name": "cc_revenue_sources", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_id": { + "name": "source_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": true + }, + "recurrence": { + "name": "recurrence", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "recurrence_day": { + "name": "recurrence_day", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "next_expected_date": { + "name": "next_expected_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "confidence": { + "name": "confidence", + "type": "numeric(3, 2)", + "primaryKey": false, + "notNull": false, + "default": "'0.50'" + }, + "verified_by": { + "name": "verified_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "contract_ref": { + "name": "contract_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'active'" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_revenue_sources_next": { + "name": "idx_cc_revenue_sources_next", + "columns": [ + { + "expression": "next_expected_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_revenue_sources_status": { + "name": "idx_cc_revenue_sources_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cc_revenue_sources_account_id_cc_accounts_id_fk": { + "name": "cc_revenue_sources_account_id_cc_accounts_id_fk", + "tableFrom": "cc_revenue_sources", + "tableTo": "cc_accounts", + "columnsFrom": [ + "account_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {} + }, + "public.cc_scrape_jobs": { + "name": "cc_scrape_jobs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "chitty_id": { + "name": "chitty_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "job_type": { + "name": "job_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "target": { + "name": "target", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "attempt": { + "name": "attempt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "max_attempts": { + "name": "max_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 3 + }, + "scheduled_at": { + "name": "scheduled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "result": { + "name": "result", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "parent_job_id": { + "name": "parent_job_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cron_source": { + "name": "cron_source", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_scrape_jobs_status": { + "name": "idx_cc_scrape_jobs_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "scheduled_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_scrape_jobs_type": { + "name": "idx_cc_scrape_jobs_type", + "columns": [ + { + "expression": "job_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_scrape_jobs_chitty": { + "name": "idx_cc_scrape_jobs_chitty", + "columns": [ + { + "expression": "chitty_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {} + }, + "public.cc_sync_log": { + "name": "cc_sync_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "chitty_id": { + "name": "chitty_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sync_type": { + "name": "sync_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "records_synced": { + "name": "records_synced", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {} + }, + "public.cc_tasks": { + "name": "cc_tasks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "notion_page_id": { + "name": "notion_page_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "task_type": { + "name": "task_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'general'" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'notion'" + }, + "priority": { + "name": "priority", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 5 + }, + "backend_status": { + "name": "backend_status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "assigned_to": { + "name": "assigned_to", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "verification_type": { + "name": "verification_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'soft'" + }, + "verification_artifact": { + "name": "verification_artifact", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "verification_notes": { + "name": "verification_notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "verified_at": { + "name": "verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "spawned_recommendation_id": { + "name": "spawned_recommendation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "ledger_record_id": { + "name": "ledger_record_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_tasks_status": { + "name": "idx_cc_tasks_status", + "columns": [ + { + "expression": "backend_status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_tasks_external_id": { + "name": "idx_cc_tasks_external_id", + "columns": [ + { + "expression": "external_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_tasks_notion_page_id": { + "name": "idx_cc_tasks_notion_page_id", + "columns": [ + { + "expression": "notion_page_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_tasks_due_date": { + "name": "idx_cc_tasks_due_date", + "columns": [ + { + "expression": "due_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_tasks_priority": { + "name": "idx_cc_tasks_priority", + "columns": [ + { + "expression": "priority", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_tasks_type": { + "name": "idx_cc_tasks_type", + "columns": [ + { + "expression": "task_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cc_tasks_spawned_recommendation_id_cc_recommendations_id_fk": { + "name": "cc_tasks_spawned_recommendation_id_cc_recommendations_id_fk", + "tableFrom": "cc_tasks", + "tableTo": "cc_recommendations", + "columnsFrom": [ + "spawned_recommendation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "cc_tasks_external_id_unique": { + "name": "cc_tasks_external_id_unique", + "nullsNotDistinct": false, + "columns": [ + "external_id" + ] + }, + "cc_tasks_notion_page_id_unique": { + "name": "cc_tasks_notion_page_id_unique", + "nullsNotDistinct": false, + "columns": [ + "notion_page_id" + ] + } + }, + "policies": {}, + "checkConstraints": {} + }, + "public.cc_transactions": { + "name": "cc_transactions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "obligation_id": { + "name": "obligation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_id": { + "name": "source_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "counterparty": { + "name": "counterparty", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "amount": { + "name": "amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": true + }, + "direction": { + "name": "direction", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tx_date": { + "name": "tx_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "posted_at": { + "name": "posted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_transactions_date": { + "name": "idx_cc_transactions_date", + "columns": [ + { + "expression": "tx_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_transactions_account": { + "name": "idx_cc_transactions_account", + "columns": [ + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_transactions_source": { + "name": "idx_cc_transactions_source", + "columns": [ + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cc_transactions_account_id_cc_accounts_id_fk": { + "name": "cc_transactions_account_id_cc_accounts_id_fk", + "tableFrom": "cc_transactions", + "tableTo": "cc_accounts", + "columnsFrom": [ + "account_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "cc_transactions_obligation_id_cc_obligations_id_fk": { + "name": "cc_transactions_obligation_id_cc_obligations_id_fk", + "tableFrom": "cc_transactions", + "tableTo": "cc_obligations", + "columnsFrom": [ + "obligation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {} + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/migrations/meta/0001_snapshot.json b/migrations/meta/0001_snapshot.json new file mode 100644 index 0000000..62d20c4 --- /dev/null +++ b/migrations/meta/0001_snapshot.json @@ -0,0 +1,2727 @@ +{ + "id": "88be8848-936b-4a7a-9924-0b91abebd153", + "prevId": "2ba8676b-6c8d-4a65-b8d6-952a997c65ea", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.cc_accounts": { + "name": "cc_accounts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_id": { + "name": "source_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "account_name": { + "name": "account_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "account_type": { + "name": "account_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "institution": { + "name": "institution", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "current_balance": { + "name": "current_balance", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "credit_limit": { + "name": "credit_limit", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "interest_rate": { + "name": "interest_rate", + "type": "numeric(5, 3)", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "last_synced_at": { + "name": "last_synced_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_actions_log": { + "name": "cc_actions_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "action_type": { + "name": "action_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_id": { + "name": "target_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "request_payload": { + "name": "request_payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "response_payload": { + "name": "response_payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "executed_at": { + "name": "executed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_actions_log_date": { + "name": "idx_cc_actions_log_date", + "columns": [ + { + "expression": "executed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_cashflow_projections": { + "name": "cc_cashflow_projections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "projection_date": { + "name": "projection_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "projected_inflow": { + "name": "projected_inflow", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "projected_outflow": { + "name": "projected_outflow", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "projected_balance": { + "name": "projected_balance", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "obligations": { + "name": "obligations", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "confidence": { + "name": "confidence", + "type": "numeric(3, 2)", + "primaryKey": false, + "notNull": false + }, + "generated_at": { + "name": "generated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_cashflow_date": { + "name": "idx_cc_cashflow_date", + "columns": [ + { + "expression": "projection_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_decision_feedback": { + "name": "cc_decision_feedback", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "recommendation_id": { + "name": "recommendation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "obligation_id": { + "name": "obligation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "decision": { + "name": "decision", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "original_action": { + "name": "original_action", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "modified_action": { + "name": "modified_action", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "confidence_at_decision": { + "name": "confidence_at_decision", + "type": "numeric(3, 2)", + "primaryKey": false, + "notNull": false + }, + "outcome_status": { + "name": "outcome_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "outcome_recorded_at": { + "name": "outcome_recorded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_decision_feedback_rec": { + "name": "idx_cc_decision_feedback_rec", + "columns": [ + { + "expression": "recommendation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_decision_feedback_ob": { + "name": "idx_cc_decision_feedback_ob", + "columns": [ + { + "expression": "obligation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_decision_feedback_created": { + "name": "idx_cc_decision_feedback_created", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cc_decision_feedback_recommendation_id_cc_recommendations_id_fk": { + "name": "cc_decision_feedback_recommendation_id_cc_recommendations_id_fk", + "tableFrom": "cc_decision_feedback", + "tableTo": "cc_recommendations", + "columnsFrom": [ + "recommendation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "cc_decision_feedback_obligation_id_cc_obligations_id_fk": { + "name": "cc_decision_feedback_obligation_id_cc_obligations_id_fk", + "tableFrom": "cc_decision_feedback", + "tableTo": "cc_obligations", + "columnsFrom": [ + "obligation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_dispute_correspondence": { + "name": "cc_dispute_correspondence", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "dispute_id": { + "name": "dispute_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "direction": { + "name": "direction", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "attachments": { + "name": "attachments", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'[]'::jsonb" + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + } + }, + "indexes": { + "idx_cc_dispute_corr_dispute": { + "name": "idx_cc_dispute_corr_dispute", + "columns": [ + { + "expression": "dispute_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cc_dispute_correspondence_dispute_id_cc_disputes_id_fk": { + "name": "cc_dispute_correspondence_dispute_id_cc_disputes_id_fk", + "tableFrom": "cc_dispute_correspondence", + "tableTo": "cc_disputes", + "columnsFrom": [ + "dispute_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_disputes": { + "name": "cc_disputes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "counterparty": { + "name": "counterparty", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "dispute_type": { + "name": "dispute_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "amount_claimed": { + "name": "amount_claimed", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "amount_at_stake": { + "name": "amount_at_stake", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "stage": { + "name": "stage", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'filed'" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'open'" + }, + "priority": { + "name": "priority", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 5 + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "next_action": { + "name": "next_action", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "next_action_date": { + "name": "next_action_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "resolution_target": { + "name": "resolution_target", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_documents": { + "name": "cc_documents", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "chitty_id": { + "name": "chitty_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "doc_type": { + "name": "doc_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "filename": { + "name": "filename", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "r2_key": { + "name": "r2_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "content_text": { + "name": "content_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "parsed_data": { + "name": "parsed_data", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "linked_obligation_id": { + "name": "linked_obligation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "linked_account_id": { + "name": "linked_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "linked_dispute_id": { + "name": "linked_dispute_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "processing_status": { + "name": "processing_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'pending'" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "cc_documents_linked_obligation_id_cc_obligations_id_fk": { + "name": "cc_documents_linked_obligation_id_cc_obligations_id_fk", + "tableFrom": "cc_documents", + "tableTo": "cc_obligations", + "columnsFrom": [ + "linked_obligation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "cc_documents_linked_account_id_cc_accounts_id_fk": { + "name": "cc_documents_linked_account_id_cc_accounts_id_fk", + "tableFrom": "cc_documents", + "tableTo": "cc_accounts", + "columnsFrom": [ + "linked_account_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "cc_documents_linked_dispute_id_cc_disputes_id_fk": { + "name": "cc_documents_linked_dispute_id_cc_disputes_id_fk", + "tableFrom": "cc_documents", + "tableTo": "cc_disputes", + "columnsFrom": [ + "linked_dispute_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_email_connections": { + "name": "cc_email_connections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_address": { + "name": "email_address", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "connect_ref": { + "name": "connect_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "namespace": { + "name": "namespace", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'pending'" + }, + "last_synced_at": { + "name": "last_synced_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "config": { + "name": "config", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_email_conn_email_user": { + "name": "idx_cc_email_conn_email_user", + "columns": [ + { + "expression": "email_address", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_email_conn_user": { + "name": "idx_cc_email_conn_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_email_conn_namespace": { + "name": "idx_cc_email_conn_namespace", + "columns": [ + { + "expression": "namespace", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_legal_deadlines": { + "name": "cc_legal_deadlines", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "chitty_id": { + "name": "chitty_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "case_ref": { + "name": "case_ref", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "case_system": { + "name": "case_system", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_type": { + "name": "deadline_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_date": { + "name": "deadline_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "reminder_days": { + "name": "reminder_days", + "type": "integer[]", + "primaryKey": false, + "notNull": false, + "default": "'{7,3,1}'" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'upcoming'" + }, + "urgency_score": { + "name": "urgency_score", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evidence_db_ref": { + "name": "evidence_db_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_legal_deadlines_date": { + "name": "idx_cc_legal_deadlines_date", + "columns": [ + { + "expression": "deadline_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_obligations": { + "name": "cc_obligations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "chitty_id": { + "name": "chitty_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subcategory": { + "name": "subcategory", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "payee": { + "name": "payee", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "amount_due": { + "name": "amount_due", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "amount_minimum": { + "name": "amount_minimum", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "recurrence": { + "name": "recurrence", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "recurrence_day": { + "name": "recurrence_day", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'pending'" + }, + "auto_pay": { + "name": "auto_pay", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "negotiable": { + "name": "negotiable", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "late_fee": { + "name": "late_fee", + "type": "numeric(8, 2)", + "primaryKey": false, + "notNull": false + }, + "grace_period_days": { + "name": "grace_period_days", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "urgency_score": { + "name": "urgency_score", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "action_type": { + "name": "action_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action_payload": { + "name": "action_payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "source_doc_id": { + "name": "source_doc_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "escalation_type": { + "name": "escalation_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "escalation_threshold_days": { + "name": "escalation_threshold_days", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "escalation_amount": { + "name": "escalation_amount", + "type": "numeric(8, 2)", + "primaryKey": false, + "notNull": false + }, + "credit_impact_score": { + "name": "credit_impact_score", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "preferred_account_id": { + "name": "preferred_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_obligations_due": { + "name": "idx_cc_obligations_due", + "columns": [ + { + "expression": "due_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_obligations_status": { + "name": "idx_cc_obligations_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_obligations_urgency": { + "name": "idx_cc_obligations_urgency", + "columns": [ + { + "expression": "urgency_score", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cc_obligations_account_id_cc_accounts_id_fk": { + "name": "cc_obligations_account_id_cc_accounts_id_fk", + "tableFrom": "cc_obligations", + "tableTo": "cc_accounts", + "columnsFrom": [ + "account_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "cc_obligations_preferred_account_id_cc_accounts_id_fk": { + "name": "cc_obligations_preferred_account_id_cc_accounts_id_fk", + "tableFrom": "cc_obligations", + "tableTo": "cc_accounts", + "columnsFrom": [ + "preferred_account_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_payment_plans": { + "name": "cc_payment_plans", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "plan_type": { + "name": "plan_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "horizon_days": { + "name": "horizon_days", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 90 + }, + "starting_balance": { + "name": "starting_balance", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "ending_balance": { + "name": "ending_balance", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "lowest_balance": { + "name": "lowest_balance", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "lowest_balance_date": { + "name": "lowest_balance_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "total_inflows": { + "name": "total_inflows", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "total_outflows": { + "name": "total_outflows", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "total_late_fees_avoided": { + "name": "total_late_fees_avoided", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "total_late_fees_risked": { + "name": "total_late_fees_risked", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "schedule": { + "name": "schedule", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "warnings": { + "name": "warnings", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'[]'::jsonb" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'draft'" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_payment_plans_status": { + "name": "idx_cc_payment_plans_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_properties": { + "name": "cc_properties", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "chitty_id": { + "name": "chitty_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "property_name": { + "name": "property_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "unit": { + "name": "unit", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "doorloop_id": { + "name": "doorloop_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "property_type": { + "name": "property_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "monthly_hoa": { + "name": "monthly_hoa", + "type": "numeric(8, 2)", + "primaryKey": false, + "notNull": false + }, + "hoa_payee": { + "name": "hoa_payee", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "annual_tax": { + "name": "annual_tax", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "tax_pin": { + "name": "tax_pin", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mortgage_account_id": { + "name": "mortgage_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "mortgage_servicer": { + "name": "mortgage_servicer", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mortgage_account": { + "name": "mortgage_account", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "cc_properties_mortgage_account_id_cc_accounts_id_fk": { + "name": "cc_properties_mortgage_account_id_cc_accounts_id_fk", + "tableFrom": "cc_properties", + "tableTo": "cc_accounts", + "columnsFrom": [ + "mortgage_account_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "cc_properties_tax_pin_unique": { + "name": "cc_properties_tax_pin_unique", + "nullsNotDistinct": false, + "columns": [ + "tax_pin" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_recommendations": { + "name": "cc_recommendations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "obligation_id": { + "name": "obligation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "dispute_id": { + "name": "dispute_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "rec_type": { + "name": "rec_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "priority": { + "name": "priority", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reasoning": { + "name": "reasoning", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "estimated_savings": { + "name": "estimated_savings", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": false + }, + "action_type": { + "name": "action_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action_payload": { + "name": "action_payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "action_url": { + "name": "action_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'active'" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "model_version": { + "name": "model_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "confidence": { + "name": "confidence", + "type": "numeric(3, 2)", + "primaryKey": false, + "notNull": false + }, + "suggested_account_id": { + "name": "suggested_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "suggested_amount": { + "name": "suggested_amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "payment_sequence": { + "name": "payment_sequence", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "escalation_risk": { + "name": "escalation_risk", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scenario_impact": { + "name": "scenario_impact", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "acted_on_at": { + "name": "acted_on_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_cc_recommendations_priority": { + "name": "idx_cc_recommendations_priority", + "columns": [ + { + "expression": "priority", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_recommendations_status": { + "name": "idx_cc_recommendations_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cc_recommendations_obligation_id_cc_obligations_id_fk": { + "name": "cc_recommendations_obligation_id_cc_obligations_id_fk", + "tableFrom": "cc_recommendations", + "tableTo": "cc_obligations", + "columnsFrom": [ + "obligation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "cc_recommendations_dispute_id_cc_disputes_id_fk": { + "name": "cc_recommendations_dispute_id_cc_disputes_id_fk", + "tableFrom": "cc_recommendations", + "tableTo": "cc_disputes", + "columnsFrom": [ + "dispute_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "cc_recommendations_suggested_account_id_cc_accounts_id_fk": { + "name": "cc_recommendations_suggested_account_id_cc_accounts_id_fk", + "tableFrom": "cc_recommendations", + "tableTo": "cc_accounts", + "columnsFrom": [ + "suggested_account_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_revenue_sources": { + "name": "cc_revenue_sources", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_id": { + "name": "source_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": true + }, + "recurrence": { + "name": "recurrence", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "recurrence_day": { + "name": "recurrence_day", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "next_expected_date": { + "name": "next_expected_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "confidence": { + "name": "confidence", + "type": "numeric(3, 2)", + "primaryKey": false, + "notNull": false, + "default": "'0.50'" + }, + "verified_by": { + "name": "verified_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "contract_ref": { + "name": "contract_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'active'" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_revenue_sources_next": { + "name": "idx_cc_revenue_sources_next", + "columns": [ + { + "expression": "next_expected_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_revenue_sources_status": { + "name": "idx_cc_revenue_sources_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cc_revenue_sources_account_id_cc_accounts_id_fk": { + "name": "cc_revenue_sources_account_id_cc_accounts_id_fk", + "tableFrom": "cc_revenue_sources", + "tableTo": "cc_accounts", + "columnsFrom": [ + "account_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_scrape_jobs": { + "name": "cc_scrape_jobs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "chitty_id": { + "name": "chitty_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "job_type": { + "name": "job_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "target": { + "name": "target", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "attempt": { + "name": "attempt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "max_attempts": { + "name": "max_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 3 + }, + "scheduled_at": { + "name": "scheduled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "result": { + "name": "result", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "parent_job_id": { + "name": "parent_job_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cron_source": { + "name": "cron_source", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_scrape_jobs_status": { + "name": "idx_cc_scrape_jobs_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "scheduled_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_scrape_jobs_type": { + "name": "idx_cc_scrape_jobs_type", + "columns": [ + { + "expression": "job_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_scrape_jobs_chitty": { + "name": "idx_cc_scrape_jobs_chitty", + "columns": [ + { + "expression": "chitty_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_sync_log": { + "name": "cc_sync_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "chitty_id": { + "name": "chitty_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sync_type": { + "name": "sync_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "records_synced": { + "name": "records_synced", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_tasks": { + "name": "cc_tasks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "notion_page_id": { + "name": "notion_page_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "task_type": { + "name": "task_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'general'" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'notion'" + }, + "priority": { + "name": "priority", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 5 + }, + "backend_status": { + "name": "backend_status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "assigned_to": { + "name": "assigned_to", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "verification_type": { + "name": "verification_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'soft'" + }, + "verification_artifact": { + "name": "verification_artifact", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "verification_notes": { + "name": "verification_notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "verified_at": { + "name": "verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "spawned_recommendation_id": { + "name": "spawned_recommendation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "ledger_record_id": { + "name": "ledger_record_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_tasks_status": { + "name": "idx_cc_tasks_status", + "columns": [ + { + "expression": "backend_status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_tasks_external_id": { + "name": "idx_cc_tasks_external_id", + "columns": [ + { + "expression": "external_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_tasks_notion_page_id": { + "name": "idx_cc_tasks_notion_page_id", + "columns": [ + { + "expression": "notion_page_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_tasks_due_date": { + "name": "idx_cc_tasks_due_date", + "columns": [ + { + "expression": "due_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_tasks_priority": { + "name": "idx_cc_tasks_priority", + "columns": [ + { + "expression": "priority", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_tasks_type": { + "name": "idx_cc_tasks_type", + "columns": [ + { + "expression": "task_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cc_tasks_spawned_recommendation_id_cc_recommendations_id_fk": { + "name": "cc_tasks_spawned_recommendation_id_cc_recommendations_id_fk", + "tableFrom": "cc_tasks", + "tableTo": "cc_recommendations", + "columnsFrom": [ + "spawned_recommendation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "cc_tasks_external_id_unique": { + "name": "cc_tasks_external_id_unique", + "nullsNotDistinct": false, + "columns": [ + "external_id" + ] + }, + "cc_tasks_notion_page_id_unique": { + "name": "cc_tasks_notion_page_id_unique", + "nullsNotDistinct": false, + "columns": [ + "notion_page_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_transactions": { + "name": "cc_transactions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "obligation_id": { + "name": "obligation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_id": { + "name": "source_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "counterparty": { + "name": "counterparty", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "amount": { + "name": "amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": true + }, + "direction": { + "name": "direction", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tx_date": { + "name": "tx_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "posted_at": { + "name": "posted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_cc_transactions_date": { + "name": "idx_cc_transactions_date", + "columns": [ + { + "expression": "tx_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_transactions_account": { + "name": "idx_cc_transactions_account", + "columns": [ + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_cc_transactions_source": { + "name": "idx_cc_transactions_source", + "columns": [ + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cc_transactions_account_id_cc_accounts_id_fk": { + "name": "cc_transactions_account_id_cc_accounts_id_fk", + "tableFrom": "cc_transactions", + "tableTo": "cc_accounts", + "columnsFrom": [ + "account_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "cc_transactions_obligation_id_cc_obligations_id_fk": { + "name": "cc_transactions_obligation_id_cc_obligations_id_fk", + "tableFrom": "cc_transactions", + "tableTo": "cc_obligations", + "columnsFrom": [ + "obligation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cc_user_namespaces": { + "name": "cc_user_namespaces", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "namespace": { + "name": "namespace", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "cc_user_namespaces_user_id_unique": { + "name": "cc_user_namespaces_user_id_unique", + "nullsNotDistinct": false, + "columns": [ + "user_id" + ] + }, + "cc_user_namespaces_namespace_unique": { + "name": "cc_user_namespaces_namespace_unique", + "nullsNotDistinct": false, + "columns": [ + "namespace" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/migrations/meta/_journal.json b/migrations/meta/_journal.json new file mode 100644 index 0000000..cfae81f --- /dev/null +++ b/migrations/meta/_journal.json @@ -0,0 +1,20 @@ +{ + "version": "7", + "dialect": "postgresql", + "entries": [ + { + "idx": 0, + "version": "7", + "when": 1774315592286, + "tag": "0000_aromatic_diamondback", + "breakpoints": true + }, + { + "idx": 1, + "version": "7", + "when": 1774375302000, + "tag": "0001_dashing_bulldozer", + "breakpoints": true + } + ] +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 9197ffe..cee1efd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "@hono/zod-validator": "^0.7.6", "@neondatabase/serverless": "^0.10.0", - "drizzle-orm": "^0.33.0", + "drizzle-orm": "^0.45.1", "hono": "^4.12.5", "zod": "^3.23.0" }, @@ -1829,36 +1829,37 @@ } }, "node_modules/drizzle-orm": { - "version": "0.33.0", - "resolved": "https://registry.npmjs.org/drizzle-orm/-/drizzle-orm-0.33.0.tgz", - "integrity": "sha512-SHy72R2Rdkz0LEq0PSG/IdvnT3nGiWuRk+2tXZQ90GVq/XQhpCzu/EFT3V2rox+w8MlkBQxifF8pCStNYnERfA==", + "version": "0.45.1", + "resolved": "https://registry.npmjs.org/drizzle-orm/-/drizzle-orm-0.45.1.tgz", + "integrity": "sha512-Te0FOdKIistGNPMq2jscdqngBRfBpC8uMFVwqjf6gtTVJHIQ/dosgV/CLBU2N4ZJBsXL5savCba9b0YJskKdcA==", "license": "Apache-2.0", "peerDependencies": { "@aws-sdk/client-rds-data": ">=3", - "@cloudflare/workers-types": ">=3", - "@electric-sql/pglite": ">=0.1.1", - "@libsql/client": "*", - "@neondatabase/serverless": ">=0.1", + "@cloudflare/workers-types": ">=4", + "@electric-sql/pglite": ">=0.2.0", + "@libsql/client": ">=0.10.0", + "@libsql/client-wasm": ">=0.10.0", + "@neondatabase/serverless": ">=0.10.0", "@op-engineering/op-sqlite": ">=2", "@opentelemetry/api": "^1.4.1", - "@planetscale/database": ">=1", + "@planetscale/database": ">=1.13", "@prisma/client": "*", "@tidbcloud/serverless": "*", "@types/better-sqlite3": "*", "@types/pg": "*", - "@types/react": ">=18", "@types/sql.js": "*", + "@upstash/redis": ">=1.34.7", "@vercel/postgres": ">=0.8.0", "@xata.io/client": "*", "better-sqlite3": ">=7", "bun-types": "*", - "expo-sqlite": ">=13.2.0", + "expo-sqlite": ">=14.0.0", + "gel": ">=2", "knex": "*", "kysely": "*", "mysql2": ">=2", "pg": ">=8", "postgres": ">=3", - "react": ">=18", "sql.js": ">=1", "sqlite3": ">=5" }, @@ -1875,6 +1876,9 @@ "@libsql/client": { "optional": true }, + "@libsql/client-wasm": { + "optional": true + }, "@neondatabase/serverless": { "optional": true }, @@ -1899,10 +1903,10 @@ "@types/pg": { "optional": true }, - "@types/react": { + "@types/sql.js": { "optional": true }, - "@types/sql.js": { + "@upstash/redis": { "optional": true }, "@vercel/postgres": { @@ -1920,6 +1924,9 @@ "expo-sqlite": { "optional": true }, + "gel": { + "optional": true + }, "knex": { "optional": true }, @@ -1938,9 +1945,6 @@ "prisma": { "optional": true }, - "react": { - "optional": true - }, "sql.js": { "optional": true }, diff --git a/package.json b/package.json index 8e9afb3..ad6ee0c 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "dependencies": { "@hono/zod-validator": "^0.7.6", "@neondatabase/serverless": "^0.10.0", - "drizzle-orm": "^0.33.0", + "drizzle-orm": "^0.45.1", "hono": "^4.12.5", "zod": "^3.23.0" }, diff --git a/src/db/schema.ts b/src/db/schema.ts index 5d5dce7..78dde5f 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -40,6 +40,12 @@ export const ccObligations = pgTable('cc_obligations', { actionType: text('action_type'), actionPayload: jsonb('action_payload'), sourceDocId: uuid('source_doc_id'), + // Escalation tracking (migration 0008) + escalationType: text('escalation_type'), + escalationThresholdDays: integer('escalation_threshold_days'), + escalationAmount: numeric('escalation_amount', { precision: 8, scale: 2 }), + creditImpactScore: integer('credit_impact_score'), + preferredAccountId: uuid('preferred_account_id').references(() => ccAccounts.id), metadata: jsonb('metadata').default({}), createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(), updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow(), @@ -182,6 +188,13 @@ export const ccRecommendations = pgTable('cc_recommendations', { status: text('status').default('active'), expiresAt: timestamp('expires_at', { withTimezone: true }), modelVersion: text('model_version'), + // Planner-aware fields (migration 0008) + confidence: numeric('confidence', { precision: 3, scale: 2 }), + suggestedAccountId: uuid('suggested_account_id').references(() => ccAccounts.id), + suggestedAmount: numeric('suggested_amount', { precision: 12, scale: 2 }), + paymentSequence: integer('payment_sequence'), + escalationRisk: text('escalation_risk'), + scenarioImpact: jsonb('scenario_impact'), createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(), actedOnAt: timestamp('acted_on_at', { withTimezone: true }), }, (table) => ({ @@ -351,3 +364,32 @@ export const ccScrapeJobs = pgTable('cc_scrape_jobs', { typeIdx: index('idx_cc_scrape_jobs_type').on(table.jobType), chittyIdx: index('idx_cc_scrape_jobs_chitty').on(table.chittyId), })); + +// ── Email Connections (migration 0009) ────────────────────── +export const ccEmailConnections = pgTable('cc_email_connections', { + id: uuid('id').primaryKey().defaultRandom(), + userId: text('user_id').notNull(), + provider: text('provider').notNull(), + emailAddress: text('email_address').notNull(), + displayName: text('display_name'), + connectRef: text('connect_ref'), + namespace: text('namespace'), + status: text('status').default('pending'), + lastSyncedAt: timestamp('last_synced_at', { withTimezone: true }), + errorMessage: text('error_message'), + config: jsonb('config').default({}), + createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(), + updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow(), +}, (table) => ({ + emailUserIdx: index('idx_cc_email_conn_email_user').on(table.emailAddress, table.userId), + userIdx: index('idx_cc_email_conn_user').on(table.userId), + namespaceIdx: index('idx_cc_email_conn_namespace').on(table.namespace), +})); + +// ── User Namespaces (migration 0009) ──────────────────────── +export const ccUserNamespaces = pgTable('cc_user_namespaces', { + id: uuid('id').primaryKey().defaultRandom(), + userId: text('user_id').notNull().unique(), + namespace: text('namespace').notNull().unique(), + createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(), +});