diff --git a/.env.example b/.env.example index be7efe7..90b1459 100644 --- a/.env.example +++ b/.env.example @@ -12,7 +12,7 @@ SITE_URL=http://localhost:3000 SEED_ADMIN_PASSWORD= # LLM API keys. Each live model id picks its API provider by prefix: claude-* -> -# Anthropic, gpt-* / o-numbered / chatgpt-* -> OpenAI. With MOCK_MODE=false every +# Anthropic, gpt-* / o-numbered / chatgpt-* -> OpenAI. With live mode every # configured model must use an API-backed provider with its key set. ANTHROPIC_API_KEY= OPENAI_API_KEY= @@ -37,9 +37,11 @@ PIPELINE_MODEL_BRIEF_ANGLE= # Admin topic-discovery fit labels only; not a content-run blocker. Same # small-model default as the brief angles TOPIC_RELEVANCE_MODEL= +# Brand-guide extraction. Blank: the generate model, so a workspace that writes +# with an OpenAI model is not asked for an Anthropic key BRAND_VOICE_EXTRACT_MODEL= # Drafts onboarding steps (audiences, positioning, evidence bank); falls back to -# BRAND_VOICE_EXTRACT_MODEL before the platform default +# BRAND_VOICE_EXTRACT_MODEL, then to the generate model SETUP_ASSIST_MODEL= # Ahrefs API key for keyword/SERP research @@ -57,7 +59,10 @@ TARGET_DOMAIN=example.com # These are also .env.example placeholders and are treated as unset. COMPETITOR_DOMAINS=competitor-a.com,competitor-b.com -# When true, pipeline stages return canned responses instead of calling paid APIs +# true/1/yes: canned responses, no paid API calls. false/0/no: live. Unset or +# empty: live only when ANTHROPIC_API_KEY or OPENAI_API_KEY is set, else mock. +# Any other value runs mock and shows up as a problem in the admin. Nothing +# throws at start-up; live runs are refused until each model's key is set. MOCK_MODE=true # --- Information-gain policy ------------------------------------------------- diff --git a/README.md b/README.md index d7ac9e4..78e8499 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Everything that decides how Datum writes sits in the admin nav's **Setup** and * - **Setup checklist** (`/admin/ops/setup`) — seven steps, and `/admin` keeps showing it until the four required ones are done and the workspace holds at least one piece. Four are required, and a content run refuses to start without them: a workspace with a target domain (`/admin/ops/setup/workspace`), an active brand voice, at least one active audience (`/admin/ops/setup/audiences`), and at least one template (`/admin/ops/templates`). Three are recommended: your positioning (`/admin/ops/setup/positioning`) and an evidence bank (`/admin/ops/setup/evidence`) change what a draft may claim, and **Models** (below) picks which model runs each stage. The workspace, audience and positioning steps each have **Draft with AI** and **Refine with AI**, and the evidence bank offers the assistant on two of its three tabs; every reply drafts one section of one asset, so you read it before accepting it. They work from your own site: **Fetch site pages** reads your home page and up to seven marketing pages linked from it. **Start with the demo workspace** fills every required and recommended step but Templates and Models with the Kettle & Burr home-espresso demo in one click. See [`docs/tenant-context.md`](docs/tenant-context.md). - **Brand voice** (`/admin/ops/setup/brand-voice`) — a workspace-wide voice every generated title, description, FAQ, and body follows, layered on top of `docs/style-guide.md`. Set it up with a nine-step onboarding stepper or by uploading an existing brand guide (`.md`/`.txt`/`.pdf`/`.docx`) for one-call extraction into a draft you review before activating. An active voice is required for content runs. Seed a demo voice with `npm run seed -- --with-brand-voice`. -- **Models** (`/admin/globals/llm-settings`) — eleven choices: one for each of the eight pipeline stages that call a model (generate, fact check, qualitative review, claim extraction, information-gain judge, evidence verification, evidence check, brief angles), plus brand-voice extraction, the setup assistant, and admin topic relevance. Pick a model here, or leave it blank to fall back to the matching `PIPELINE_MODEL_*` / `BRAND_VOICE_EXTRACT_MODEL` / `SETUP_ASSIST_MODEL` env var, or to `claude-opus-5` if neither is set. Brief angles and topic relevance are the exception: unset, they use the small model of the generate model's provider (`claude-haiku-4-5`, or `gpt-5.4-mini` when generate is a `gpt-*` model). Each live model needs its provider's API key (`ANTHROPIC_API_KEY` for `claude-*`, `OPENAI_API_KEY` for `gpt-*`, `o`-numbered and `chatgpt-*` models) wherever that call runs; see the env var split below. +- **Models** (`/admin/globals/llm-settings`) — eleven choices: one for each of the eight pipeline stages that call a model (generate, fact check, qualitative review, claim extraction, information-gain judge, evidence verification, evidence check, brief angles), plus brand-voice extraction, the setup assistant, and admin topic relevance. Pick a model here, or leave it blank to fall back to the matching `PIPELINE_MODEL_*` / `BRAND_VOICE_EXTRACT_MODEL` / `SETUP_ASSIST_MODEL` env var, or to `claude-opus-5` if neither is set. Brief angles and topic relevance are the exception: unset, they use the small model of the generate model's provider (`claude-haiku-4-5`, or `gpt-5.4-mini` when generate is a `gpt-*` model). Brand-voice extraction and the setup assistant, unset, use the generate model itself. Each live model needs its provider's API key (`ANTHROPIC_API_KEY` for `claude-*`, `OPENAI_API_KEY` for `gpt-*`, `o`-numbered and `chatgpt-*` models) wherever that call runs; see the env var split below. - **Sources** (`/admin/collections/evidence-sources`) and **Source review** (`/admin/ops/governance/source-review`) — Sources holds the domain rules you have already rated and is what scoring reads. Source review is the queue behind it: the domains the pipeline cited or saw ranking that nobody has rated yet. An unrated domain can't back a claim nobody else is making, so an article resting on one gets blocked; rate the ones you trust and the next run counts them. See [`docs/information-gain.md`](docs/information-gain.md). - **Scoring policy** (`/admin/globals/information-gain-policy`) — the thresholds that decide whether a scored draft passes, needs revision, needs your call, or is blocked. Every run stamps the policy version onto the score it writes. See [`docs/information-gain.md`](docs/information-gain.md). Delivery settings sit apart from all of that, because no run reads them: **Webhooks** (`/admin/globals/webhook-settings`) sends a signed `article.status_changed` POST on every status transition, falling back to `WEBHOOK_URL` and `WEBHOOK_SECRET`. Nothing is sent until both a URL and a secret resolve. See [`docs/operations.md`](docs/operations.md). @@ -94,7 +94,7 @@ The seed creates this account for local development. Change its password before ### Pipeline mock mode -Mock mode needs no API keys. Set `MOCK_MODE=true`, as shown in `.env.example`, and Datum uses fixtures instead of calling Ahrefs or Anthropic. +Mock mode needs no API keys. Set `MOCK_MODE=true`, as shown in `.env.example`, and Datum uses fixtures instead of calling Ahrefs or Anthropic. `pipeline:run` obeys the same setup gate as the admin, so a fresh database needs a workspace first: `npm run seed -- --with-brand-voice` writes the demo one. ```bash npm run pipeline:fetch -- --template Listicle --count 3 @@ -106,7 +106,7 @@ npm run pipeline:report -- --period week `/admin` opens on the setup checklist and keeps showing it until the four required steps are done and the workspace holds at least one piece; the three recommended steps never block it. If you would rather look around first, **Start with the demo workspace** fills every required and recommended step but Templates and Models from the Kettle & Burr home-espresso fixtures in one click; it only ever fills what is still blank, so pressing it twice is safe. Templates are seeded. Missing live-provider keys show as a banner for whoever deploys — they never block an editor. -Then **New content** (`/admin/ops/new`) shows the same blockers as a notice if anything required is still missing; otherwise pick the kind of piece (a template card), say what it is about — suggested topics from Ahrefs, or a keyword you already know — and create it. Research starts on its own; the piece opens; when research is done a **brief** appears with the angle, audience and sections. Edit it, approve it, and Datum writes the draft, runs the checks and scores it. **Content** (`/admin/ops/content`) is the one list: every piece on a five-step stepper (Research → Brief → Writing → Review → Publish), who it is waiting on, and the one thing to do next. A stalled piece — waiting on a person rather than a run — carries a **Run next stage** button on its own page and a **Run** button on the board; select several and **Run selected** advances them together. Each of those queues the article as a `pipeline-runs` row, executed as a native Payload `content-run` task, so `npm run jobs:run --workspace cms` (or dev's in-process worker) is what actually processes it; a bar at the bottom of every admin page shows what the model is doing while a run is in flight. `pipeline:run` reaches the same stages directly from the CLI, outside that queue, and is no longer the only way to move a stalled piece forward. Live mode asks for a paid-provider confirmation before the expensive half starts. +Then **New content** (`/admin/ops/new`) shows the same blockers as a notice if anything required is still missing; otherwise pick the kind of piece (a template card), say what it is about — suggested topics from Ahrefs, or a keyword you already know — and create it. Research starts on its own; the piece opens; when research is done a **brief** appears with the angle, audience and sections. Edit it, approve it, and Datum writes the draft, runs the checks and scores it. **Content** (`/admin/ops/content`) is the one list: every piece on a five-step stepper (Research → Brief → Writing → Review → Publish), who it is waiting on, and the one thing to do next. A stalled piece — waiting on a person rather than a run — carries a **Run next stage** button on its own page and a **Run** button on the board; select several and **Run selected** advances them together. Each of those queues the article as a `pipeline-runs` row, executed as a native Payload `content-run` task, so `npm run jobs:run --workspace cms` (or dev's in-process worker) is what actually processes it; a bar at the bottom of every admin page shows what the model is doing while a run is in flight. `pipeline:run` reaches the same stages directly from the CLI, outside that queue, and is no longer the only way to move a stalled piece forward; it registers itself as a `cli` run under the same lock, so it refuses while another run is active, and admin and selected runs refuse the articles it is carrying until it finishes. Live mode asks for a paid-provider confirmation before the expensive half starts. Local development runs all three job queues in process: `content` and `webhooks` every two seconds, `scheduled` every ten. Production intentionally disables in-process autorun, so a durable worker or scheduler has to invoke each one: @@ -116,9 +116,9 @@ npm run jobs:webhooks --workspace cms # webhook deliveries npm run jobs:scheduled --workspace cms # due publishes, daily suggestion scan ``` -Each invocation of the first command processes one queued content run; schedule it repeatedly for continuous processing. Run the other two every minute or faster. Use these scripts, not a bare `payload jobs:run`: the Payload CLI does not set `NODE_ENV`, and without `NODE_ENV=production` it runs the development schema push against your database on every invocation. The scripts turn that push off. [`docs/operations.md`](docs/operations.md) has the cadence, the delivery contract and the fixed limits. +Each invocation of the first command processes one queued content run; schedule it repeatedly for continuous processing. Run the other two every minute or faster: the `scheduled` queue also runs `recover-stale-runs`, which fails a run whose worker stopped sending heartbeats for 15 minutes and frees the content queue behind it. Use these scripts, not a bare `payload jobs:run`: the Payload CLI does not set `NODE_ENV`, and without `NODE_ENV=production` it runs the development schema push against your database on every invocation. The scripts turn that push off. [`docs/operations.md`](docs/operations.md) has the cadence, the delivery contract and the fixed limits. -For live API calls, set `MOCK_MODE=false` and provide the key for each chosen model's provider (`ANTHROPIC_API_KEY` or `OPENAI_API_KEY`). Ahrefs also needs `AHREFS_API_KEY` plus a target domain and competitors, which come from the **Workspace** setup page (`/admin/ops/setup/workspace`); `TARGET_DOMAIN` and `COMPETITOR_DOMAINS` are its fallback. See [`.env.example`](.env.example). +For live API calls, set `MOCK_MODE=false` and provide the key for each chosen model's provider (`ANTHROPIC_API_KEY` or `OPENAI_API_KEY`). The admin and the pipeline share one rule for mock versus live and never fail to start because of it: with `MOCK_MODE=false` and a missing key the admin stays up, the setup banner lists the key, and a run is refused until it is set. Admin-side model calls (brand-voice extraction, setup assistant, topic fit) follow the workspace mode and, live without that model's key, fail naming the key rather than returning demo data. Ahrefs also needs `AHREFS_API_KEY` plus a target domain and competitors, which come from the **Workspace** setup page (`/admin/ops/setup/workspace`); `TARGET_DOMAIN` and `COMPETITOR_DOMAINS` are its fallback. See [`.env.example`](.env.example). ## Environment variables @@ -136,11 +136,11 @@ Copy [`.env.example`](.env.example) and [`cms/.env.example`](cms/.env.example) | `TOPIC_RELEVANCE_MODEL` | CMS-only audience-fit labels for topic discovery; no CLI scoring or content-run key requirement. | | `TARGET_DOMAIN` | Fallback for the Workspace global's target domain. The admin field wins; a mock run falls back again to a demo domain. The `.env.example` placeholder (`example.com`) is treated as unset rather than a real domain. | | `COMPETITOR_DOMAINS` | Comma-separated fallback for the Workspace global's competitor list, same rule. The `.env.example` placeholders (`competitor-a.com`, `competitor-b.com`) are likewise treated as unset. | -| `MOCK_MODE` | `true` to use fixtures instead of paid APIs | +| `MOCK_MODE` | `true` to use fixtures instead of paid APIs, `false` for live. Unset, it is live only when `ANTHROPIC_API_KEY` or `OPENAI_API_KEY` is set. An unrecognised value runs mock and is reported as a setup problem | | `SEED_ADMIN_PASSWORD` | Password for the seeded admin user | | `PIPELINE_MODEL_GENERATE` / `_FACT_CHECK` / `_QUALITATIVE_REVIEW` / `_CLAIM_EXTRACTION` / `_INFORMATION_GAIN_JUDGE` / `_EVIDENCE_VERIFICATION` / `_EVIDENCE_CHECK` / `_BRIEF_ANGLE` | Fallback model for each of the eight pipeline stages that call a model, when the [Models](#setup-and-governance) admin field is blank | -| `BRAND_VOICE_EXTRACT_MODEL` | Fallback model for brand-guide upload extraction, same rule | -| `SETUP_ASSIST_MODEL` | Fallback model for the setup assistant. Falls back to `BRAND_VOICE_EXTRACT_MODEL` before the platform default. | +| `BRAND_VOICE_EXTRACT_MODEL` | Fallback model for brand-guide upload extraction, same rule. Unset, the generate model | +| `SETUP_ASSIST_MODEL` | Fallback model for the setup assistant. Falls back to `BRAND_VOICE_EXTRACT_MODEL`, then the generate model. | | `INFORMATION_GAIN_*` | Threshold overrides used when the Scoring policy global is blank. See [`docs/information-gain.md`](docs/information-gain.md). | | `WEBHOOK_URL` / `WEBHOOK_SECRET` | Fallback for the Webhooks global. Nothing is delivered until both resolve. See [`docs/operations.md`](docs/operations.md). | | `PAYLOAD_AUTO_LOGIN` (cms/.env only) | `true` to skip the admin login form in local dev; never honoured when `NODE_ENV=production` | @@ -165,7 +165,7 @@ For running the test suites. Set these in your shell, not in a committed `.env`. | `npm run dev` | CMS Next.js dev server | | `npm run seed` | Create or update templates, evidence-source rules, and the admin user. Add `-- --with-brand-voice` to also seed the Kettle & Burr home-espresso demo workspace: an active brand voice, the workspace profile, two audiences, a position, and an evidence bank. | | `npm run pipeline:fetch -- --template NAME_OR_ID` | Create templated articles from content-gap keywords | -| `npm run pipeline:run` | Advance every eligible article one stage set: research (stops at the brief), then generate → QA → scoring for approved briefs | +| `npm run pipeline:run` | Advance every eligible article one stage set: research (stops at the brief), then generate → QA → scoring for approved briefs. Refused until setup is finished or while another run is active | | `npm run pipeline:report` | Print the QA and spending report | | `npm run jobs:run --workspace cms` | Process one queued content run. The production content worker. | | `npm run typecheck` / `lint` / `test` | Workspace checks described in [CONTRIBUTING.md](CONTRIBUTING.md) | diff --git a/cms/.env.example b/cms/.env.example index 5ca7a04..1d7716c 100644 --- a/cms/.env.example +++ b/cms/.env.example @@ -16,7 +16,8 @@ NODE_OPTIONS="--no-deprecation --no-experimental-strip-types" # BRAND_VOICE_EXTRACT_MODEL, SETUP_ASSIST_MODEL, WEBHOOK_URL, WEBHOOK_SECRET, # SITE_URL, and the INFORMATION_GAIN_* fallbacks (admin-queued runs score in # this process; they are listed in the root .env.example). -# See the root .env.example for what each does. +# See the root .env.example for what each does. MOCK_MODE: true or false (unset +# is live only when a provider key is set; an unrecognised value runs mock). MOCK_MODE=true ANTHROPIC_API_KEY= OPENAI_API_KEY= @@ -39,8 +40,9 @@ PIPELINE_MODEL_EVIDENCE_CHECK= PIPELINE_MODEL_BRIEF_ANGLE= # Admin topic-discovery fit labels only; same small-model default TOPIC_RELEVANCE_MODEL= +# Blank: the generate model BRAND_VOICE_EXTRACT_MODEL= -# Falls back to BRAND_VOICE_EXTRACT_MODEL when blank +# Falls back to BRAND_VOICE_EXTRACT_MODEL, then the generate model, when blank SETUP_ASSIST_MODEL= # Status-event webhooks. Fallbacks for the Webhooks global (/admin/globals/webhook-settings); # nothing is delivered until both a URL and a secret resolve. See docs/operations.md. diff --git a/cms/src/collections/Articles.ts b/cms/src/collections/Articles.ts index 2c2fa6c..529f20e 100644 --- a/cms/src/collections/Articles.ts +++ b/cms/src/collections/Articles.ts @@ -13,6 +13,7 @@ import { invalidateStaleInformationGain, } from '../lib/articleReviewGate' import { stampPublication } from '../lib/articlePublication' +import { uniqueArticleSlug } from '../lib/articleSlug' /** * Shown on every field in `SCORED_CONTENT_FIELDS` that an editor can reach in @@ -27,6 +28,9 @@ const SCORED_FIELD_DESCRIPTION = export const Articles: CollectionConfig = { slug: 'articles', hooks: { + // Before validation, so the unique index only ever sees a normalised slug + // that is already free. + beforeValidate: [uniqueArticleSlug], // `gateArchivedStatus` runs first: an archived piece refuses every move, // so nothing below needs to reason about one. Then // `invalidateStaleInformationGain`, because it is a *dependency*: @@ -84,8 +88,10 @@ export const Articles: CollectionConfig = { admin: { description: SCORED_FIELD_DESCRIPTION }, }, { + // Normalised and de-duplicated by `uniqueArticleSlug`; the index makes a + // duplicate that slips past it (two concurrent writes) an error. name: 'slug', - index: true, + unique: true, type: 'text', }, { diff --git a/cms/src/collections/PipelineRuns.ts b/cms/src/collections/PipelineRuns.ts index 4c11b13..89a4dc9 100644 --- a/cms/src/collections/PipelineRuns.ts +++ b/cms/src/collections/PipelineRuns.ts @@ -25,7 +25,7 @@ export const PipelineRuns: CollectionConfig = { options: ['admin', 'cli', 'selected'], admin: { description: - 'Where the run came from. `selected` runs the articles a person ticked on the board; `admin` discovers new content-gap topics first.', + 'Where the run came from. `selected` runs the articles a person ticked on the board; `admin` discovers new content-gap topics first; `cli` is `npm run pipeline:run`, which advances every article waiting at a stage.', }, }, { @@ -36,7 +36,8 @@ export const PipelineRuns: CollectionConfig = { options: ['queued', 'running', 'succeeded', 'failed'], }, { name: 'mode', type: 'select', required: true, options: ['mock', 'live'] }, - { name: 'template', type: 'relationship', relationTo: 'templates', required: true }, + // Empty only on a `cli` run, which advances articles of every template. + { name: 'template', type: 'relationship', relationTo: 'templates' }, // `admin` runs are capped at 5 because each one buys a fresh topic. A // `selected` run buys nothing new — it advances articles that already // exist — so the ceiling is only there to stop a runaway select-all, and @@ -50,6 +51,13 @@ export const PipelineRuns: CollectionConfig = { { name: 'errorSummary', type: 'textarea' }, { name: 'requestedBy', type: 'text', required: true }, { name: 'startedAt', type: 'date' }, + { + // The run's lease (`lib/pipelineRunLease.ts`): refreshed every minute by + // whatever is executing the run. `recover-stale-runs` fails a `running` + // row whose heartbeat is more than 15 minutes old. + name: 'heartbeatAt', + type: 'date', + }, { name: 'completedAt', type: 'date' }, ], } diff --git a/cms/src/components/ops/topicDiscoveryActions.ts b/cms/src/components/ops/topicDiscoveryActions.ts index 658d7a7..cc9250e 100644 --- a/cms/src/components/ops/topicDiscoveryActions.ts +++ b/cms/src/components/ops/topicDiscoveryActions.ts @@ -3,13 +3,13 @@ import { revalidatePath } from 'next/cache' import { errorMessage } from '../../lib/errorMessage' import { requireUser } from '../../lib/requireUser' +import { runModeFromEnv } from '../../lib/runMode' import { loadTenantContextCms } from '../../lib/loadTenantContextCms' import { resolveTopicRelevanceModel } from '../../lib/llmSettings' import { scoreTopicRelevance } from '../../lib/scoreTopicRelevance' import { cachedTopicRelevance, rankByFit, relevanceFingerprint } from '../../lib/tenant/topicRelevance' import { createAhrefsClient, type DiscoveredKeyword } from '../../../../pipeline/src/ahrefs' -import { config as pipelineConfig } from '../../../../pipeline/src/config' import { ActivePipelineRunError } from '../../lib/createPipelineRun' import { loadWorkspaceSetup } from '../../lib/loadWorkspaceReadiness' import { gateRunReadiness, queueRunForArticles } from '../../lib/queueRunForArticles' @@ -80,9 +80,9 @@ export async function discoverTopicsAction( ? cachedCandidates(cachedRow.candidates) : null - // Discovery has no pipeline-runs row to carry a mode, so the ambient config - // decides — the same signal the run bar shows the operator. - const mode = pipelineConfig.mockMode ? 'mock' : 'live' + // Discovery has no pipeline-runs row to carry a mode, so the environment + // decides, by the one shared rule — the same signal the run bar shows. + const mode = runModeFromEnv(process.env) const tenant = await loadTenantContextCms(payload, mode) const candidates = usableCache ?? diff --git a/cms/src/globals/LlmSettings.ts b/cms/src/globals/LlmSettings.ts index 1da3846..b5d6d8c 100644 --- a/cms/src/globals/LlmSettings.ts +++ b/cms/src/globals/LlmSettings.ts @@ -104,6 +104,7 @@ export const LlmSettings: GlobalConfig = { 'Brand voice extraction', EXTRACTION_ENV_VAR, 'Turns an uploaded brand guide into a brand voice draft.', + 'the generate model (Claude Opus 5 unless you changed it)', ), modelField( 'setupAssistModel', diff --git a/cms/src/jobs/contentRun.ts b/cms/src/jobs/contentRun.ts index 0a3674b..a3ec3c8 100644 --- a/cms/src/jobs/contentRun.ts +++ b/cms/src/jobs/contentRun.ts @@ -3,6 +3,15 @@ import type { Payload, TaskConfig } from 'payload' import { fetchTopics } from '../../../pipeline/src/fetchTopics' import { buildStageContext, loadStageInputs } from '../../../pipeline/src/runContext' import { runPipeline } from '../../../pipeline/src/stages' +import { + RUN_HEARTBEAT_INTERVAL_MS, + type RunHeartbeat, + RunLeaseLostError, + safeRunError, + settledRunData, + startRunHeartbeat, + updateRunIfStatus, +} from '../lib/pipelineRunLease' import type { PipelineRun } from '../payload-types' type ContentRunTask = { @@ -10,26 +19,44 @@ type ContentRunTask = { output: { articleIds: number[]; finalStatuses: Record } } -function safeError(error: unknown): string { - let message = error instanceof Error ? error.message : 'Content run failed' - for (const name of ['ANTHROPIC_API_KEY', 'OPENAI_API_KEY', 'AHREFS_API_KEY', 'PAYLOAD_SECRET']) { - const secret = process.env[name] - if (secret) message = message.replaceAll(secret, '[redacted]') - } - return message.replace(/(sk-|api[_-]?key[=: ]+)[^\s,;]+/gi, '$1[redacted]').slice(0, 500) +export interface ExecuteContentRunOptions { + /** How often the lease is refreshed; tests shorten it. */ + heartbeatIntervalMs?: number } -async function executeContentRun(payload: Payload, run: PipelineRun) { - const startedAt = new Date().toISOString() - await payload.update({ - collection: 'pipeline-runs', - id: run.id, - overrideAccess: true, - data: { status: 'running', startedAt, errorSummary: null }, - }) +export async function executeContentRun( + payload: Payload, + run: PipelineRun, + { heartbeatIntervalMs = RUN_HEARTBEAT_INTERVAL_MS }: ExecuteContentRunOptions = {}, +) { + let heartbeat: RunHeartbeat | null = null + // Whether this handler moved the row to `running`. Before that the row is + // still `queued` (or someone else's), and the catch below must settle it as + // such: the job has no retries, so a queued row left behind blocks every + // later run until someone deletes it. + let claimed = false + // Every write below is fenced on the status the run expects to find, so a + // run that recovery failed under this worker is never written back over. + const writeRunning = async (data: Partial) => { + if (!(await updateRunIfStatus(payload, run.id, 'running', data))) { + throw new RunLeaseLostError(run.runId) + } + } try { - const templateId = typeof run.template === 'object' ? run.template.id : run.template + const startedAt = new Date().toISOString() + // The claim: only a queued row becomes running. A row recovery already + // failed stays failed, and the job ends without touching it. + claimed = await updateRunIfStatus(payload, run.id, 'queued', { + status: 'running', + startedAt, + heartbeatAt: startedAt, + errorSummary: null, + }) + if (!claimed) throw new RunLeaseLostError(run.runId) + heartbeat = startRunHeartbeat(payload, run, heartbeatIntervalMs) + + const templateId = typeof run.template === 'object' ? run.template?.id : run.template let articleIds: number[] const inputs = await loadStageInputs(payload, run.mode) const { tenant, brandVoice } = inputs @@ -39,7 +66,12 @@ async function executeContentRun(payload: Payload, run: PipelineRun) { 'Finish setup: brand voice, target domain, and at least one active audience (ICP) are required.', ) } - const stageContext = buildStageContext(payload, run.runId, run.mode, inputs) + // The signal reaches discovery and every model call, so a recovered run + // stops between steps rather than at its next article write. + const stageContext = { + ...buildStageContext(payload, run.runId, run.mode, inputs), + signal: heartbeat.signal, + } if (run.source === 'selected') { // The articles were chosen by a person and attached when the run was @@ -52,10 +84,13 @@ async function executeContentRun(payload: Payload, run: PipelineRun) { throw new Error('This run has no articles attached.') } } else { + if (templateId == null) throw new Error('This run has no template to discover topics for.') + heartbeat.signal.throwIfAborted() const fetched = await fetchTopics(stageContext, { count: run.requestedCount, templateId, icpId: (tenant.icps.find((icp) => icp.primary)?.id as number | undefined) ?? null, + commitArticle: heartbeat.commit, }) articleIds = fetched.createdIds if (articleIds.length === 0) { @@ -63,54 +98,32 @@ async function executeContentRun(payload: Payload, run: PipelineRun) { } } - await payload.update({ - collection: 'pipeline-runs', - id: run.id, - overrideAccess: true, - data: { articles: articleIds }, - }) + await writeRunning({ articles: articleIds }) - const result = await runPipeline(stageContext, { articleIds }) - const completedAt = new Date().toISOString() - // A run that advanced nothing is not a success, whatever the job queue - // thinks. `runPipeline` deliberately swallows a single article's failure so - // the rest of the batch survives, which means the only signal that anything - // went wrong is `result.failed` — and reporting `succeeded` regardless left - // an operator staring at a card that had not moved with nowhere to look. - const advanced = Object.values(result.finalStatuses).reduce((sum, n) => sum + n, 0) - const status = advanced === 0 && result.failed > 0 ? 'failed' : 'succeeded' - await payload.update({ - collection: 'pipeline-runs', - id: run.id, - overrideAccess: true, - data: { - status, - articles: articleIds, - finalStatuses: result.finalStatuses, - warnings: result.failures.length > 0 ? result.failures : null, - errorSummary: - result.failures.length > 0 - ? result.failures - .map((f) => `${f.stage}: "${f.keyword}" — ${safeError(new Error(f.message))}`) - .join('\n\n') - : null, - completedAt, - }, + const result = await runPipeline(stageContext, { + articleIds, + signal: heartbeat.signal, + commitArticle: heartbeat.commit, }) + await writeRunning({ ...settledRunData(result), articles: articleIds }) return result } catch (error) { - const errorSummary = safeError(error) - await payload.update({ - collection: 'pipeline-runs', - id: run.id, - overrideAccess: true, - data: { + const errorSummary = safeRunError(error) + // Fenced too: a lost lease means the row already says what happened, and + // before the claim only a row still `queued` is ours to fail — never a + // row another handler is running. + if (!(error instanceof RunLeaseLostError)) { + await updateRunIfStatus(payload, run.id, claimed ? 'running' : 'queued', { status: 'failed', errorSummary, completedAt: new Date().toISOString(), - }, - }) + }).catch((settleError) => { + payload.logger.error(`could not mark run ${run.runId} failed: ${safeRunError(settleError)}`) + }) + } throw new Error(errorSummary) + } finally { + heartbeat?.stop() } } diff --git a/cms/src/jobs/recoverStaleRuns.ts b/cms/src/jobs/recoverStaleRuns.ts new file mode 100644 index 0000000..4686394 --- /dev/null +++ b/cms/src/jobs/recoverStaleRuns.ts @@ -0,0 +1,33 @@ +import type { TaskConfig } from 'payload' + +import { recoverStaleRuns } from '../lib/pipelineRunLease' + +type RecoverStaleRunsTask = { + input: object + output: { recoveredRuns: string[]; failedJobs: Array } +} + +/** + * Fails pipeline runs whose worker (or CLI) stopped refreshing its heartbeat, + * and frees the `content-pipeline` concurrency key the dead worker's job still + * holds. Without it, one killed process left a `running` row that refused every + * later admin run and its articles forever, and a `processing` job that every + * later content run queued behind. See `lib/pipelineRunLease.ts`. + * + * On the `scheduled` queue beside `publish-due`, not on `content`: the job it + * exists to release is the one blocking that queue. + */ +export const RecoverStaleRunsTask: TaskConfig = { + slug: 'recover-stale-runs', + label: 'Recover stale pipeline runs', + retries: 0, + schedule: [{ cron: '0 */5 * * * *', queue: 'scheduled' }], + inputSchema: [], + outputSchema: [ + { name: 'recoveredRuns', type: 'json', required: true }, + { name: 'failedJobs', type: 'json', required: true }, + ], + async handler({ req }) { + return { output: await recoverStaleRuns(req.payload) } + }, +} diff --git a/cms/src/lib/articleSlug.ts b/cms/src/lib/articleSlug.ts new file mode 100644 index 0000000..a8d9f1e --- /dev/null +++ b/cms/src/lib/articleSlug.ts @@ -0,0 +1,90 @@ +import type { CollectionBeforeValidateHook, PayloadRequest } from 'payload' + +/** Long enough for any honest title, short enough for a readable URL. */ +export const MAX_SLUG_LENGTH = 80 + +/** + * Lower case, `a-z0-9` words joined by single hyphens, no hyphen at either + * end, at most `MAX_SLUG_LENGTH` characters. Accents fold to their base letter + * (`café` → `cafe`); anything else outside `a-z0-9` becomes a separator. The + * result is empty when nothing usable is left. + */ +export function normaliseSlug(value: string): string { + return value + .normalize('NFKD') + .replace(/[̀-ͯ]/g, '') + .toLowerCase() + .replace(/[^a-z0-9]+/g, '-') + .replace(/^-+|-+$/g, '') + .slice(0, MAX_SLUG_LENGTH) + .replace(/-+$/, '') +} + +/** `base` with `-n` appended, trimmed so the whole still fits. */ +function withSuffix(base: string, n: number): string { + const suffix = `-${n}` + return `${base.slice(0, MAX_SLUG_LENGTH - suffix.length).replace(/-+$/, '')}${suffix}` +} + +const BATCH = 25 + +/** + * The first of `base`, `base-2`, `base-3`, … that no other article holds. + * A purely numeric slug starts at `-2`: `/articles/` is also the id + * fallback route, and a slug that reads as an id would shadow one. + */ +async function firstFreeSlug( + req: PayloadRequest, + base: string, + ownId: number | string | undefined, +): Promise { + const numeric = /^\d+$/.test(base) + for (let start = numeric ? 2 : 1; ; start += BATCH) { + const candidates = Array.from({ length: BATCH }, (_, i) => + start + i === 1 ? base : withSuffix(base, start + i), + ) + const { docs } = await req.payload.find({ + collection: 'articles', + where: { + and: [ + { slug: { in: candidates } }, + ...(ownId != null ? [{ id: { not_equals: ownId } }] : []), + ], + }, + select: { slug: true }, + pagination: false, + limit: 0, + depth: 0, + overrideAccess: true, + req, + }) + const taken = new Set(docs.map((doc) => doc.slug)) + const free = candidates.find((candidate) => !taken.has(candidate)) + if (free) return free + } +} + +/** + * Normalise a slug that is being set or changed, and suffix it when another + * article already has it. + * + * Slugs come from the model, which happily gives two articles the same one; + * the public route resolves a slug to one published article, so the other + * would be unreachable and its canonical would point at its twin. An unchanged + * slug is left alone, so an unrelated save never renames a live URL. Archived + * articles still count as taken: the column is unique across every row. + * + * Two concurrent writes can still pick the same free slug; the unique index + * turns that into an error rather than a silent duplicate. + */ +export const uniqueArticleSlug: CollectionBeforeValidateHook = async ({ + data, + originalDoc, + req, +}) => { + if (!data || typeof data.slug !== 'string') return data + if (originalDoc && data.slug === originalDoc.slug) return data + const base = normaliseSlug(data.slug) + data.slug = base ? await firstFreeSlug(req, base, originalDoc?.id) : null + return data +} diff --git a/cms/src/lib/brandVoiceExtract.ts b/cms/src/lib/brandVoiceExtract.ts index 83d45b0..a01c982 100644 --- a/cms/src/lib/brandVoiceExtract.ts +++ b/cms/src/lib/brandVoiceExtract.ts @@ -34,7 +34,7 @@ export function extractionModel( return resolveExtractionModel(settings, env).model } -/** The shared CMS rule (`cmsMockMode`), defaulted to the extraction model. */ +/** The shared CMS rule (`cmsMockMode`): the workspace's mode; `model` is accepted for compatibility and ignored. */ export function extractionMockMode( env: Record = process.env, model: string = extractionModel(env), diff --git a/cms/src/lib/cmsLlm.ts b/cms/src/lib/cmsLlm.ts index f32b734..2ce8f67 100644 --- a/cms/src/lib/cmsLlm.ts +++ b/cms/src/lib/cmsLlm.ts @@ -11,8 +11,14 @@ import OpenAI from 'openai' import type { Payload } from 'payload' import type { CostLog } from '../payload-types' -import { apiKeyForModel, type LlmProvider, providerForModel } from './llmProvider' +import { + apiKeyForModel, + type LlmProvider, + PROVIDER_ENV_VAR_NAME, + providerForModel, +} from './llmProvider' import { costUsd } from './pricing' +import { runModeFromEnv } from './runMode' export interface CmsLlmRequest { system: string @@ -54,29 +60,18 @@ export class CmsLlmError extends Error { const DEFAULT_MAX_TOKENS = 8000 -function parseBool(value: string | undefined): boolean | undefined { - if (value === undefined || value === '') return undefined - if (['true', '1', 'yes'].includes(value.toLowerCase())) return true - if (['false', '0', 'no'].includes(value.toLowerCase())) return false - return undefined -} - /** - * Same rule as `pipeline/src/config.ts`: `MOCK_MODE` wins when set, otherwise - * mock whenever the model's API key is absent. Never throws — the admin flow - * must work in a keyless dev environment. + * The workspace's mock/live mode (`runMode.ts`, the rule the pipeline and + * readiness use). It is the workspace's, not the model's: in live mode a model + * whose provider key is missing fails in `completeJsonCms` naming the key, + * instead of quietly returning a fixture while the rest of the workspace is + * live. `_model` is kept so existing call sites keep compiling. */ export function cmsMockMode( env: Record = process.env, - model: string, + _model?: string, ): boolean { - const explicit = parseBool(env.MOCK_MODE) - if (explicit !== undefined) return explicit - // Only the model's own key flips this workspace live, and only for the model - // that carries it. `pipeline/src/config.ts` and `modeFromEnv` make the same - // call; if this one differed, an upload would bill a provider while the rest - // of the workspace still reported mock. - return apiKeyForModel(model, env) === undefined + return runModeFromEnv(env) === 'mock' } function parseJsonReply(text: string): unknown { @@ -107,7 +102,7 @@ export async function completeJsonCms( const { model, system, user } = request const label = request.label ?? 'Model call' const maxTokens = request.maxTokens ?? DEFAULT_MAX_TOKENS - if (cmsMockMode(env, model)) { + if (cmsMockMode(env)) { throw new Error(`${label} was attempted in mock mode; callers must supply their own fixture`) } @@ -115,9 +110,17 @@ export async function completeJsonCms( if (provider === 'unknown') { throw new Error(`${label} cannot run: "${model}" is not an Anthropic or OpenAI model id`) } + // Live mode, but this model's provider has no key: say which one rather than + // letting the SDK fail on an undefined credential. + if (apiKeyForModel(model, env) === undefined) { + throw new Error( + `${label} cannot run: "${model}" needs ${PROVIDER_ENV_VAR_NAME[provider]} set (the workspace is in live mode; set MOCK_MODE=true for demo data)`, + ) + } let text: string | undefined let stopReason: string + let cutOff = false let usage: { inputTokens: number; outputTokens: number } if (provider === 'openai') { const client = new OpenAI({ apiKey: env.OPENAI_API_KEY }) @@ -130,6 +133,7 @@ export async function completeJsonCms( }) text = response.output_text || undefined stopReason = response.incomplete_details?.reason ?? response.status ?? 'unknown' + cutOff = response.status === 'incomplete' usage = { inputTokens: response.usage?.input_tokens ?? 0, outputTokens: response.usage?.output_tokens ?? 0, @@ -146,6 +150,8 @@ export async function completeJsonCms( .filter((block): block is Anthropic.TextBlock => block.type === 'text') .at(-1)?.text stopReason = response.stop_reason ?? 'unknown' + // Anything but a normal finish (a token cap, a refusal) is named in the error. + cutOff = response.stop_reason !== 'end_turn' && response.stop_reason != null usage = { inputTokens: response.usage.input_tokens, outputTokens: response.usage.output_tokens, @@ -160,7 +166,13 @@ export async function completeJsonCms( try { json = parseJsonReply(text) } catch { - throw new CmsLlmError(`${label} reply was not valid JSON: ${text.trim().slice(0, 200)}`, billed) + // A reply cut off at the token cap is not malformed, it is unfinished: + // name the cap so nobody goes looking for a prompt bug. + const why = cutOff ? ` (did not finish normally; stop_reason: ${stopReason})` : '' + throw new CmsLlmError( + `${label} reply was not valid JSON${why}: ${text.trim().slice(0, 200)}`, + billed, + ) } return { json, text, ...billed } } diff --git a/cms/src/lib/createPipelineRun.ts b/cms/src/lib/createPipelineRun.ts index 3baaacd..776ffa2 100644 --- a/cms/src/lib/createPipelineRun.ts +++ b/cms/src/lib/createPipelineRun.ts @@ -2,6 +2,8 @@ import { sql } from '@payloadcms/db-postgres' import { createLocalReq, type Payload, type TypedUser } from 'payload' import { activeRunIdForArticles } from './activeRuns' +import type { PipelineRun } from '../payload-types' + import type { WorkspaceReadiness } from './workspaceReadiness' export interface CreatePipelineRunInput { @@ -40,12 +42,17 @@ export class ArticleInActiveRunError extends ActivePipelineRunError { } } -/** Atomically create the run record and its Payload job. */ -export async function createPipelineRun( +type LockedRequest = Awaited> + +/** + * Run `fn` inside the run-creation transaction, holding the advisory lock that + * serialises every launch decision — the CMS's and the CLI's. + */ +async function withRunCreationLock( payload: Payload, - user: TypedUser, - input: CreatePipelineRunInput, -): Promise { + user: TypedUser | null, + fn: (req: LockedRequest) => Promise, +): Promise { // The advisory lock serializes launch decisions. READ COMMITTED gives a // waiter a fresh snapshot after acquiring it; SERIALIZABLE would retain the // snapshot from before the wait and reject valid queued selected runs. @@ -54,7 +61,7 @@ export async function createPipelineRun( throw new Error('The database could not start a content-run transaction.') try { - const req = await createLocalReq({ req: { transactionID }, user }, payload) + const req = await createLocalReq({ req: { transactionID }, user: user ?? undefined }, payload) const transaction = ( payload.db as typeof payload.db & { sessions: Record Promise } }> @@ -65,7 +72,71 @@ export async function createPipelineRun( // Serialize the predicate check and insert. This transaction-scoped lock is // automatically released on commit or rollback, including process errors. await transaction.execute(sql`SELECT pg_advisory_xact_lock(424242, 434343)`) + const value = await fn(req) + await payload.db.commitTransaction(transactionID) + return value + } catch (error) { + await payload.db.rollbackTransaction(transactionID) + throw error + } +} + +/** The active run, if any: queued or running. Read under the creation lock. */ +async function findActiveRun(payload: Payload, req: LockedRequest) { + const active = await payload.find({ + collection: 'pipeline-runs', + where: { status: { in: ['queued', 'running'] } }, + limit: 1, + depth: 0, + overrideAccess: true, + req, + }) + return active.docs[0] ?? null +} +/** What a run row records about the workspace it wrote for. */ +function configSnapshotOf(readiness: WorkspaceReadiness, templateId: number | null) { + return { + mode: readiness.mode, + requiredEnvironment: readiness.runtime.missing, + activeVoiceId: readiness.governance.activeVoiceId, + templateId, + // The workspace this run wrote for. Kept on the row because the + // audience and the target domain decide what every prompt said, and + // an article's output stops being explainable the moment they change. + tenant: { + targetDomain: readiness.tenant.profile.targetDomain, + competitorCount: readiness.tenant.profile.competitorCount, + icpId: readiness.tenant.icps.primaryId, + icpCount: readiness.tenant.icps.count, + positioning: readiness.tenant.positioning.status, + // The counts, not the claims: a snapshot that carried the bank's + // text would grow without bound and duplicate the audit trail. The + // counts are enough to explain why a draft could or could not state + // a first-party fact when this run wrote it. + evidenceBank: readiness.tenant.evidenceBank, + }, + models: readiness.content.models.map( + ({ stage, model, source, provider, requirement, envVar, configured }) => ({ + stage, + model, + source, + provider, + requirement, + envVar, + configured, + }), + ), + } +} + +/** Atomically create the run record and its Payload job. */ +export async function createPipelineRun( + payload: Payload, + user: TypedUser, + input: CreatePipelineRunInput, +): Promise { + await withRunCreationLock(payload, user, async (req) => { // Recheck overlap under the creation lock using this transaction. An // earlier UI/queue check can race another request that has not committed. if (input.articleIds?.length) { @@ -73,22 +144,15 @@ export async function createPipelineRun( if (activeRunId) throw new ArticleInActiveRunError(activeRunId, input.articleIds.length) } - const active = await payload.find({ - collection: 'pipeline-runs', - where: { status: { in: ['queued', 'running'] } }, - limit: 1, - depth: 0, - overrideAccess: true, - req, - }) + const active = await findActiveRun(payload, req) // Runs started by creating a piece or approving a brief are implicit — // nobody is watching a button — so two in a row must queue, not fail. The // job task already serialises on the `content-pipeline` concurrency key, // so queued runs execute one at a time. A discovery run keeps the // one-at-a-time rule too: it creates articles, and two at once would // double-buy topics. - if (active.docs[0] && input.source !== 'selected') { - throw new ActivePipelineRunError(active.docs[0].runId) + if (active && input.source !== 'selected') { + throw new ActivePipelineRunError(active.runId) } const requestedCount = @@ -108,38 +172,7 @@ export async function createPipelineRun( requestedCount, ...(input.articleIds?.length ? { articles: input.articleIds } : {}), configFingerprint: input.readiness.configFingerprint, - configSnapshot: { - mode: input.readiness.mode, - requiredEnvironment: input.readiness.runtime.missing, - activeVoiceId: input.readiness.governance.activeVoiceId, - templateId: input.templateId, - // The workspace this run wrote for. Kept on the row because the - // audience and the target domain decide what every prompt said, and - // an article's output stops being explainable the moment they change. - tenant: { - targetDomain: input.readiness.tenant.profile.targetDomain, - competitorCount: input.readiness.tenant.profile.competitorCount, - icpId: input.readiness.tenant.icps.primaryId, - icpCount: input.readiness.tenant.icps.count, - positioning: input.readiness.tenant.positioning.status, - // The counts, not the claims: a snapshot that carried the bank's - // text would grow without bound and duplicate the audit trail. The - // counts are enough to explain why a draft could or could not state - // a first-party fact when this run wrote it. - evidenceBank: input.readiness.tenant.evidenceBank, - }, - models: input.readiness.content.models.map( - ({ stage, model, source, provider, requirement, envVar, configured }) => ({ - stage, - model, - source, - provider, - requirement, - envVar, - configured, - }), - ), - }, + configSnapshot: configSnapshotOf(input.readiness, input.templateId), requestedBy: input.requestedBy, }, }) @@ -150,9 +183,54 @@ export async function createPipelineRun( overrideAccess: true, req, }) - await payload.db.commitTransaction(transactionID) - } catch (error) { - await payload.db.rollbackTransaction(transactionID) - throw error - } + }) +} + +export interface CreateCliRunInput { + runId: string + mode: 'mock' | 'live' + readiness: WorkspaceReadiness + /** Every article the CLI will advance, so other runs refuse them. */ + articleIds: number[] + requestedBy: string +} + +/** + * Register a `pipeline run` CLI invocation as a `running` run. + * + * Same lock and the same one-active-run rule as an admin run: the CLI walks + * every waiting article, so it refuses while any run is queued or running, and + * listing its articles on the row makes later admin and selected runs refuse + * them in turn. There is no job — the CLI executes the run itself — so the row + * is created already `running`, with the heartbeat the recovery task reads. + */ +export async function createCliRun( + payload: Payload, + input: CreateCliRunInput, +): Promise { + return withRunCreationLock(payload, null, async (req) => { + const active = await findActiveRun(payload, req) + if (active) throw new ActivePipelineRunError(active.runId) + const now = new Date().toISOString() + return payload.create({ + collection: 'pipeline-runs', + overrideAccess: true, + depth: 0, + req, + data: { + runId: input.runId, + source: 'cli', + status: 'running', + mode: input.mode, + // The schema's ceiling; the row's `articles` is the real list. + requestedCount: Math.max(1, Math.min(50, input.articleIds.length)), + ...(input.articleIds.length ? { articles: input.articleIds } : {}), + configFingerprint: input.readiness.configFingerprint, + configSnapshot: configSnapshotOf(input.readiness, null), + requestedBy: input.requestedBy, + startedAt: now, + heartbeatAt: now, + }, + }) + }) } diff --git a/cms/src/lib/llmCatalog.ts b/cms/src/lib/llmCatalog.ts index 66432e2..929f91a 100644 --- a/cms/src/lib/llmCatalog.ts +++ b/cms/src/lib/llmCatalog.ts @@ -22,7 +22,7 @@ export const LLM_CATALOG: readonly LlmModel[] = [ // Anthropic — Claude 5 family { id: 'claude-fable-5', label: 'Claude Fable 5', provider: 'anthropic', input: 10, output: 50, note: 'Most capable' }, { id: 'claude-opus-5', label: 'Claude Opus 5', provider: 'anthropic', input: 5, output: 25, note: 'Default; strong long-form writing' }, - { id: 'claude-sonnet-5', label: 'Claude Sonnet 5', provider: 'anthropic', input: 3, output: 15, note: 'Balanced' }, + { id: 'claude-sonnet-5', label: 'Claude Sonnet 5', provider: 'anthropic', input: 2, output: 10, note: 'Balanced' }, { id: 'claude-haiku-4-5', label: 'Claude Haiku 4.5', provider: 'anthropic', input: 1, output: 5, note: 'Fast and cheap' }, // OpenAI — flagship models { id: 'gpt-5.6-sol', label: 'GPT-5.6 Sol', provider: 'openai', input: 4, output: 20, note: 'Frontier model for complex work' }, diff --git a/cms/src/lib/llmSettings.ts b/cms/src/lib/llmSettings.ts index df78516..6d1c6dd 100644 --- a/cms/src/lib/llmSettings.ts +++ b/cms/src/lib/llmSettings.ts @@ -148,7 +148,18 @@ export function resolveExtractionModel( settings: LlmSettingsDoc | null | undefined, env: Record, ): ResolvedModel { - return resolveModel(settings?.brandVoiceExtractModel, env[EXTRACTION_ENV_VAR]) + // Unset follows the generate model, provider and tier: a workspace that + // writes with an OpenAI model is not refused for an Anthropic model it never + // chose, and one that writes with Claude Opus keeps Opus for this drafting + // task rather than dropping to a small model. A generate id neither + // provider serves (a stale `codex/*` override) falls back to the platform + // default instead of being inherited. + const generate = resolveStageModels(settings, env).generate.model + return resolveModel( + settings?.brandVoiceExtractModel, + env[EXTRACTION_ENV_VAR], + providerForModel(generate) === 'unknown' ? DEFAULT_MODEL : generate, + ) } /** diff --git a/cms/src/lib/pipelineRunLease.ts b/cms/src/lib/pipelineRunLease.ts new file mode 100644 index 0000000..c0e0f47 --- /dev/null +++ b/cms/src/lib/pipelineRunLease.ts @@ -0,0 +1,423 @@ +import { sql } from '@payloadcms/db-postgres' +import { createLocalReq, type Payload, type PayloadRequest } from 'payload' + +import type { RunPipelineResult } from '../../../pipeline/src/stages' +import type { PipelineRun } from '../payload-types' + +/** + * The lease a running pipeline run holds on its `pipeline-runs` row. + * + * A run is `running` only while something refreshes `heartbeatAt`: the content + * worker and the `pipeline run` CLI both start a heartbeat when they claim the + * row and stop it when they settle it. A process that dies stops refreshing, + * and `recoverStaleRuns` (the `recover-stale-runs` task) fails the row once the + * heartbeat is older than `RUN_LEASE_TIMEOUT_MS`. Elapsed time alone never + * releases a run: a long run whose worker is alive keeps its lease. + * + * Every write a run makes to its own row after it starts is fenced on the + * status it expects (`updateRunIfStatus`), under a row lock that recovery takes + * too. A worker that comes back after its run was recovered therefore cannot + * overwrite the recovered state, and its heartbeat aborts the run instead. + */ + +export const RUN_HEARTBEAT_INTERVAL_MS = 60_000 +export const RUN_LEASE_TIMEOUT_MS = 15 * 60_000 + +type RunStatus = PipelineRun['status'] + +/** Thrown into a run whose row was recovered (or otherwise settled) under it. */ +export class RunLeaseLostError extends Error { + constructor(readonly runId: string) { + super( + `Run ${runId} is no longer running: it was marked failed (by recover-stale-runs, once its heartbeat lapsed), so this process stopped without writing to it.`, + ) + this.name = 'RunLeaseLostError' + } +} + +/** Strip anything that looks like a credential before an error is stored on a run row. */ +export function safeRunError(error: unknown, fallback = 'Content run failed'): string { + let message = error instanceof Error ? error.message : fallback + for (const name of ['ANTHROPIC_API_KEY', 'OPENAI_API_KEY', 'AHREFS_API_KEY', 'PAYLOAD_SECRET']) { + const secret = process.env[name] + if (secret) message = message.replaceAll(secret, '[redacted]') + } + return message.replace(/(sk-|api[_-]?key[=: ]+)[^\s,;]+/gi, '$1[redacted]').slice(0, 500) +} + +/** What a finished pipeline result leaves on its run row; shared with the CLI. */ +export function settledRunData(result: RunPipelineResult) { + // A run that advanced nothing is not a success, whatever the job queue + // thinks. `runPipeline` deliberately swallows a single article's failure so + // the rest of the batch survives, which means the only signal that anything + // went wrong is `result.failed` — and reporting `succeeded` regardless left + // an operator staring at a card that had not moved with nowhere to look. + const advanced = Object.values(result.finalStatuses).reduce((sum, n) => sum + n, 0) + return { + status: advanced === 0 && result.failed > 0 ? ('failed' as const) : ('succeeded' as const), + finalStatuses: result.finalStatuses, + warnings: result.failures.length > 0 ? result.failures : null, + errorSummary: + result.failures.length > 0 + ? result.failures + .map((f) => `${f.stage}: "${f.keyword}" — ${safeRunError(new Error(f.message))}`) + .join('\n\n') + : null, + completedAt: new Date().toISOString(), + } +} + +type SqlExecutor = { + execute: (query: unknown) => Promise<{ rows: Array> }> +} + +interface LockedRunRow { + runId: string | null + status: RunStatus | null + heartbeatAt: Date | null + startedAt: Date | null + createdAt: Date | null +} + +const asDate = (value: unknown): Date | null => + value == null ? null : value instanceof Date ? value : new Date(String(value)) + +/** + * Run `fn` holding a row lock on one `pipeline-runs` row, inside a transaction + * whose request `fn` must pass to any Payload write. Recovery and every fenced + * write go through here, so the status check and the write are atomic with + * respect to each other. + */ +async function withRunRowLock( + payload: Payload, + id: number, + fn: (row: LockedRunRow, req: PayloadRequest) => Promise, +): Promise { + const transactionID = await payload.db.beginTransaction({ isolationLevel: 'read committed' }) + if (transactionID == null) throw new Error('The database could not start a run transaction.') + try { + const session = ( + payload.db as typeof payload.db & { sessions: Record } + ).sessions[String(transactionID)]?.db + if (!session) throw new Error('The run transaction session is unavailable.') + const { rows } = await session.execute( + sql`SELECT run_id, status, heartbeat_at, started_at, created_at FROM pipeline_runs WHERE id = ${id} FOR UPDATE`, + ) + const raw = rows[0] + const row: LockedRunRow = { + runId: (raw?.run_id as string | undefined) ?? null, + status: (raw?.status as RunStatus | undefined) ?? null, + heartbeatAt: asDate(raw?.heartbeat_at), + startedAt: asDate(raw?.started_at), + createdAt: asDate(raw?.created_at), + } + const req = await createLocalReq({ req: { transactionID } }, payload) + const value = await fn(row, req) + await payload.db.commitTransaction(transactionID) + return value + } catch (error) { + await payload.db.rollbackTransaction(transactionID) + throw error + } +} + +/** + * Write `data` to the run row only if it is still at `expected`. Returns false, + * having written nothing, when the row has moved on — recovered, or settled by + * someone else. + */ +export async function updateRunIfStatus( + payload: Payload, + id: number, + expected: RunStatus, + data: Partial, +): Promise { + return withRunRowLock(payload, id, async (row, req) => { + if (row.status !== expected) return false + await payload.update({ + collection: 'pipeline-runs', + id, + data, + depth: 0, + overrideAccess: true, + req, + }) + return true + }) +} + +/** + * Refresh the lease. One atomic UPDATE, fenced on `running`; false when the row + * is no longer running, which is the holder's cue to stop. + */ +export async function touchRunHeartbeat(payload: Payload, id: number): Promise { + const now = new Date().toISOString() + const { rows } = await (payload.db as unknown as { drizzle: SqlExecutor }).drizzle.execute( + sql`UPDATE pipeline_runs SET heartbeat_at = ${now}, updated_at = ${now} WHERE id = ${id} AND status = 'running' RETURNING id`, + ) + return rows.length > 0 +} + +export interface RunHeartbeat { + /** Aborted once the row is found no longer `running`. */ + signal: AbortSignal + /** + * Run `write` with a request inside a transaction that holds the run row + * lock, only if the row is still this run's and still `running`. Otherwise + * aborts `signal` and resolves false without calling `write`. The timer alone + * leaves up to a minute in which a recovered run could still write; this + * closes it for every article write the stage loop commits. + */ + commit(write: (req: PayloadRequest) => Promise): Promise + stop(): void +} + +/** + * Refresh `heartbeatAt` every `intervalMs` until stopped. When a refresh finds + * the row recovered, the signal aborts with a `RunLeaseLostError` so the run + * stops before its next write. A refresh that fails outright (the database is + * briefly unreachable) is logged and retried on the next tick: the lease has + * fifteen minutes of slack for exactly that. + */ +export function startRunHeartbeat( + payload: Payload, + run: Pick, + intervalMs = RUN_HEARTBEAT_INTERVAL_MS, +): RunHeartbeat { + const controller = new AbortController() + let inFlight = false + const timer = setInterval(() => { + if (inFlight || controller.signal.aborted) return + inFlight = true + touchRunHeartbeat(payload, run.id) + .then((alive) => { + if (!alive) { + clearInterval(timer) + controller.abort(new RunLeaseLostError(run.runId)) + } + }) + .catch((error) => { + payload.logger.warn( + `heartbeat for run ${run.runId} failed: ${error instanceof Error ? error.message : String(error)}`, + ) + }) + .finally(() => { + inFlight = false + }) + }, intervalMs) + // A heartbeat must never be what keeps a finished CLI process alive. + timer.unref?.() + return { + signal: controller.signal, + commit: async (write) => { + if (controller.signal.aborted) return false + const owned = await withRunRowLock(payload, run.id, async (row, req) => { + if (row.status !== 'running' || row.runId !== run.runId) return false + await write(req) + return true + }) + if (!owned) { + clearInterval(timer) + controller.abort(new RunLeaseLostError(run.runId)) + } + return owned + }, + stop: () => clearInterval(timer), + } +} + +/** The lease's age reference: the last heartbeat, else the start, else creation. */ +function leaseSince( + row: Pick, +): Date | null { + return row.heartbeatAt ?? row.startedAt ?? row.createdAt +} + +export interface RecoverStaleRunsResult { + /** `runId`s marked failed because their lease expired. */ + recoveredRuns: string[] + /** `payload-jobs` ids released from `processing` and marked failed. */ + failedJobs: Array +} + +/** + * Fail every run whose lease has expired, and release the content job that + * held the `content-pipeline` concurrency key for it. + * + * A run is stale when it is `running` and its `heartbeatAt` (or, for a row + * written before heartbeats existed, its `startedAt`) is older than + * `timeoutMs`. Each candidate is re-checked under the row lock, so a heartbeat + * that lands between the query and the write keeps its run alive. + * + * Jobs: Payload treats a `content-run` job with `processing: true` as holding + * the concurrency key, and nothing but the worker that took it ever clears the + * flag. So a job is released when its run was just recovered, or when the + * queue has not touched it for `timeoutMs` and its run is not `running` (the + * worker died after taking the job but before claiming the run; that run is + * still `queued` and is failed with it). Either way the decision is made under + * the run row lock and the job is released in the same transaction, so a + * worker that claims the run first keeps both its run and its job. A released + * job is marked the way Payload marks a job that ran out of retries — + * `hasError`, not processing — so it is never picked up again. + */ +export async function recoverStaleRuns( + payload: Payload, + { now = new Date(), timeoutMs = RUN_LEASE_TIMEOUT_MS }: { now?: Date; timeoutMs?: number } = {}, +): Promise { + const cutoff = new Date(now.getTime() - timeoutMs) + const cutoffIso = cutoff.toISOString() + const minutes = Math.round(timeoutMs / 60_000) + + const { docs: jobs } = await payload.find({ + collection: 'payload-jobs', + where: { + and: [ + { taskSlug: { equals: 'content-run' } }, + { processing: { equals: true } }, + { completedAt: { exists: false } }, + ], + }, + select: { input: true, updatedAt: true, totalTried: true }, + pagination: false, + limit: 0, + depth: 0, + overrideAccess: true, + }) + const jobRunId = (job: (typeof jobs)[number]) => { + const runId = (job.input as { runId?: unknown } | null | undefined)?.runId + return typeof runId === 'string' ? runId : null + } + + const failedJobs: Array = [] + /** Release one job, still only if it is processing; `req` keeps it in the caller's transaction. */ + const releaseJob = async (job: (typeof jobs)[number], runId: string, req?: PayloadRequest) => { + const result = await payload.update({ + collection: 'payload-jobs', + where: { and: [{ id: { equals: job.id } }, { processing: { equals: true } }] }, + data: { + processing: false, + hasError: true, + totalTried: (job.totalTried ?? 0) + 1, + error: { + message: `Released by recover-stale-runs: run ${runId} stopped responding.`, + }, + }, + depth: 0, + overrideAccess: true, + ...(req ? { req } : {}), + }) + return result.docs.length > 0 + } + + const { docs: candidates } = await payload.find({ + collection: 'pipeline-runs', + where: { + and: [ + { status: { equals: 'running' } }, + { + or: [ + { heartbeatAt: { less_than: cutoffIso } }, + { + and: [{ heartbeatAt: { exists: false } }, { startedAt: { less_than: cutoffIso } }], + }, + { + and: [ + { heartbeatAt: { exists: false } }, + { startedAt: { exists: false } }, + { createdAt: { less_than: cutoffIso } }, + ], + }, + ], + }, + ], + }, + select: { runId: true }, + pagination: false, + limit: 0, + depth: 0, + overrideAccess: true, + }) + + const recoveredRuns: string[] = [] + for (const candidate of candidates) { + const released = await withRunRowLock(payload, candidate.id, async (row, req) => { + const since = leaseSince(row) + if (row.status !== 'running' || !since || since >= cutoff) return null + await payload.update({ + collection: 'pipeline-runs', + id: candidate.id, + data: { + status: 'failed', + completedAt: now.toISOString(), + errorSummary: + `The worker stopped responding: no heartbeat since ${since.toISOString()}, ` + + `so Datum marked this run failed after ${minutes} minutes. Articles keep the ` + + 'status they last saved; start a new run to carry on.', + }, + depth: 0, + overrideAccess: true, + req, + }) + const ids: Array = [] + for (const job of jobs) { + if (jobRunId(job) === candidate.runId && (await releaseJob(job, candidate.runId, req))) { + ids.push(job.id) + } + } + return ids + }) + if (released) { + recoveredRuns.push(candidate.runId) + failedJobs.push(...released) + payload.logger.warn(`recovered stale pipeline run ${candidate.runId}`) + } + } + + for (const job of jobs) { + const runId = jobRunId(job) + if (runId == null || recoveredRuns.includes(runId)) continue + if (new Date(job.updatedAt) >= cutoff) continue + const { docs } = await payload.find({ + collection: 'pipeline-runs', + where: { runId: { equals: runId } }, + select: { runId: true }, + limit: 1, + depth: 0, + overrideAccess: true, + }) + const run = docs[0] + if (!run) { + if (await releaseJob(job, runId)) failedJobs.push(job.id) + continue + } + // Decided under the row lock: a worker that claims the run while this + // waits leaves it `running`, and then both the run and its job are its. + const outcome = await withRunRowLock(payload, run.id, async (row, req) => { + // A `running` run here has a fresh lease (stale ones were failed above), + // so its worker is alive and the job is genuinely in progress. + if (row.status === 'running') return null + const failedRun = row.status === 'queued' + if (failedRun) { + await payload.update({ + collection: 'pipeline-runs', + id: run.id, + data: { + status: 'failed', + completedAt: now.toISOString(), + errorSummary: + `The worker took this run's job but stopped responding before starting it; ` + + `Datum marked the run failed after ${minutes} minutes. Start a new run to carry on.`, + }, + depth: 0, + overrideAccess: true, + req, + }) + } + return { failedRun, released: await releaseJob(job, runId, req) } + }) + if (outcome?.failedRun) recoveredRuns.push(runId) + if (outcome?.released) failedJobs.push(job.id) + } + + return { recoveredRuns, failedJobs } +} diff --git a/cms/src/lib/runMode.ts b/cms/src/lib/runMode.ts new file mode 100644 index 0000000..2e62518 --- /dev/null +++ b/cms/src/lib/runMode.ts @@ -0,0 +1,46 @@ +/** + * The one mock/live rule. Dependency-free on purpose: the pipeline config, the + * CMS-side model calls and the readiness check all import it, and none of them + * may throw at import because of a bad environment. + * + * - `MOCK_MODE` true/1/yes -> mock; false/0/no -> live. + * - Unset or blank -> live only when a provider key is present, else mock. Only + * a key lifts mock: nothing else a dev machine carries may start paid runs. + * - Anything else -> mock (the safe side), and `runModeProblem` says why. + * + * `MOCK_MODE=false` with no key is live: the per-stage key check in + * `pipeline/src/models.ts` refuses the run and readiness lists the missing keys. + */ +export type RunMode = 'mock' | 'live' + +type Env = Record + +const TRUE_VALUES = ['true', '1', 'yes'] +const FALSE_VALUES = ['false', '0', 'no'] + +function set(value: string | undefined): value is string { + return Boolean(value?.trim()) +} + +/** The raw `MOCK_MODE` when it is set but is not one of the accepted spellings. */ +function unrecognisedValue(env: Env): string | undefined { + const raw = env.MOCK_MODE?.trim() + if (!raw) return undefined + const value = raw.toLowerCase() + return TRUE_VALUES.includes(value) || FALSE_VALUES.includes(value) ? undefined : raw +} + +export function runModeFromEnv(env: Env): RunMode { + const value = env.MOCK_MODE?.trim().toLowerCase() + // Explicit and unrecognised values both resolve here: only a false spelling is live. + if (value) return FALSE_VALUES.includes(value) ? 'live' : 'mock' + return set(env.ANTHROPIC_API_KEY) || set(env.OPENAI_API_KEY) ? 'live' : 'mock' +} + +/** An operator-facing sentence when `MOCK_MODE` is set to something unusable, else undefined. */ +export function runModeProblem(env: Env): string | undefined { + const raw = unrecognisedValue(env) + return raw === undefined + ? undefined + : `MOCK_MODE has an unrecognised value: "${raw}". Treated as mock mode until it is set to true or false` +} diff --git a/cms/src/lib/workspaceReadiness.ts b/cms/src/lib/workspaceReadiness.ts index 1effb18..90fcd24 100644 --- a/cms/src/lib/workspaceReadiness.ts +++ b/cms/src/lib/workspaceReadiness.ts @@ -12,6 +12,7 @@ import { type PipelineStage, resolveStageModels, } from './llmSettings' +import { runModeFromEnv, runModeProblem } from './runMode' import { COMPETITOR_DOMAINS_ENV_VAR, type EvidenceBankContent, @@ -175,13 +176,10 @@ function configured(value: string | undefined): boolean { return Boolean(value?.trim()) } -// Only an API key flips a workspace live on its own, matching -// `pipeline/src/config.ts`: nothing else a dev machine happens to carry counts. +// The rule lives in `runMode.ts`, shared with the pipeline config and the +// CMS-side model calls so they cannot disagree about mock versus live. export function modeFromEnv(env: Record): PipelineMode { - const value = env.MOCK_MODE?.trim().toLowerCase() - if (value === 'false' || value === '0' || value === 'no') return 'live' - if (value === 'true' || value === '1' || value === 'yes') return 'mock' - return configured(env.ANTHROPIC_API_KEY) || configured(env.OPENAI_API_KEY) ? 'live' : 'mock' + return runModeFromEnv(env) } function fingerprint(value: unknown): string { @@ -240,7 +238,9 @@ export function evaluateRuntimeReadiness( } const sortedMissing = [...missing].sort() + const modeProblem = runModeProblem(input.env) const problems = [ + ...(modeProblem ? [modeProblem] : []), ...(placeholderVars.length > 0 ? [ `Replace the .env.example placeholders in ${placeholderVars.join(', ')}, or fill in the Workspace step (what is saved there is used instead)`, @@ -397,3 +397,20 @@ export function evaluateWorkspaceReadiness(input: WorkspaceReadinessInput): Work }, } } + +/** + * Why no pipeline run may start in this workspace, in the words an operator + * acts on, or null when one may. The same setup rule every run obeys — brand + * voice, workspace (target domain; competitors in live mode) and an active + * audience, plus the environment a live run needs. The CMS adds its live-cost + * confirmation on top (`gateRunReadiness`); `pipeline run` asks this directly. + */ +export function runReadinessRefusal(readiness: WorkspaceReadiness): string | null { + if (!readiness.runtime.ready) { + return `Configure the required environment variables: ${readiness.runtime.blockers.join(', ')}.` + } + if (!readiness.governance.ready) { + return `Finish setup before running the pipeline: ${readiness.governance.problems.join('; ')}.` + } + return null +} diff --git a/cms/src/migrations/20261110_054316_pipeline_run_lease.json b/cms/src/migrations/20261110_054316_pipeline_run_lease.json new file mode 100644 index 0000000..4a92972 --- /dev/null +++ b/cms/src/migrations/20261110_054316_pipeline_run_lease.json @@ -0,0 +1,9785 @@ +{ + "version": "7", + "dialect": "postgresql", + "tables": { + "public.setup_suggestions": { + "name": "setup_suggestions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "enum_setup_suggestions_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'banned_word'" + }, + "signature": { + "name": "signature", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "target": { + "name": "target", + "type": "enum_setup_suggestions_target", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'brand-voice'" + }, + "proposal": { + "name": "proposal", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "occurrences": { + "name": "occurrences", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "count": { + "name": "count", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "status": { + "name": "status", + "type": "enum_setup_suggestions_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'open'" + }, + "first_seen_at": { + "name": "first_seen_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "decided_by": { + "name": "decided_by", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "decided_at": { + "name": "decided_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "decision_reason": { + "name": "decision_reason", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "setup_suggestions_signature_idx": { + "name": "setup_suggestions_signature_idx", + "columns": [ + { + "expression": "signature", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "setup_suggestions_status_idx": { + "name": "setup_suggestions_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "setup_suggestions_updated_at_idx": { + "name": "setup_suggestions_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "setup_suggestions_created_at_idx": { + "name": "setup_suggestions_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users_sessions": { + "name": "users_sessions", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "users_sessions_order_idx": { + "name": "users_sessions_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "users_sessions_parent_id_idx": { + "name": "users_sessions_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "users_sessions_parent_id_fk": { + "name": "users_sessions_parent_id_fk", + "tableFrom": "users_sessions", + "tableTo": "users", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "email": { + "name": "email", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "reset_password_token": { + "name": "reset_password_token", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "reset_password_expiration": { + "name": "reset_password_expiration", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "salt": { + "name": "salt", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "hash": { + "name": "hash", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "reset_password_requested_at": { + "name": "reset_password_requested_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "login_attempts": { + "name": "login_attempts", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "lock_until": { + "name": "lock_until", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "users_updated_at_idx": { + "name": "users_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "users_created_at_idx": { + "name": "users_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "users_email_idx": { + "name": "users_email_idx", + "columns": [ + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media": { + "name": "media", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "alt": { + "name": "alt", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "url": { + "name": "url", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "thumbnail_u_r_l": { + "name": "thumbnail_u_r_l", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "filename": { + "name": "filename", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "mime_type": { + "name": "mime_type", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "filesize": { + "name": "filesize", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "width": { + "name": "width", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "height": { + "name": "height", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "focal_x": { + "name": "focal_x", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "focal_y": { + "name": "focal_y", + "type": "numeric", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "media_updated_at_idx": { + "name": "media_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "media_created_at_idx": { + "name": "media_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "media_filename_idx": { + "name": "media_filename_idx", + "columns": [ + { + "expression": "filename", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.templates_dos": { + "name": "templates_dos", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "templates_dos_order_idx": { + "name": "templates_dos_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "templates_dos_parent_id_idx": { + "name": "templates_dos_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "templates_dos_parent_id_fk": { + "name": "templates_dos_parent_id_fk", + "tableFrom": "templates_dos", + "tableTo": "templates", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.templates_donts": { + "name": "templates_donts", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "templates_donts_order_idx": { + "name": "templates_donts_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "templates_donts_parent_id_idx": { + "name": "templates_donts_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "templates_donts_parent_id_fk": { + "name": "templates_donts_parent_id_fk", + "tableFrom": "templates_donts", + "tableTo": "templates", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.templates_required_sections": { + "name": "templates_required_sections", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "heading": { + "name": "heading", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "templates_required_sections_order_idx": { + "name": "templates_required_sections_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "templates_required_sections_parent_id_idx": { + "name": "templates_required_sections_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "templates_required_sections_parent_id_fk": { + "name": "templates_required_sections_parent_id_fk", + "tableFrom": "templates_required_sections", + "tableTo": "templates", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.templates": { + "name": "templates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "intent": { + "name": "intent", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "company_mentions": { + "name": "company_mentions", + "type": "enum_templates_company_mentions", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'mention'" + }, + "outline": { + "name": "outline", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "example": { + "name": "example", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "seo_spec_title_tag_max_length": { + "name": "seo_spec_title_tag_max_length", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 60 + }, + "seo_spec_meta_description_max_length": { + "name": "seo_spec_meta_description_max_length", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 160 + }, + "seo_spec_heading_structure_rules": { + "name": "seo_spec_heading_structure_rules", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "seo_spec_faq_required": { + "name": "seo_spec_faq_required", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "seo_spec_faq_min_questions": { + "name": "seo_spec_faq_min_questions", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "seo_spec_faq_max_questions": { + "name": "seo_spec_faq_max_questions", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "seo_spec_og_tags_required": { + "name": "seo_spec_og_tags_required", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "templates_name_idx": { + "name": "templates_name_idx", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "templates_updated_at_idx": { + "name": "templates_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "templates_created_at_idx": { + "name": "templates_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.articles_secondary_keywords": { + "name": "articles_secondary_keywords", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "keyword": { + "name": "keyword", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "articles_secondary_keywords_order_idx": { + "name": "articles_secondary_keywords_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_secondary_keywords_parent_id_idx": { + "name": "articles_secondary_keywords_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "articles_secondary_keywords_parent_id_fk": { + "name": "articles_secondary_keywords_parent_id_fk", + "tableFrom": "articles_secondary_keywords", + "tableTo": "articles", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.articles_research_common_subtopics": { + "name": "articles_research_common_subtopics", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "articles_research_common_subtopics_order_idx": { + "name": "articles_research_common_subtopics_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_research_common_subtopics_parent_id_idx": { + "name": "articles_research_common_subtopics_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "articles_research_common_subtopics_parent_id_fk": { + "name": "articles_research_common_subtopics_parent_id_fk", + "tableFrom": "articles_research_common_subtopics", + "tableTo": "articles", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.articles_research_related_questions": { + "name": "articles_research_related_questions", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "articles_research_related_questions_order_idx": { + "name": "articles_research_related_questions_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_research_related_questions_parent_id_idx": { + "name": "articles_research_related_questions_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "articles_research_related_questions_parent_id_fk": { + "name": "articles_research_related_questions_parent_id_fk", + "tableFrom": "articles_research_related_questions", + "tableTo": "articles", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.articles_brief_sections": { + "name": "articles_brief_sections", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "heading": { + "name": "heading", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "notes": { + "name": "notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "enum_articles_brief_sections_source", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "articles_brief_sections_order_idx": { + "name": "articles_brief_sections_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_brief_sections_parent_id_idx": { + "name": "articles_brief_sections_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "articles_brief_sections_parent_id_fk": { + "name": "articles_brief_sections_parent_id_fk", + "tableFrom": "articles_brief_sections", + "tableTo": "articles", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.articles_faq_items": { + "name": "articles_faq_items", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "question": { + "name": "question", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "answer": { + "name": "answer", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "articles_faq_items_order_idx": { + "name": "articles_faq_items_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_faq_items_parent_id_idx": { + "name": "articles_faq_items_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "articles_faq_items_parent_id_fk": { + "name": "articles_faq_items_parent_id_fk", + "tableFrom": "articles_faq_items", + "tableTo": "articles", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.articles": { + "name": "articles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "title": { + "name": "title", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "slug": { + "name": "slug", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "keyword": { + "name": "keyword", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "template_id": { + "name": "template_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "icp_id": { + "name": "icp_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "research_ranking_pages_summary": { + "name": "research_ranking_pages_summary", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "research_snapshot_id": { + "name": "research_snapshot_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "research_query_cluster": { + "name": "research_query_cluster", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "research_facets": { + "name": "research_facets", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "research_gaps": { + "name": "research_gaps", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "brief_angle": { + "name": "brief_angle", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "brief_angle_options": { + "name": "brief_angle_options", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "brief_audience": { + "name": "brief_audience", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "brief_must_cover": { + "name": "brief_must_cover", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "brief_opportunities": { + "name": "brief_opportunities", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "brief_notes": { + "name": "brief_notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "brief_approved_at": { + "name": "brief_approved_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "brief_approved_by": { + "name": "brief_approved_by", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "title_tag": { + "name": "title_tag", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "meta_description": { + "name": "meta_description", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "og_title": { + "name": "og_title", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "og_description": { + "name": "og_description", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "og_image": { + "name": "og_image", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "enum_articles_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'topic_selected'" + }, + "publish_at": { + "name": "publish_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "evidence_citations": { + "name": "evidence_citations", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "qa_results_structural_passed": { + "name": "qa_results_structural_passed", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "qa_results_structural_violations": { + "name": "qa_results_structural_violations", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "qa_results_fact_check_passed": { + "name": "qa_results_fact_check_passed", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "qa_results_fact_check_notes": { + "name": "qa_results_fact_check_notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "qa_results_fact_check_sources": { + "name": "qa_results_fact_check_sources", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "qa_results_qualitative_review_passed": { + "name": "qa_results_qualitative_review_passed", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "qa_results_qualitative_review_notes": { + "name": "qa_results_qualitative_review_notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "qa_results_qualitative_review_voice_score": { + "name": "qa_results_qualitative_review_voice_score", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "qa_results_qualitative_review_voice_notes": { + "name": "qa_results_qualitative_review_voice_notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "qa_results_qualitative_review_not_trait_violations": { + "name": "qa_results_qualitative_review_not_trait_violations", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "qa_results_evidence_check_passed": { + "name": "qa_results_evidence_check_passed", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "qa_results_evidence_check_notes": { + "name": "qa_results_evidence_check_notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "qa_results_evidence_check_claims": { + "name": "qa_results_evidence_check_claims", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "information_gain_run_id": { + "name": "information_gain_run_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "information_gain_decision": { + "name": "information_gain_decision", + "type": "enum_articles_information_gain_decision", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "information_gain_policy_version": { + "name": "information_gain_policy_version", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "information_gain_consensus_coverage": { + "name": "information_gain_consensus_coverage", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "information_gain_verified_gain_units": { + "name": "information_gain_verified_gain_units", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "information_gain_verification_ratio": { + "name": "information_gain_verification_ratio", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "information_gain_internal_duplication_rate": { + "name": "information_gain_internal_duplication_rate", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "information_gain_verified_novel_claims": { + "name": "information_gain_verified_novel_claims", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "information_gain_scored_at": { + "name": "information_gain_scored_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "generation_model": { + "name": "generation_model", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "qa_models": { + "name": "qa_models", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "total_cost_usd": { + "name": "total_cost_usd", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "reviewed_by": { + "name": "reviewed_by", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "review_notes": { + "name": "review_notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "review_justification": { + "name": "review_justification", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "revision_notes": { + "name": "revision_notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "revision_count": { + "name": "revision_count", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "content_updated_at": { + "name": "content_updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "published_at": { + "name": "published_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "articles_archived_idx": { + "name": "articles_archived_idx", + "columns": [ + { + "expression": "archived", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_slug_idx": { + "name": "articles_slug_idx", + "columns": [ + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_keyword_idx": { + "name": "articles_keyword_idx", + "columns": [ + { + "expression": "keyword", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_template_idx": { + "name": "articles_template_idx", + "columns": [ + { + "expression": "template_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_icp_idx": { + "name": "articles_icp_idx", + "columns": [ + { + "expression": "icp_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_research_research_snapshot_idx": { + "name": "articles_research_research_snapshot_idx", + "columns": [ + { + "expression": "research_snapshot_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_status_idx": { + "name": "articles_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_publish_at_idx": { + "name": "articles_publish_at_idx", + "columns": [ + { + "expression": "publish_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_information_gain_information_gain_run_idx": { + "name": "articles_information_gain_information_gain_run_idx", + "columns": [ + { + "expression": "information_gain_run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_updated_at_idx": { + "name": "articles_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_created_at_idx": { + "name": "articles_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "articles_template_id_templates_id_fk": { + "name": "articles_template_id_templates_id_fk", + "tableFrom": "articles", + "tableTo": "templates", + "columnsFrom": [ + "template_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "articles_icp_id_icps_id_fk": { + "name": "articles_icp_id_icps_id_fk", + "tableFrom": "articles", + "tableTo": "icps", + "columnsFrom": [ + "icp_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "articles_research_snapshot_id_corpus_snapshots_id_fk": { + "name": "articles_research_snapshot_id_corpus_snapshots_id_fk", + "tableFrom": "articles", + "tableTo": "corpus_snapshots", + "columnsFrom": [ + "research_snapshot_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "articles_information_gain_run_id_information_gain_runs_id_fk": { + "name": "articles_information_gain_run_id_information_gain_runs_id_fk", + "tableFrom": "articles", + "tableTo": "information_gain_runs", + "columnsFrom": [ + "information_gain_run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cost_log": { + "name": "cost_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "pipeline_run_id": { + "name": "pipeline_run_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "article_id": { + "name": "article_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "stage": { + "name": "stage", + "type": "enum_cost_log_stage", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "provider": { + "name": "provider", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "input_tokens": { + "name": "input_tokens", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "output_tokens": { + "name": "output_tokens", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "web_search_requests": { + "name": "web_search_requests", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "cost_usd": { + "name": "cost_usd", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "request": { + "name": "request", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "response": { + "name": "response", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "cost_log_pipeline_run_id_idx": { + "name": "cost_log_pipeline_run_id_idx", + "columns": [ + { + "expression": "pipeline_run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "cost_log_article_idx": { + "name": "cost_log_article_idx", + "columns": [ + { + "expression": "article_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "cost_log_updated_at_idx": { + "name": "cost_log_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "cost_log_created_at_idx": { + "name": "cost_log_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cost_log_article_id_articles_id_fk": { + "name": "cost_log_article_id_articles_id_fk", + "tableFrom": "cost_log", + "tableTo": "articles", + "columnsFrom": [ + "article_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.article_audit": { + "name": "article_audit", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "article_id": { + "name": "article_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "event": { + "name": "event", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "summary": { + "name": "summary", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "actor_type": { + "name": "actor_type", + "type": "enum_article_audit_actor_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "actor": { + "name": "actor", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "pipeline_run_id": { + "name": "pipeline_run_id", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "stage": { + "name": "stage", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "from_status": { + "name": "from_status", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "to_status": { + "name": "to_status", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "details": { + "name": "details", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "article_audit_article_idx": { + "name": "article_audit_article_idx", + "columns": [ + { + "expression": "article_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "article_audit_event_idx": { + "name": "article_audit_event_idx", + "columns": [ + { + "expression": "event", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "article_audit_pipeline_run_id_idx": { + "name": "article_audit_pipeline_run_id_idx", + "columns": [ + { + "expression": "pipeline_run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "article_audit_updated_at_idx": { + "name": "article_audit_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "article_audit_created_at_idx": { + "name": "article_audit_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "article_audit_article_id_articles_id_fk": { + "name": "article_audit_article_id_articles_id_fk", + "tableFrom": "article_audit", + "tableTo": "articles", + "columnsFrom": [ + "article_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brand_voices_core_values": { + "name": "brand_voices_core_values", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "value": { + "name": "value", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "brand_voices_core_values_order_idx": { + "name": "brand_voices_core_values_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_core_values_parent_id_idx": { + "name": "brand_voices_core_values_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "brand_voices_core_values_parent_id_fk": { + "name": "brand_voices_core_values_parent_id_fk", + "tableFrom": "brand_voices_core_values", + "tableTo": "brand_voices", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brand_voices_voice_adjectives": { + "name": "brand_voices_voice_adjectives", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "adjective": { + "name": "adjective", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "do_example": { + "name": "do_example", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "dont_example": { + "name": "dont_example", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "brand_voices_voice_adjectives_order_idx": { + "name": "brand_voices_voice_adjectives_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_voice_adjectives_parent_id_idx": { + "name": "brand_voices_voice_adjectives_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "brand_voices_voice_adjectives_parent_id_fk": { + "name": "brand_voices_voice_adjectives_parent_id_fk", + "tableFrom": "brand_voices_voice_adjectives", + "tableTo": "brand_voices", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brand_voices_not_traits": { + "name": "brand_voices_not_traits", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "trait": { + "name": "trait", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "boundary_note": { + "name": "boundary_note", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "brand_voices_not_traits_order_idx": { + "name": "brand_voices_not_traits_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_not_traits_parent_id_idx": { + "name": "brand_voices_not_traits_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "brand_voices_not_traits_parent_id_fk": { + "name": "brand_voices_not_traits_parent_id_fk", + "tableFrom": "brand_voices_not_traits", + "tableTo": "brand_voices", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brand_voices_preferred_words": { + "name": "brand_voices_preferred_words", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "word": { + "name": "word", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "brand_voices_preferred_words_order_idx": { + "name": "brand_voices_preferred_words_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_preferred_words_parent_id_idx": { + "name": "brand_voices_preferred_words_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "brand_voices_preferred_words_parent_id_fk": { + "name": "brand_voices_preferred_words_parent_id_fk", + "tableFrom": "brand_voices_preferred_words", + "tableTo": "brand_voices", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brand_voices_banned_words": { + "name": "brand_voices_banned_words", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "word": { + "name": "word", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "brand_voices_banned_words_order_idx": { + "name": "brand_voices_banned_words_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_banned_words_parent_id_idx": { + "name": "brand_voices_banned_words_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "brand_voices_banned_words_parent_id_fk": { + "name": "brand_voices_banned_words_parent_id_fk", + "tableFrom": "brand_voices_banned_words", + "tableTo": "brand_voices", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brand_voices_samples": { + "name": "brand_voices_samples", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "brand_voices_samples_order_idx": { + "name": "brand_voices_samples_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_samples_parent_id_idx": { + "name": "brand_voices_samples_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "brand_voices_samples_parent_id_fk": { + "name": "brand_voices_samples_parent_id_fk", + "tableFrom": "brand_voices_samples", + "tableTo": "brand_voices", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brand_voices": { + "name": "brand_voices", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "enum_brand_voices_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "source": { + "name": "source", + "type": "enum_brand_voices_source", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'onboarding'" + }, + "source_file_id": { + "name": "source_file_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "onboarding_step": { + "name": "onboarding_step", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "activated_at": { + "name": "activated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "activated_by": { + "name": "activated_by", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "essence_one_liner": { + "name": "essence_one_liner", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "essence_mission": { + "name": "essence_mission", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "audience_description": { + "name": "audience_description", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "audience_language_level": { + "name": "audience_language_level", + "type": "enum_brand_voices_audience_language_level", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "audience_interests": { + "name": "audience_interests", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "audience_needs": { + "name": "audience_needs", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "persona": { + "name": "persona", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "voice_in_own_words": { + "name": "voice_in_own_words", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "tone_formality": { + "name": "tone_formality", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 3 + }, + "tone_warmth": { + "name": "tone_warmth", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 3 + }, + "tone_boldness": { + "name": "tone_boldness", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 3 + }, + "tone_energy": { + "name": "tone_energy", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 3 + }, + "extraction_model": { + "name": "extraction_model", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "extraction_provider": { + "name": "extraction_provider", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "extraction_extracted_at": { + "name": "extraction_extracted_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "extraction_source_chars": { + "name": "extraction_source_chars", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "extraction_warnings": { + "name": "extraction_warnings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "brand_voices_status_idx": { + "name": "brand_voices_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_source_file_idx": { + "name": "brand_voices_source_file_idx", + "columns": [ + { + "expression": "source_file_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_updated_at_idx": { + "name": "brand_voices_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_created_at_idx": { + "name": "brand_voices_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "brand_voices_source_file_id_brand_voice_files_id_fk": { + "name": "brand_voices_source_file_id_brand_voice_files_id_fk", + "tableFrom": "brand_voices", + "tableTo": "brand_voice_files", + "columnsFrom": [ + "source_file_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brand_voice_files": { + "name": "brand_voice_files", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "url": { + "name": "url", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "thumbnail_u_r_l": { + "name": "thumbnail_u_r_l", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "filename": { + "name": "filename", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "mime_type": { + "name": "mime_type", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "filesize": { + "name": "filesize", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "width": { + "name": "width", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "height": { + "name": "height", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "focal_x": { + "name": "focal_x", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "focal_y": { + "name": "focal_y", + "type": "numeric", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "brand_voice_files_updated_at_idx": { + "name": "brand_voice_files_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voice_files_created_at_idx": { + "name": "brand_voice_files_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voice_files_filename_idx": { + "name": "brand_voice_files_filename_idx", + "columns": [ + { + "expression": "filename", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.icps_pains_evidence": { + "name": "icps_pains_evidence", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "ref": { + "name": "ref", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "icps_pains_evidence_order_idx": { + "name": "icps_pains_evidence_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_pains_evidence_parent_id_idx": { + "name": "icps_pains_evidence_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "icps_pains_evidence_parent_id_fk": { + "name": "icps_pains_evidence_parent_id_fk", + "tableFrom": "icps_pains_evidence", + "tableTo": "icps_pains", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.icps_pains": { + "name": "icps_pains", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "statement": { + "name": "statement", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "confidence": { + "name": "confidence", + "type": "enum_icps_pains_confidence", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "icps_pains_order_idx": { + "name": "icps_pains_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_pains_parent_id_idx": { + "name": "icps_pains_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "icps_pains_parent_id_fk": { + "name": "icps_pains_parent_id_fk", + "tableFrom": "icps_pains", + "tableTo": "icps", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.icps_solution_sample_lines": { + "name": "icps_solution_sample_lines", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "icps_solution_sample_lines_order_idx": { + "name": "icps_solution_sample_lines_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_solution_sample_lines_parent_id_idx": { + "name": "icps_solution_sample_lines_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "icps_solution_sample_lines_parent_id_fk": { + "name": "icps_solution_sample_lines_parent_id_fk", + "tableFrom": "icps_solution_sample_lines", + "tableTo": "icps", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.icps_competition": { + "name": "icps_competition", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "competitor": { + "name": "competitor", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "claim": { + "name": "claim", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "claimed_at": { + "name": "claimed_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "confidence": { + "name": "confidence", + "type": "enum_icps_competition_confidence", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "icps_competition_order_idx": { + "name": "icps_competition_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_competition_parent_id_idx": { + "name": "icps_competition_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "icps_competition_parent_id_fk": { + "name": "icps_competition_parent_id_fk", + "tableFrom": "icps_competition", + "tableTo": "icps", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.icps_channels": { + "name": "icps_channels", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "channel": { + "name": "channel", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "confidence": { + "name": "confidence", + "type": "enum_icps_channels_confidence", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "icps_channels_order_idx": { + "name": "icps_channels_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_channels_parent_id_idx": { + "name": "icps_channels_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "icps_channels_parent_id_fk": { + "name": "icps_channels_parent_id_fk", + "tableFrom": "icps_channels", + "tableTo": "icps", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.icps_churn_triggers": { + "name": "icps_churn_triggers", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "icps_churn_triggers_order_idx": { + "name": "icps_churn_triggers_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_churn_triggers_parent_id_idx": { + "name": "icps_churn_triggers_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "icps_churn_triggers_parent_id_fk": { + "name": "icps_churn_triggers_parent_id_fk", + "tableFrom": "icps_churn_triggers", + "tableTo": "icps", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.icps_not_our_user": { + "name": "icps_not_our_user", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "icps_not_our_user_order_idx": { + "name": "icps_not_our_user_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_not_our_user_parent_id_idx": { + "name": "icps_not_our_user_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "icps_not_our_user_parent_id_fk": { + "name": "icps_not_our_user_parent_id_fk", + "tableFrom": "icps_not_our_user", + "tableTo": "icps", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.icps": { + "name": "icps", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "enum_icps_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "primary": { + "name": "primary", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "activated_at": { + "name": "activated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "activated_by": { + "name": "activated_by", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "who": { + "name": "who", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "motivation_text": { + "name": "motivation_text", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "motivation_hypothesis": { + "name": "motivation_hypothesis", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "motivation_confidence": { + "name": "motivation_confidence", + "type": "enum_icps_motivation_confidence", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "solution_mechanism": { + "name": "solution_mechanism", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "solution_confidence": { + "name": "solution_confidence", + "type": "enum_icps_solution_confidence", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "why_us_text": { + "name": "why_us_text", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "why_us_confidence": { + "name": "why_us_confidence", + "type": "enum_icps_why_us_confidence", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "icps_status_idx": { + "name": "icps_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_primary_idx": { + "name": "icps_primary_idx", + "columns": [ + { + "expression": "primary", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_updated_at_idx": { + "name": "icps_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_created_at_idx": { + "name": "icps_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.governance_audit": { + "name": "governance_audit", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "subject_global": { + "name": "subject_global", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "event": { + "name": "event", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "summary": { + "name": "summary", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "actor_type": { + "name": "actor_type", + "type": "enum_governance_audit_actor_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "actor": { + "name": "actor", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "from_status": { + "name": "from_status", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "to_status": { + "name": "to_status", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "details": { + "name": "details", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "governance_audit_subject_global_idx": { + "name": "governance_audit_subject_global_idx", + "columns": [ + { + "expression": "subject_global", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "governance_audit_event_idx": { + "name": "governance_audit_event_idx", + "columns": [ + { + "expression": "event", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "governance_audit_updated_at_idx": { + "name": "governance_audit_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "governance_audit_created_at_idx": { + "name": "governance_audit_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.governance_audit_rels": { + "name": "governance_audit_rels", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "order": { + "name": "order", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "parent_id": { + "name": "parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "path": { + "name": "path", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "brand_voices_id": { + "name": "brand_voices_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evidence_sources_id": { + "name": "evidence_sources_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "icps_id": { + "name": "icps_id", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "governance_audit_rels_order_idx": { + "name": "governance_audit_rels_order_idx", + "columns": [ + { + "expression": "order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "governance_audit_rels_parent_idx": { + "name": "governance_audit_rels_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "governance_audit_rels_path_idx": { + "name": "governance_audit_rels_path_idx", + "columns": [ + { + "expression": "path", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "governance_audit_rels_brand_voices_id_idx": { + "name": "governance_audit_rels_brand_voices_id_idx", + "columns": [ + { + "expression": "brand_voices_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "governance_audit_rels_evidence_sources_id_idx": { + "name": "governance_audit_rels_evidence_sources_id_idx", + "columns": [ + { + "expression": "evidence_sources_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "governance_audit_rels_icps_id_idx": { + "name": "governance_audit_rels_icps_id_idx", + "columns": [ + { + "expression": "icps_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "governance_audit_rels_parent_fk": { + "name": "governance_audit_rels_parent_fk", + "tableFrom": "governance_audit_rels", + "tableTo": "governance_audit", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "governance_audit_rels_brand_voices_fk": { + "name": "governance_audit_rels_brand_voices_fk", + "tableFrom": "governance_audit_rels", + "tableTo": "brand_voices", + "columnsFrom": [ + "brand_voices_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "governance_audit_rels_evidence_sources_fk": { + "name": "governance_audit_rels_evidence_sources_fk", + "tableFrom": "governance_audit_rels", + "tableTo": "evidence_sources", + "columnsFrom": [ + "evidence_sources_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "governance_audit_rels_icps_fk": { + "name": "governance_audit_rels_icps_fk", + "tableFrom": "governance_audit_rels", + "tableTo": "icps", + "columnsFrom": [ + "icps_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.evidence_sources": { + "name": "evidence_sources", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "quality_class": { + "name": "quality_class", + "type": "enum_evidence_sources_quality_class", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "evidence_sources_domain_idx": { + "name": "evidence_sources_domain_idx", + "columns": [ + { + "expression": "domain", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_sources_updated_at_idx": { + "name": "evidence_sources_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_sources_created_at_idx": { + "name": "evidence_sources_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.evidence_source_candidates": { + "name": "evidence_source_candidates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "enum_evidence_source_candidates_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "suggested_class": { + "name": "suggested_class", + "type": "enum_evidence_source_candidates_suggested_class", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "citation_count": { + "name": "citation_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "serp_count": { + "name": "serp_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "domain_rating": { + "name": "domain_rating", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "first_seen_at": { + "name": "first_seen_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "sightings": { + "name": "sightings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "resolved_source_id": { + "name": "resolved_source_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "resolved_at": { + "name": "resolved_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "resolved_by": { + "name": "resolved_by", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "evidence_source_candidates_domain_idx": { + "name": "evidence_source_candidates_domain_idx", + "columns": [ + { + "expression": "domain", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_source_candidates_status_idx": { + "name": "evidence_source_candidates_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_source_candidates_last_seen_at_idx": { + "name": "evidence_source_candidates_last_seen_at_idx", + "columns": [ + { + "expression": "last_seen_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_source_candidates_resolved_source_idx": { + "name": "evidence_source_candidates_resolved_source_idx", + "columns": [ + { + "expression": "resolved_source_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_source_candidates_updated_at_idx": { + "name": "evidence_source_candidates_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_source_candidates_created_at_idx": { + "name": "evidence_source_candidates_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "evidence_source_candidates_resolved_source_id_evidence_sources_id_fk": { + "name": "evidence_source_candidates_resolved_source_id_evidence_sources_id_fk", + "tableFrom": "evidence_source_candidates", + "tableTo": "evidence_sources", + "columnsFrom": [ + "resolved_source_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.corpus_snapshots_pages": { + "name": "corpus_snapshots_pages", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "position": { + "name": "position", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "url": { + "name": "url", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "domain": { + "name": "domain", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "domain_rating": { + "name": "domain_rating", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "fetch_status": { + "name": "fetch_status", + "type": "enum_corpus_snapshots_pages_fetch_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "failure_reason": { + "name": "failure_reason", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "chars": { + "name": "chars", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "text_hash": { + "name": "text_hash", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "claim_count": { + "name": "claim_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "unverified_excerpt_count": { + "name": "unverified_excerpt_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "corpus_snapshots_pages_order_idx": { + "name": "corpus_snapshots_pages_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "corpus_snapshots_pages_parent_id_idx": { + "name": "corpus_snapshots_pages_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "corpus_snapshots_pages_parent_id_fk": { + "name": "corpus_snapshots_pages_parent_id_fk", + "tableFrom": "corpus_snapshots_pages", + "tableTo": "corpus_snapshots", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.corpus_snapshots_internal_corpus": { + "name": "corpus_snapshots_internal_corpus", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "article_id": { + "name": "article_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "article_updated_at": { + "name": "article_updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true + }, + "claim_count": { + "name": "claim_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "corpus_snapshots_internal_corpus_order_idx": { + "name": "corpus_snapshots_internal_corpus_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "corpus_snapshots_internal_corpus_parent_id_idx": { + "name": "corpus_snapshots_internal_corpus_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "corpus_snapshots_internal_corpus_article_idx": { + "name": "corpus_snapshots_internal_corpus_article_idx", + "columns": [ + { + "expression": "article_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "corpus_snapshots_internal_corpus_article_id_articles_id_fk": { + "name": "corpus_snapshots_internal_corpus_article_id_articles_id_fk", + "tableFrom": "corpus_snapshots_internal_corpus", + "tableTo": "articles", + "columnsFrom": [ + "article_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "corpus_snapshots_internal_corpus_parent_id_fk": { + "name": "corpus_snapshots_internal_corpus_parent_id_fk", + "tableFrom": "corpus_snapshots_internal_corpus", + "tableTo": "corpus_snapshots", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.corpus_snapshots": { + "name": "corpus_snapshots", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "keyword": { + "name": "keyword", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "keyword_key": { + "name": "keyword_key", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "country": { + "name": "country", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "captured_at": { + "name": "captured_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "enum_corpus_snapshots_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "pipeline_run_id": { + "name": "pipeline_run_id", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "snapshot_hash": { + "name": "snapshot_hash", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "models": { + "name": "models", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "query_cluster": { + "name": "query_cluster", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "baseline_claims": { + "name": "baseline_claims", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "facets": { + "name": "facets", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "gaps": { + "name": "gaps", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "baseline_doc_count": { + "name": "baseline_doc_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "failed_page_count": { + "name": "failed_page_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "corpus_snapshots_keyword_idx": { + "name": "corpus_snapshots_keyword_idx", + "columns": [ + { + "expression": "keyword", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "corpus_snapshots_keyword_key_idx": { + "name": "corpus_snapshots_keyword_key_idx", + "columns": [ + { + "expression": "keyword_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "corpus_snapshots_pipeline_run_id_idx": { + "name": "corpus_snapshots_pipeline_run_id_idx", + "columns": [ + { + "expression": "pipeline_run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "corpus_snapshots_updated_at_idx": { + "name": "corpus_snapshots_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "corpus_snapshots_created_at_idx": { + "name": "corpus_snapshots_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.topic_searches": { + "name": "topic_searches", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "relevance": { + "name": "relevance", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "relevance_fingerprint": { + "name": "relevance_fingerprint", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "relevance_model": { + "name": "relevance_model", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "seed": { + "name": "seed", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "seed_key": { + "name": "seed_key", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "country": { + "name": "country", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "fetched_at": { + "name": "fetched_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true + }, + "result_count": { + "name": "result_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "candidates": { + "name": "candidates", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "topic_searches_seed_key_idx": { + "name": "topic_searches_seed_key_idx", + "columns": [ + { + "expression": "seed_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "topic_searches_fetched_at_idx": { + "name": "topic_searches_fetched_at_idx", + "columns": [ + { + "expression": "fetched_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "topic_searches_updated_at_idx": { + "name": "topic_searches_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "topic_searches_created_at_idx": { + "name": "topic_searches_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.information_gain_runs": { + "name": "information_gain_runs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "article_id": { + "name": "article_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "pipeline_run_id": { + "name": "pipeline_run_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "snapshot_id": { + "name": "snapshot_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "policy_version": { + "name": "policy_version", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "policy": { + "name": "policy", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "models": { + "name": "models", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "decision": { + "name": "decision", + "type": "enum_information_gain_runs_decision", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "reasons": { + "name": "reasons", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "baseline_available": { + "name": "baseline_available", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "calibrated": { + "name": "calibrated", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "scores_consensus_coverage": { + "name": "scores_consensus_coverage", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "scores_potential_gain_units": { + "name": "scores_potential_gain_units", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "scores_verified_gain_units": { + "name": "scores_verified_gain_units", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "scores_verification_ratio": { + "name": "scores_verification_ratio", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "scores_verified_gain_density": { + "name": "scores_verified_gain_density", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "scores_facet_gain_coverage": { + "name": "scores_facet_gain_coverage", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "scores_internal_duplication_rate": { + "name": "scores_internal_duplication_rate", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "claim_summary_total_claims": { + "name": "claim_summary_total_claims", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "claim_summary_materially_novel_claims": { + "name": "claim_summary_materially_novel_claims", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "claim_summary_verified_novel_claims": { + "name": "claim_summary_verified_novel_claims", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "claim_summary_unsupported_novel_claims": { + "name": "claim_summary_unsupported_novel_claims", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "claim_summary_contradictory_claims": { + "name": "claim_summary_contradictory_claims", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "claim_summary_first_party_claims": { + "name": "claim_summary_first_party_claims", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "claim_ids_blocked": { + "name": "claim_ids_blocked", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "claim_ids_review": { + "name": "claim_ids_review", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "claim_ids_materially_novel": { + "name": "claim_ids_materially_novel", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "claim_ids_verified_novel": { + "name": "claim_ids_verified_novel", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "claims": { + "name": "claims", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "token_count": { + "name": "token_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "cost_usd": { + "name": "cost_usd", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "draft_updated_at": { + "name": "draft_updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "information_gain_runs_article_idx": { + "name": "information_gain_runs_article_idx", + "columns": [ + { + "expression": "article_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "information_gain_runs_pipeline_run_id_idx": { + "name": "information_gain_runs_pipeline_run_id_idx", + "columns": [ + { + "expression": "pipeline_run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "information_gain_runs_snapshot_idx": { + "name": "information_gain_runs_snapshot_idx", + "columns": [ + { + "expression": "snapshot_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "information_gain_runs_decision_idx": { + "name": "information_gain_runs_decision_idx", + "columns": [ + { + "expression": "decision", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "information_gain_runs_updated_at_idx": { + "name": "information_gain_runs_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "information_gain_runs_created_at_idx": { + "name": "information_gain_runs_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "information_gain_runs_article_id_articles_id_fk": { + "name": "information_gain_runs_article_id_articles_id_fk", + "tableFrom": "information_gain_runs", + "tableTo": "articles", + "columnsFrom": [ + "article_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "information_gain_runs_snapshot_id_corpus_snapshots_id_fk": { + "name": "information_gain_runs_snapshot_id_corpus_snapshots_id_fk", + "tableFrom": "information_gain_runs", + "tableTo": "corpus_snapshots", + "columnsFrom": [ + "snapshot_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pipeline_runs": { + "name": "pipeline_runs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "enum_pipeline_runs_source", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "enum_pipeline_runs_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "mode": { + "name": "mode", + "type": "enum_pipeline_runs_mode", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "template_id": { + "name": "template_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "requested_count": { + "name": "requested_count", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "config_fingerprint": { + "name": "config_fingerprint", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "config_snapshot": { + "name": "config_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "final_statuses": { + "name": "final_statuses", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "warnings": { + "name": "warnings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error_summary": { + "name": "error_summary", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "requested_by": { + "name": "requested_by", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "started_at": { + "name": "started_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "heartbeat_at": { + "name": "heartbeat_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pipeline_runs_run_id_idx": { + "name": "pipeline_runs_run_id_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pipeline_runs_status_idx": { + "name": "pipeline_runs_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pipeline_runs_template_idx": { + "name": "pipeline_runs_template_idx", + "columns": [ + { + "expression": "template_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pipeline_runs_config_fingerprint_idx": { + "name": "pipeline_runs_config_fingerprint_idx", + "columns": [ + { + "expression": "config_fingerprint", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pipeline_runs_updated_at_idx": { + "name": "pipeline_runs_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pipeline_runs_created_at_idx": { + "name": "pipeline_runs_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pipeline_runs_template_id_templates_id_fk": { + "name": "pipeline_runs_template_id_templates_id_fk", + "tableFrom": "pipeline_runs", + "tableTo": "templates", + "columnsFrom": [ + "template_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pipeline_runs_rels": { + "name": "pipeline_runs_rels", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "order": { + "name": "order", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "parent_id": { + "name": "parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "path": { + "name": "path", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "articles_id": { + "name": "articles_id", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "pipeline_runs_rels_order_idx": { + "name": "pipeline_runs_rels_order_idx", + "columns": [ + { + "expression": "order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pipeline_runs_rels_parent_idx": { + "name": "pipeline_runs_rels_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pipeline_runs_rels_path_idx": { + "name": "pipeline_runs_rels_path_idx", + "columns": [ + { + "expression": "path", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pipeline_runs_rels_articles_id_idx": { + "name": "pipeline_runs_rels_articles_id_idx", + "columns": [ + { + "expression": "articles_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pipeline_runs_rels_parent_fk": { + "name": "pipeline_runs_rels_parent_fk", + "tableFrom": "pipeline_runs_rels", + "tableTo": "pipeline_runs", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pipeline_runs_rels_articles_fk": { + "name": "pipeline_runs_rels_articles_fk", + "tableFrom": "pipeline_runs_rels", + "tableTo": "articles", + "columnsFrom": [ + "articles_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_kv": { + "name": "payload_kv", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "key": { + "name": "key", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "payload_kv_key_idx": { + "name": "payload_kv_key_idx", + "columns": [ + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_jobs_log": { + "name": "payload_jobs_log", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "executed_at": { + "name": "executed_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true + }, + "task_slug": { + "name": "task_slug", + "type": "enum_payload_jobs_log_task_slug", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "task_i_d": { + "name": "task_i_d", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "input": { + "name": "input", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "output": { + "name": "output", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "state": { + "name": "state", + "type": "enum_payload_jobs_log_state", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "error": { + "name": "error", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "payload_jobs_log_order_idx": { + "name": "payload_jobs_log_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_log_parent_id_idx": { + "name": "payload_jobs_log_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "payload_jobs_log_parent_id_fk": { + "name": "payload_jobs_log_parent_id_fk", + "tableFrom": "payload_jobs_log", + "tableTo": "payload_jobs", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_jobs": { + "name": "payload_jobs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "input": { + "name": "input", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "total_tried": { + "name": "total_tried", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "has_error": { + "name": "has_error", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "error": { + "name": "error", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "task_slug": { + "name": "task_slug", + "type": "enum_payload_jobs_task_slug", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "queue": { + "name": "queue", + "type": "varchar", + "primaryKey": false, + "notNull": false, + "default": "'default'" + }, + "wait_until": { + "name": "wait_until", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "processing": { + "name": "processing", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "concurrency_key": { + "name": "concurrency_key", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "meta": { + "name": "meta", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "payload_jobs_completed_at_idx": { + "name": "payload_jobs_completed_at_idx", + "columns": [ + { + "expression": "completed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_total_tried_idx": { + "name": "payload_jobs_total_tried_idx", + "columns": [ + { + "expression": "total_tried", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_has_error_idx": { + "name": "payload_jobs_has_error_idx", + "columns": [ + { + "expression": "has_error", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_task_slug_idx": { + "name": "payload_jobs_task_slug_idx", + "columns": [ + { + "expression": "task_slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_queue_idx": { + "name": "payload_jobs_queue_idx", + "columns": [ + { + "expression": "queue", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_wait_until_idx": { + "name": "payload_jobs_wait_until_idx", + "columns": [ + { + "expression": "wait_until", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_processing_idx": { + "name": "payload_jobs_processing_idx", + "columns": [ + { + "expression": "processing", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_concurrency_key_idx": { + "name": "payload_jobs_concurrency_key_idx", + "columns": [ + { + "expression": "concurrency_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_updated_at_idx": { + "name": "payload_jobs_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_created_at_idx": { + "name": "payload_jobs_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_locked_documents": { + "name": "payload_locked_documents", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "global_slug": { + "name": "global_slug", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "payload_locked_documents_global_slug_idx": { + "name": "payload_locked_documents_global_slug_idx", + "columns": [ + { + "expression": "global_slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_updated_at_idx": { + "name": "payload_locked_documents_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_created_at_idx": { + "name": "payload_locked_documents_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_locked_documents_rels": { + "name": "payload_locked_documents_rels", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "order": { + "name": "order", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "parent_id": { + "name": "parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "path": { + "name": "path", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "setup_suggestions_id": { + "name": "setup_suggestions_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "users_id": { + "name": "users_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "media_id": { + "name": "media_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "templates_id": { + "name": "templates_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "articles_id": { + "name": "articles_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "cost_log_id": { + "name": "cost_log_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "article_audit_id": { + "name": "article_audit_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "brand_voices_id": { + "name": "brand_voices_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "brand_voice_files_id": { + "name": "brand_voice_files_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "icps_id": { + "name": "icps_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "governance_audit_id": { + "name": "governance_audit_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evidence_sources_id": { + "name": "evidence_sources_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evidence_source_candidates_id": { + "name": "evidence_source_candidates_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "corpus_snapshots_id": { + "name": "corpus_snapshots_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "topic_searches_id": { + "name": "topic_searches_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "information_gain_runs_id": { + "name": "information_gain_runs_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "pipeline_runs_id": { + "name": "pipeline_runs_id", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "payload_locked_documents_rels_order_idx": { + "name": "payload_locked_documents_rels_order_idx", + "columns": [ + { + "expression": "order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_parent_idx": { + "name": "payload_locked_documents_rels_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_path_idx": { + "name": "payload_locked_documents_rels_path_idx", + "columns": [ + { + "expression": "path", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_setup_suggestions_id_idx": { + "name": "payload_locked_documents_rels_setup_suggestions_id_idx", + "columns": [ + { + "expression": "setup_suggestions_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_users_id_idx": { + "name": "payload_locked_documents_rels_users_id_idx", + "columns": [ + { + "expression": "users_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_media_id_idx": { + "name": "payload_locked_documents_rels_media_id_idx", + "columns": [ + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_templates_id_idx": { + "name": "payload_locked_documents_rels_templates_id_idx", + "columns": [ + { + "expression": "templates_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_articles_id_idx": { + "name": "payload_locked_documents_rels_articles_id_idx", + "columns": [ + { + "expression": "articles_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_cost_log_id_idx": { + "name": "payload_locked_documents_rels_cost_log_id_idx", + "columns": [ + { + "expression": "cost_log_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_article_audit_id_idx": { + "name": "payload_locked_documents_rels_article_audit_id_idx", + "columns": [ + { + "expression": "article_audit_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_brand_voices_id_idx": { + "name": "payload_locked_documents_rels_brand_voices_id_idx", + "columns": [ + { + "expression": "brand_voices_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_brand_voice_files_id_idx": { + "name": "payload_locked_documents_rels_brand_voice_files_id_idx", + "columns": [ + { + "expression": "brand_voice_files_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_icps_id_idx": { + "name": "payload_locked_documents_rels_icps_id_idx", + "columns": [ + { + "expression": "icps_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_governance_audit_id_idx": { + "name": "payload_locked_documents_rels_governance_audit_id_idx", + "columns": [ + { + "expression": "governance_audit_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_evidence_sources_id_idx": { + "name": "payload_locked_documents_rels_evidence_sources_id_idx", + "columns": [ + { + "expression": "evidence_sources_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_evidence_source_candidates_idx": { + "name": "payload_locked_documents_rels_evidence_source_candidates_idx", + "columns": [ + { + "expression": "evidence_source_candidates_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_corpus_snapshots_id_idx": { + "name": "payload_locked_documents_rels_corpus_snapshots_id_idx", + "columns": [ + { + "expression": "corpus_snapshots_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_topic_searches_id_idx": { + "name": "payload_locked_documents_rels_topic_searches_id_idx", + "columns": [ + { + "expression": "topic_searches_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_information_gain_runs_id_idx": { + "name": "payload_locked_documents_rels_information_gain_runs_id_idx", + "columns": [ + { + "expression": "information_gain_runs_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_pipeline_runs_id_idx": { + "name": "payload_locked_documents_rels_pipeline_runs_id_idx", + "columns": [ + { + "expression": "pipeline_runs_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "payload_locked_documents_rels_parent_fk": { + "name": "payload_locked_documents_rels_parent_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "payload_locked_documents", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_setup_suggestions_fk": { + "name": "payload_locked_documents_rels_setup_suggestions_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "setup_suggestions", + "columnsFrom": [ + "setup_suggestions_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_users_fk": { + "name": "payload_locked_documents_rels_users_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "users", + "columnsFrom": [ + "users_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_media_fk": { + "name": "payload_locked_documents_rels_media_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_templates_fk": { + "name": "payload_locked_documents_rels_templates_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "templates", + "columnsFrom": [ + "templates_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_articles_fk": { + "name": "payload_locked_documents_rels_articles_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "articles", + "columnsFrom": [ + "articles_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_cost_log_fk": { + "name": "payload_locked_documents_rels_cost_log_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "cost_log", + "columnsFrom": [ + "cost_log_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_article_audit_fk": { + "name": "payload_locked_documents_rels_article_audit_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "article_audit", + "columnsFrom": [ + "article_audit_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_brand_voices_fk": { + "name": "payload_locked_documents_rels_brand_voices_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "brand_voices", + "columnsFrom": [ + "brand_voices_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_brand_voice_files_fk": { + "name": "payload_locked_documents_rels_brand_voice_files_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "brand_voice_files", + "columnsFrom": [ + "brand_voice_files_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_icps_fk": { + "name": "payload_locked_documents_rels_icps_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "icps", + "columnsFrom": [ + "icps_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_governance_audit_fk": { + "name": "payload_locked_documents_rels_governance_audit_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "governance_audit", + "columnsFrom": [ + "governance_audit_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_evidence_sources_fk": { + "name": "payload_locked_documents_rels_evidence_sources_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "evidence_sources", + "columnsFrom": [ + "evidence_sources_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_evidence_source_candidates_fk": { + "name": "payload_locked_documents_rels_evidence_source_candidates_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "evidence_source_candidates", + "columnsFrom": [ + "evidence_source_candidates_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_corpus_snapshots_fk": { + "name": "payload_locked_documents_rels_corpus_snapshots_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "corpus_snapshots", + "columnsFrom": [ + "corpus_snapshots_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_topic_searches_fk": { + "name": "payload_locked_documents_rels_topic_searches_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "topic_searches", + "columnsFrom": [ + "topic_searches_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_information_gain_runs_fk": { + "name": "payload_locked_documents_rels_information_gain_runs_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "information_gain_runs", + "columnsFrom": [ + "information_gain_runs_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_pipeline_runs_fk": { + "name": "payload_locked_documents_rels_pipeline_runs_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "pipeline_runs", + "columnsFrom": [ + "pipeline_runs_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_preferences": { + "name": "payload_preferences", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "key": { + "name": "key", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "value": { + "name": "value", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "payload_preferences_key_idx": { + "name": "payload_preferences_key_idx", + "columns": [ + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_preferences_updated_at_idx": { + "name": "payload_preferences_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_preferences_created_at_idx": { + "name": "payload_preferences_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_preferences_rels": { + "name": "payload_preferences_rels", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "order": { + "name": "order", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "parent_id": { + "name": "parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "path": { + "name": "path", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "users_id": { + "name": "users_id", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "payload_preferences_rels_order_idx": { + "name": "payload_preferences_rels_order_idx", + "columns": [ + { + "expression": "order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_preferences_rels_parent_idx": { + "name": "payload_preferences_rels_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_preferences_rels_path_idx": { + "name": "payload_preferences_rels_path_idx", + "columns": [ + { + "expression": "path", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_preferences_rels_users_id_idx": { + "name": "payload_preferences_rels_users_id_idx", + "columns": [ + { + "expression": "users_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "payload_preferences_rels_parent_fk": { + "name": "payload_preferences_rels_parent_fk", + "tableFrom": "payload_preferences_rels", + "tableTo": "payload_preferences", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_preferences_rels_users_fk": { + "name": "payload_preferences_rels_users_fk", + "tableFrom": "payload_preferences_rels", + "tableTo": "users", + "columnsFrom": [ + "users_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_migrations": { + "name": "payload_migrations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "batch": { + "name": "batch", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "payload_migrations_updated_at_idx": { + "name": "payload_migrations_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_migrations_created_at_idx": { + "name": "payload_migrations_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.setup_suggestion_scan": { + "name": "setup_suggestion_scan", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "audit_cursor": { + "name": "audit_cursor", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "audit_cursor_id": { + "name": "audit_cursor_id", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_profile_competitors": { + "name": "workspace_profile_competitors", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "workspace_profile_competitors_order_idx": { + "name": "workspace_profile_competitors_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_profile_competitors_parent_id_idx": { + "name": "workspace_profile_competitors_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workspace_profile_competitors_parent_id_fk": { + "name": "workspace_profile_competitors_parent_id_fk", + "tableFrom": "workspace_profile_competitors", + "tableTo": "workspace_profile", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_profile": { + "name": "workspace_profile", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_name": { + "name": "company_name", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "target_domain": { + "name": "target_domain", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "site_notes": { + "name": "site_notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "site_pages": { + "name": "site_pages", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "site_pages_fetched_at": { + "name": "site_pages_fetched_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.positioning_core_claims": { + "name": "positioning_core_claims", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "claim": { + "name": "claim", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "evidence_ref": { + "name": "evidence_ref", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "positioning_core_claims_order_idx": { + "name": "positioning_core_claims_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "positioning_core_claims_parent_id_idx": { + "name": "positioning_core_claims_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "positioning_core_claims_parent_id_fk": { + "name": "positioning_core_claims_parent_id_fk", + "tableFrom": "positioning_core_claims", + "tableTo": "positioning", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.positioning_pillars": { + "name": "positioning_pillars", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "one_line": { + "name": "one_line", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "carries": { + "name": "carries", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "positioning_pillars_order_idx": { + "name": "positioning_pillars_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "positioning_pillars_parent_id_idx": { + "name": "positioning_pillars_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "positioning_pillars_parent_id_fk": { + "name": "positioning_pillars_parent_id_fk", + "tableFrom": "positioning_pillars", + "tableTo": "positioning", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.positioning_descriptor_ladder": { + "name": "positioning_descriptor_ladder", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "descriptor": { + "name": "descriptor", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "positioning_descriptor_ladder_order_idx": { + "name": "positioning_descriptor_ladder_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "positioning_descriptor_ladder_parent_id_idx": { + "name": "positioning_descriptor_ladder_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "positioning_descriptor_ladder_parent_id_fk": { + "name": "positioning_descriptor_ladder_parent_id_fk", + "tableFrom": "positioning_descriptor_ladder", + "tableTo": "positioning", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.positioning_vocabulary_reach_for": { + "name": "positioning_vocabulary_reach_for", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "term": { + "name": "term", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "positioning_vocabulary_reach_for_order_idx": { + "name": "positioning_vocabulary_reach_for_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "positioning_vocabulary_reach_for_parent_id_idx": { + "name": "positioning_vocabulary_reach_for_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "positioning_vocabulary_reach_for_parent_id_fk": { + "name": "positioning_vocabulary_reach_for_parent_id_fk", + "tableFrom": "positioning_vocabulary_reach_for", + "tableTo": "positioning", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.positioning_vocabulary_avoid": { + "name": "positioning_vocabulary_avoid", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "term": { + "name": "term", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "positioning_vocabulary_avoid_order_idx": { + "name": "positioning_vocabulary_avoid_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "positioning_vocabulary_avoid_parent_id_idx": { + "name": "positioning_vocabulary_avoid_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "positioning_vocabulary_avoid_parent_id_fk": { + "name": "positioning_vocabulary_avoid_parent_id_fk", + "tableFrom": "positioning_vocabulary_avoid", + "tableTo": "positioning", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.positioning_open_rulings": { + "name": "positioning_open_rulings", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "question": { + "name": "question", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "enum_positioning_open_rulings_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'open'" + }, + "ruling": { + "name": "ruling", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "ruled_at": { + "name": "ruled_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "positioning_open_rulings_order_idx": { + "name": "positioning_open_rulings_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "positioning_open_rulings_parent_id_idx": { + "name": "positioning_open_rulings_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "positioning_open_rulings_parent_id_fk": { + "name": "positioning_open_rulings_parent_id_fk", + "tableFrom": "positioning_open_rulings", + "tableTo": "positioning", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.positioning": { + "name": "positioning", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "category": { + "name": "category", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "goal": { + "name": "goal", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "promise": { + "name": "promise", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "active_position": { + "name": "active_position", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "statement": { + "name": "statement", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "macro_frame": { + "name": "macro_frame", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "landscape": { + "name": "landscape", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "enemy": { + "name": "enemy", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "archetype": { + "name": "archetype", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "essence": { + "name": "essence", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.evidence_bank_verified_claims_cleared_surfaces": { + "name": "evidence_bank_verified_claims_cleared_surfaces", + "schema": "", + "columns": { + "order": { + "name": "order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "parent_id": { + "name": "parent_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "enum_evidence_bank_verified_claims_cleared_surfaces", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + } + }, + "indexes": { + "evidence_bank_verified_claims_cleared_surfaces_order_idx": { + "name": "evidence_bank_verified_claims_cleared_surfaces_order_idx", + "columns": [ + { + "expression": "order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_bank_verified_claims_cleared_surfaces_parent_idx": { + "name": "evidence_bank_verified_claims_cleared_surfaces_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "evidence_bank_verified_claims_cleared_surfaces_parent_fk": { + "name": "evidence_bank_verified_claims_cleared_surfaces_parent_fk", + "tableFrom": "evidence_bank_verified_claims_cleared_surfaces", + "tableTo": "evidence_bank_verified_claims", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.evidence_bank_verified_claims": { + "name": "evidence_bank_verified_claims", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "ref": { + "name": "ref", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "claim": { + "name": "claim", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "primary_source": { + "name": "primary_source", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "source_url": { + "name": "source_url", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "source_date": { + "name": "source_date", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "sample_or_method": { + "name": "sample_or_method", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "verification_depth": { + "name": "verification_depth", + "type": "enum_evidence_bank_verified_claims_verification_depth", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "limits": { + "name": "limits", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "recheck_at": { + "name": "recheck_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "evidence_bank_verified_claims_order_idx": { + "name": "evidence_bank_verified_claims_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_bank_verified_claims_parent_id_idx": { + "name": "evidence_bank_verified_claims_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "evidence_bank_verified_claims_parent_id_fk": { + "name": "evidence_bank_verified_claims_parent_id_fk", + "tableFrom": "evidence_bank_verified_claims", + "tableTo": "evidence_bank", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.evidence_bank_facts": { + "name": "evidence_bank_facts", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "ref": { + "name": "ref", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "fact": { + "name": "fact", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "owner": { + "name": "owner", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "last_confirmed_at": { + "name": "last_confirmed_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "evidence_bank_facts_order_idx": { + "name": "evidence_bank_facts_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_bank_facts_parent_id_idx": { + "name": "evidence_bank_facts_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "evidence_bank_facts_parent_id_fk": { + "name": "evidence_bank_facts_parent_id_fk", + "tableFrom": "evidence_bank_facts", + "tableTo": "evidence_bank", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.evidence_bank_rejected_claims": { + "name": "evidence_bank_rejected_claims", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "ref": { + "name": "ref", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "claim": { + "name": "claim", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "enum_evidence_bank_rejected_claims_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'rejected'" + }, + "reason": { + "name": "reason", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "replacement": { + "name": "replacement", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "evidence_bank_rejected_claims_order_idx": { + "name": "evidence_bank_rejected_claims_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_bank_rejected_claims_parent_id_idx": { + "name": "evidence_bank_rejected_claims_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "evidence_bank_rejected_claims_parent_id_fk": { + "name": "evidence_bank_rejected_claims_parent_id_fk", + "tableFrom": "evidence_bank_rejected_claims", + "tableTo": "evidence_bank", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.evidence_bank": { + "name": "evidence_bank", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "ref_counter": { + "name": "ref_counter", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "notes": { + "name": "notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.llm_settings": { + "name": "llm_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "generate_model": { + "name": "generate_model", + "type": "enum_llm_settings_generate_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "fact_check_model": { + "name": "fact_check_model", + "type": "enum_llm_settings_fact_check_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "qualitative_review_model": { + "name": "qualitative_review_model", + "type": "enum_llm_settings_qualitative_review_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "claim_extraction_model": { + "name": "claim_extraction_model", + "type": "enum_llm_settings_claim_extraction_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "information_gain_judge_model": { + "name": "information_gain_judge_model", + "type": "enum_llm_settings_information_gain_judge_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "evidence_verification_model": { + "name": "evidence_verification_model", + "type": "enum_llm_settings_evidence_verification_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "evidence_check_model": { + "name": "evidence_check_model", + "type": "enum_llm_settings_evidence_check_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "brief_angle_model": { + "name": "brief_angle_model", + "type": "enum_llm_settings_brief_angle_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "topic_relevance_model": { + "name": "topic_relevance_model", + "type": "enum_llm_settings_topic_relevance_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "brand_voice_extract_model": { + "name": "brand_voice_extract_model", + "type": "enum_llm_settings_brand_voice_extract_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "setup_assist_model": { + "name": "setup_assist_model", + "type": "enum_llm_settings_setup_assist_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.information_gain_policy": { + "name": "information_gain_policy", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "min_consensus_coverage": { + "name": "min_consensus_coverage", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "min_verification_ratio": { + "name": "min_verification_ratio", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "min_novel_factual_integrity": { + "name": "min_novel_factual_integrity", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "min_numeric_temporal_integrity": { + "name": "min_numeric_temporal_integrity", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "require_exact_value_match": { + "name": "require_exact_value_match", + "type": "enum_information_gain_policy_require_exact_value_match", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "require_evidence_lineage": { + "name": "require_evidence_lineage", + "type": "enum_information_gain_policy_require_evidence_lineage", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "block_first_party_measurements": { + "name": "block_first_party_measurements", + "type": "enum_information_gain_policy_block_first_party_measurements", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "max_contradiction_probability": { + "name": "max_contradiction_probability", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "material_novelty_threshold": { + "name": "material_novelty_threshold", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "max_internal_duplication_rate": { + "name": "max_internal_duplication_rate", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "min_verified_novel_claims": { + "name": "min_verified_novel_claims", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.webhook_settings": { + "name": "webhook_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "url": { + "name": "url", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "secret": { + "name": "secret", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_jobs_stats": { + "name": "payload_jobs_stats", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "stats": { + "name": "stats", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.enum_setup_suggestions_kind": { + "name": "enum_setup_suggestions_kind", + "schema": "public", + "values": [ + "banned_word", + "not_trait", + "unbacked_claim", + "rejected_ref" + ] + }, + "public.enum_setup_suggestions_target": { + "name": "enum_setup_suggestions_target", + "schema": "public", + "values": [ + "brand-voice", + "evidence-bank" + ] + }, + "public.enum_setup_suggestions_status": { + "name": "enum_setup_suggestions_status", + "schema": "public", + "values": [ + "open", + "accepted", + "dismissed", + "obsolete" + ] + }, + "public.enum_templates_company_mentions": { + "name": "enum_templates_company_mentions", + "schema": "public", + "values": [ + "none", + "mention", + "feature" + ] + }, + "public.enum_articles_brief_sections_source": { + "name": "enum_articles_brief_sections_source", + "schema": "public", + "values": [ + "template", + "research", + "editor" + ] + }, + "public.enum_articles_status": { + "name": "enum_articles_status", + "schema": "public", + "values": [ + "topic_selected", + "brief_review", + "researched", + "drafted", + "qa_passed", + "verified", + "needs_review", + "blocked", + "needs_revision", + "approved", + "published" + ] + }, + "public.enum_articles_information_gain_decision": { + "name": "enum_articles_information_gain_decision", + "schema": "public", + "values": [ + "PASS", + "REVISE", + "HUMAN_REVIEW", + "BLOCK" + ] + }, + "public.enum_cost_log_stage": { + "name": "enum_cost_log_stage", + "schema": "public", + "values": [ + "generate", + "factCheck", + "qualitativeReview", + "claimExtraction", + "informationGainJudge", + "evidenceVerification", + "evidenceCheck", + "briefAngle", + "brandVoiceExtract", + "setupAssist", + "topicRelevance" + ] + }, + "public.enum_article_audit_actor_type": { + "name": "enum_article_audit_actor_type", + "schema": "public", + "values": [ + "pipeline", + "user", + "system" + ] + }, + "public.enum_brand_voices_status": { + "name": "enum_brand_voices_status", + "schema": "public", + "values": [ + "draft", + "active", + "archived" + ] + }, + "public.enum_brand_voices_source": { + "name": "enum_brand_voices_source", + "schema": "public", + "values": [ + "onboarding", + "upload" + ] + }, + "public.enum_brand_voices_audience_language_level": { + "name": "enum_brand_voices_audience_language_level", + "schema": "public", + "values": [ + "plain", + "general", + "professional", + "expert" + ] + }, + "public.enum_icps_pains_confidence": { + "name": "enum_icps_pains_confidence", + "schema": "public", + "values": [ + "verified", + "strong_directional", + "qualitative_pattern", + "cultural_signal", + "inference", + "hypothesis" + ] + }, + "public.enum_icps_competition_confidence": { + "name": "enum_icps_competition_confidence", + "schema": "public", + "values": [ + "verified", + "strong_directional", + "qualitative_pattern", + "cultural_signal", + "inference", + "hypothesis" + ] + }, + "public.enum_icps_channels_confidence": { + "name": "enum_icps_channels_confidence", + "schema": "public", + "values": [ + "verified", + "strong_directional", + "qualitative_pattern", + "cultural_signal", + "inference", + "hypothesis" + ] + }, + "public.enum_icps_status": { + "name": "enum_icps_status", + "schema": "public", + "values": [ + "draft", + "active", + "archived" + ] + }, + "public.enum_icps_motivation_confidence": { + "name": "enum_icps_motivation_confidence", + "schema": "public", + "values": [ + "verified", + "strong_directional", + "qualitative_pattern", + "cultural_signal", + "inference", + "hypothesis" + ] + }, + "public.enum_icps_solution_confidence": { + "name": "enum_icps_solution_confidence", + "schema": "public", + "values": [ + "verified", + "strong_directional", + "qualitative_pattern", + "cultural_signal", + "inference", + "hypothesis" + ] + }, + "public.enum_icps_why_us_confidence": { + "name": "enum_icps_why_us_confidence", + "schema": "public", + "values": [ + "verified", + "strong_directional", + "qualitative_pattern", + "cultural_signal", + "inference", + "hypothesis" + ] + }, + "public.enum_governance_audit_actor_type": { + "name": "enum_governance_audit_actor_type", + "schema": "public", + "values": [ + "pipeline", + "user", + "system" + ] + }, + "public.enum_evidence_sources_quality_class": { + "name": "enum_evidence_sources_quality_class", + "schema": "public", + "values": [ + "first_party_dataset", + "primary", + "official_docs", + "secondary", + "unverified", + "blocked" + ] + }, + "public.enum_evidence_source_candidates_status": { + "name": "enum_evidence_source_candidates_status", + "schema": "public", + "values": [ + "pending", + "approved", + "dismissed" + ] + }, + "public.enum_evidence_source_candidates_suggested_class": { + "name": "enum_evidence_source_candidates_suggested_class", + "schema": "public", + "values": [ + "primary", + "official_docs", + "secondary", + "unverified" + ] + }, + "public.enum_corpus_snapshots_pages_fetch_status": { + "name": "enum_corpus_snapshots_pages_fetch_status", + "schema": "public", + "values": [ + "ok", + "failed", + "skipped" + ] + }, + "public.enum_corpus_snapshots_status": { + "name": "enum_corpus_snapshots_status", + "schema": "public", + "values": [ + "complete", + "partial", + "empty" + ] + }, + "public.enum_information_gain_runs_decision": { + "name": "enum_information_gain_runs_decision", + "schema": "public", + "values": [ + "PASS", + "REVISE", + "HUMAN_REVIEW", + "BLOCK" + ] + }, + "public.enum_pipeline_runs_source": { + "name": "enum_pipeline_runs_source", + "schema": "public", + "values": [ + "admin", + "cli", + "selected" + ] + }, + "public.enum_pipeline_runs_status": { + "name": "enum_pipeline_runs_status", + "schema": "public", + "values": [ + "queued", + "running", + "succeeded", + "failed" + ] + }, + "public.enum_pipeline_runs_mode": { + "name": "enum_pipeline_runs_mode", + "schema": "public", + "values": [ + "mock", + "live" + ] + }, + "public.enum_payload_jobs_log_task_slug": { + "name": "enum_payload_jobs_log_task_slug", + "schema": "public", + "values": [ + "inline", + "content-run", + "webhook-deliver", + "publish-due", + "recover-stale-runs", + "collect-setup-suggestions" + ] + }, + "public.enum_payload_jobs_log_state": { + "name": "enum_payload_jobs_log_state", + "schema": "public", + "values": [ + "failed", + "succeeded" + ] + }, + "public.enum_payload_jobs_task_slug": { + "name": "enum_payload_jobs_task_slug", + "schema": "public", + "values": [ + "inline", + "content-run", + "webhook-deliver", + "publish-due", + "recover-stale-runs", + "collect-setup-suggestions" + ] + }, + "public.enum_positioning_open_rulings_status": { + "name": "enum_positioning_open_rulings_status", + "schema": "public", + "values": [ + "open", + "ruled" + ] + }, + "public.enum_evidence_bank_verified_claims_cleared_surfaces": { + "name": "enum_evidence_bank_verified_claims_cleared_surfaces", + "schema": "public", + "values": [ + "web", + "blog", + "ads", + "sales", + "social", + "pr" + ] + }, + "public.enum_evidence_bank_verified_claims_verification_depth": { + "name": "enum_evidence_bank_verified_claims_verification_depth", + "schema": "public", + "values": [ + "primary_document", + "reproduced", + "third_party_audit", + "self_reported" + ] + }, + "public.enum_evidence_bank_rejected_claims_status": { + "name": "enum_evidence_bank_rejected_claims_status", + "schema": "public", + "values": [ + "rejected", + "expired" + ] + }, + "public.enum_llm_settings_generate_model": { + "name": "enum_llm_settings_generate_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_fact_check_model": { + "name": "enum_llm_settings_fact_check_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_qualitative_review_model": { + "name": "enum_llm_settings_qualitative_review_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_claim_extraction_model": { + "name": "enum_llm_settings_claim_extraction_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_information_gain_judge_model": { + "name": "enum_llm_settings_information_gain_judge_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_evidence_verification_model": { + "name": "enum_llm_settings_evidence_verification_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_evidence_check_model": { + "name": "enum_llm_settings_evidence_check_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_brief_angle_model": { + "name": "enum_llm_settings_brief_angle_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_topic_relevance_model": { + "name": "enum_llm_settings_topic_relevance_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_brand_voice_extract_model": { + "name": "enum_llm_settings_brand_voice_extract_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_setup_assist_model": { + "name": "enum_llm_settings_setup_assist_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_information_gain_policy_require_exact_value_match": { + "name": "enum_information_gain_policy_require_exact_value_match", + "schema": "public", + "values": [ + "enabled", + "disabled" + ] + }, + "public.enum_information_gain_policy_require_evidence_lineage": { + "name": "enum_information_gain_policy_require_evidence_lineage", + "schema": "public", + "values": [ + "enabled", + "disabled" + ] + }, + "public.enum_information_gain_policy_block_first_party_measurements": { + "name": "enum_information_gain_policy_block_first_party_measurements", + "schema": "public", + "values": [ + "enabled", + "disabled" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "id": "9f7ca3be-579a-4384-b0cd-f00a8fa81131", + "prevId": "00000000-0000-0000-0000-000000000000" +} \ No newline at end of file diff --git a/cms/src/migrations/20261110_054316_pipeline_run_lease.ts b/cms/src/migrations/20261110_054316_pipeline_run_lease.ts new file mode 100644 index 0000000..a386cd3 --- /dev/null +++ b/cms/src/migrations/20261110_054316_pipeline_run_lease.ts @@ -0,0 +1,29 @@ +import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres' + +export async function up({ db, payload, req }: MigrateUpArgs): Promise { + await db.execute(sql` + ALTER TYPE "public"."enum_payload_jobs_log_task_slug" ADD VALUE 'recover-stale-runs' BEFORE 'collect-setup-suggestions'; + ALTER TYPE "public"."enum_payload_jobs_task_slug" ADD VALUE 'recover-stale-runs' BEFORE 'collect-setup-suggestions'; + ALTER TABLE "pipeline_runs" ALTER COLUMN "template_id" DROP NOT NULL; + ALTER TABLE "pipeline_runs" ADD COLUMN "heartbeat_at" timestamp(3) with time zone;`) +} + +export async function down({ db, payload, req }: MigrateDownArgs): Promise { + // The old enums cannot hold the new task's jobs, and the old NOT NULL cannot + // hold a CLI run, which has no template. Both are removed rather than + // rewritten to something they never were. + await db.execute(sql` + DELETE FROM "payload_jobs" WHERE "task_slug" = 'recover-stale-runs'; + DELETE FROM "payload_jobs_log" WHERE "task_slug" = 'recover-stale-runs'; + DELETE FROM "pipeline_runs" WHERE "template_id" IS NULL; + ALTER TABLE "payload_jobs_log" ALTER COLUMN "task_slug" SET DATA TYPE text; + DROP TYPE "public"."enum_payload_jobs_log_task_slug"; + CREATE TYPE "public"."enum_payload_jobs_log_task_slug" AS ENUM('inline', 'content-run', 'webhook-deliver', 'publish-due', 'collect-setup-suggestions'); + ALTER TABLE "payload_jobs_log" ALTER COLUMN "task_slug" SET DATA TYPE "public"."enum_payload_jobs_log_task_slug" USING "task_slug"::"public"."enum_payload_jobs_log_task_slug"; + ALTER TABLE "payload_jobs" ALTER COLUMN "task_slug" SET DATA TYPE text; + DROP TYPE "public"."enum_payload_jobs_task_slug"; + CREATE TYPE "public"."enum_payload_jobs_task_slug" AS ENUM('inline', 'content-run', 'webhook-deliver', 'publish-due', 'collect-setup-suggestions'); + ALTER TABLE "payload_jobs" ALTER COLUMN "task_slug" SET DATA TYPE "public"."enum_payload_jobs_task_slug" USING "task_slug"::"public"."enum_payload_jobs_task_slug"; + ALTER TABLE "pipeline_runs" ALTER COLUMN "template_id" SET NOT NULL; + ALTER TABLE "pipeline_runs" DROP COLUMN "heartbeat_at";`) +} diff --git a/cms/src/migrations/20261110_055225_article_slug_unique.json b/cms/src/migrations/20261110_055225_article_slug_unique.json new file mode 100644 index 0000000..f0fde38 --- /dev/null +++ b/cms/src/migrations/20261110_055225_article_slug_unique.json @@ -0,0 +1,9785 @@ +{ + "version": "7", + "dialect": "postgresql", + "tables": { + "public.setup_suggestions": { + "name": "setup_suggestions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "enum_setup_suggestions_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'banned_word'" + }, + "signature": { + "name": "signature", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "target": { + "name": "target", + "type": "enum_setup_suggestions_target", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'brand-voice'" + }, + "proposal": { + "name": "proposal", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "occurrences": { + "name": "occurrences", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "count": { + "name": "count", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "status": { + "name": "status", + "type": "enum_setup_suggestions_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'open'" + }, + "first_seen_at": { + "name": "first_seen_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "decided_by": { + "name": "decided_by", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "decided_at": { + "name": "decided_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "decision_reason": { + "name": "decision_reason", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "setup_suggestions_signature_idx": { + "name": "setup_suggestions_signature_idx", + "columns": [ + { + "expression": "signature", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "setup_suggestions_status_idx": { + "name": "setup_suggestions_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "setup_suggestions_updated_at_idx": { + "name": "setup_suggestions_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "setup_suggestions_created_at_idx": { + "name": "setup_suggestions_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users_sessions": { + "name": "users_sessions", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "users_sessions_order_idx": { + "name": "users_sessions_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "users_sessions_parent_id_idx": { + "name": "users_sessions_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "users_sessions_parent_id_fk": { + "name": "users_sessions_parent_id_fk", + "tableFrom": "users_sessions", + "tableTo": "users", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "email": { + "name": "email", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "reset_password_token": { + "name": "reset_password_token", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "reset_password_expiration": { + "name": "reset_password_expiration", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "salt": { + "name": "salt", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "hash": { + "name": "hash", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "reset_password_requested_at": { + "name": "reset_password_requested_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "login_attempts": { + "name": "login_attempts", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "lock_until": { + "name": "lock_until", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "users_updated_at_idx": { + "name": "users_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "users_created_at_idx": { + "name": "users_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "users_email_idx": { + "name": "users_email_idx", + "columns": [ + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media": { + "name": "media", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "alt": { + "name": "alt", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "url": { + "name": "url", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "thumbnail_u_r_l": { + "name": "thumbnail_u_r_l", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "filename": { + "name": "filename", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "mime_type": { + "name": "mime_type", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "filesize": { + "name": "filesize", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "width": { + "name": "width", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "height": { + "name": "height", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "focal_x": { + "name": "focal_x", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "focal_y": { + "name": "focal_y", + "type": "numeric", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "media_updated_at_idx": { + "name": "media_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "media_created_at_idx": { + "name": "media_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "media_filename_idx": { + "name": "media_filename_idx", + "columns": [ + { + "expression": "filename", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.templates_dos": { + "name": "templates_dos", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "templates_dos_order_idx": { + "name": "templates_dos_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "templates_dos_parent_id_idx": { + "name": "templates_dos_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "templates_dos_parent_id_fk": { + "name": "templates_dos_parent_id_fk", + "tableFrom": "templates_dos", + "tableTo": "templates", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.templates_donts": { + "name": "templates_donts", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "templates_donts_order_idx": { + "name": "templates_donts_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "templates_donts_parent_id_idx": { + "name": "templates_donts_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "templates_donts_parent_id_fk": { + "name": "templates_donts_parent_id_fk", + "tableFrom": "templates_donts", + "tableTo": "templates", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.templates_required_sections": { + "name": "templates_required_sections", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "heading": { + "name": "heading", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "templates_required_sections_order_idx": { + "name": "templates_required_sections_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "templates_required_sections_parent_id_idx": { + "name": "templates_required_sections_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "templates_required_sections_parent_id_fk": { + "name": "templates_required_sections_parent_id_fk", + "tableFrom": "templates_required_sections", + "tableTo": "templates", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.templates": { + "name": "templates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "intent": { + "name": "intent", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "company_mentions": { + "name": "company_mentions", + "type": "enum_templates_company_mentions", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'mention'" + }, + "outline": { + "name": "outline", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "example": { + "name": "example", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "seo_spec_title_tag_max_length": { + "name": "seo_spec_title_tag_max_length", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 60 + }, + "seo_spec_meta_description_max_length": { + "name": "seo_spec_meta_description_max_length", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 160 + }, + "seo_spec_heading_structure_rules": { + "name": "seo_spec_heading_structure_rules", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "seo_spec_faq_required": { + "name": "seo_spec_faq_required", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "seo_spec_faq_min_questions": { + "name": "seo_spec_faq_min_questions", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "seo_spec_faq_max_questions": { + "name": "seo_spec_faq_max_questions", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "seo_spec_og_tags_required": { + "name": "seo_spec_og_tags_required", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "templates_name_idx": { + "name": "templates_name_idx", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "templates_updated_at_idx": { + "name": "templates_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "templates_created_at_idx": { + "name": "templates_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.articles_secondary_keywords": { + "name": "articles_secondary_keywords", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "keyword": { + "name": "keyword", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "articles_secondary_keywords_order_idx": { + "name": "articles_secondary_keywords_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_secondary_keywords_parent_id_idx": { + "name": "articles_secondary_keywords_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "articles_secondary_keywords_parent_id_fk": { + "name": "articles_secondary_keywords_parent_id_fk", + "tableFrom": "articles_secondary_keywords", + "tableTo": "articles", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.articles_research_common_subtopics": { + "name": "articles_research_common_subtopics", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "articles_research_common_subtopics_order_idx": { + "name": "articles_research_common_subtopics_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_research_common_subtopics_parent_id_idx": { + "name": "articles_research_common_subtopics_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "articles_research_common_subtopics_parent_id_fk": { + "name": "articles_research_common_subtopics_parent_id_fk", + "tableFrom": "articles_research_common_subtopics", + "tableTo": "articles", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.articles_research_related_questions": { + "name": "articles_research_related_questions", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "articles_research_related_questions_order_idx": { + "name": "articles_research_related_questions_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_research_related_questions_parent_id_idx": { + "name": "articles_research_related_questions_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "articles_research_related_questions_parent_id_fk": { + "name": "articles_research_related_questions_parent_id_fk", + "tableFrom": "articles_research_related_questions", + "tableTo": "articles", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.articles_brief_sections": { + "name": "articles_brief_sections", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "heading": { + "name": "heading", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "notes": { + "name": "notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "enum_articles_brief_sections_source", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "articles_brief_sections_order_idx": { + "name": "articles_brief_sections_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_brief_sections_parent_id_idx": { + "name": "articles_brief_sections_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "articles_brief_sections_parent_id_fk": { + "name": "articles_brief_sections_parent_id_fk", + "tableFrom": "articles_brief_sections", + "tableTo": "articles", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.articles_faq_items": { + "name": "articles_faq_items", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "question": { + "name": "question", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "answer": { + "name": "answer", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "articles_faq_items_order_idx": { + "name": "articles_faq_items_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_faq_items_parent_id_idx": { + "name": "articles_faq_items_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "articles_faq_items_parent_id_fk": { + "name": "articles_faq_items_parent_id_fk", + "tableFrom": "articles_faq_items", + "tableTo": "articles", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.articles": { + "name": "articles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "title": { + "name": "title", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "slug": { + "name": "slug", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "keyword": { + "name": "keyword", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "template_id": { + "name": "template_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "icp_id": { + "name": "icp_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "research_ranking_pages_summary": { + "name": "research_ranking_pages_summary", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "research_snapshot_id": { + "name": "research_snapshot_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "research_query_cluster": { + "name": "research_query_cluster", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "research_facets": { + "name": "research_facets", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "research_gaps": { + "name": "research_gaps", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "brief_angle": { + "name": "brief_angle", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "brief_angle_options": { + "name": "brief_angle_options", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "brief_audience": { + "name": "brief_audience", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "brief_must_cover": { + "name": "brief_must_cover", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "brief_opportunities": { + "name": "brief_opportunities", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "brief_notes": { + "name": "brief_notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "brief_approved_at": { + "name": "brief_approved_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "brief_approved_by": { + "name": "brief_approved_by", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "title_tag": { + "name": "title_tag", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "meta_description": { + "name": "meta_description", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "og_title": { + "name": "og_title", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "og_description": { + "name": "og_description", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "og_image": { + "name": "og_image", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "enum_articles_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'topic_selected'" + }, + "publish_at": { + "name": "publish_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "evidence_citations": { + "name": "evidence_citations", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "qa_results_structural_passed": { + "name": "qa_results_structural_passed", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "qa_results_structural_violations": { + "name": "qa_results_structural_violations", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "qa_results_fact_check_passed": { + "name": "qa_results_fact_check_passed", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "qa_results_fact_check_notes": { + "name": "qa_results_fact_check_notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "qa_results_fact_check_sources": { + "name": "qa_results_fact_check_sources", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "qa_results_qualitative_review_passed": { + "name": "qa_results_qualitative_review_passed", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "qa_results_qualitative_review_notes": { + "name": "qa_results_qualitative_review_notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "qa_results_qualitative_review_voice_score": { + "name": "qa_results_qualitative_review_voice_score", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "qa_results_qualitative_review_voice_notes": { + "name": "qa_results_qualitative_review_voice_notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "qa_results_qualitative_review_not_trait_violations": { + "name": "qa_results_qualitative_review_not_trait_violations", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "qa_results_evidence_check_passed": { + "name": "qa_results_evidence_check_passed", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "qa_results_evidence_check_notes": { + "name": "qa_results_evidence_check_notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "qa_results_evidence_check_claims": { + "name": "qa_results_evidence_check_claims", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "information_gain_run_id": { + "name": "information_gain_run_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "information_gain_decision": { + "name": "information_gain_decision", + "type": "enum_articles_information_gain_decision", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "information_gain_policy_version": { + "name": "information_gain_policy_version", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "information_gain_consensus_coverage": { + "name": "information_gain_consensus_coverage", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "information_gain_verified_gain_units": { + "name": "information_gain_verified_gain_units", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "information_gain_verification_ratio": { + "name": "information_gain_verification_ratio", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "information_gain_internal_duplication_rate": { + "name": "information_gain_internal_duplication_rate", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "information_gain_verified_novel_claims": { + "name": "information_gain_verified_novel_claims", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "information_gain_scored_at": { + "name": "information_gain_scored_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "generation_model": { + "name": "generation_model", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "qa_models": { + "name": "qa_models", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "total_cost_usd": { + "name": "total_cost_usd", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "reviewed_by": { + "name": "reviewed_by", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "review_notes": { + "name": "review_notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "review_justification": { + "name": "review_justification", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "revision_notes": { + "name": "revision_notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "revision_count": { + "name": "revision_count", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "content_updated_at": { + "name": "content_updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "published_at": { + "name": "published_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "articles_archived_idx": { + "name": "articles_archived_idx", + "columns": [ + { + "expression": "archived", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_slug_idx": { + "name": "articles_slug_idx", + "columns": [ + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_keyword_idx": { + "name": "articles_keyword_idx", + "columns": [ + { + "expression": "keyword", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_template_idx": { + "name": "articles_template_idx", + "columns": [ + { + "expression": "template_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_icp_idx": { + "name": "articles_icp_idx", + "columns": [ + { + "expression": "icp_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_research_research_snapshot_idx": { + "name": "articles_research_research_snapshot_idx", + "columns": [ + { + "expression": "research_snapshot_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_status_idx": { + "name": "articles_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_publish_at_idx": { + "name": "articles_publish_at_idx", + "columns": [ + { + "expression": "publish_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_information_gain_information_gain_run_idx": { + "name": "articles_information_gain_information_gain_run_idx", + "columns": [ + { + "expression": "information_gain_run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_updated_at_idx": { + "name": "articles_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "articles_created_at_idx": { + "name": "articles_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "articles_template_id_templates_id_fk": { + "name": "articles_template_id_templates_id_fk", + "tableFrom": "articles", + "tableTo": "templates", + "columnsFrom": [ + "template_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "articles_icp_id_icps_id_fk": { + "name": "articles_icp_id_icps_id_fk", + "tableFrom": "articles", + "tableTo": "icps", + "columnsFrom": [ + "icp_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "articles_research_snapshot_id_corpus_snapshots_id_fk": { + "name": "articles_research_snapshot_id_corpus_snapshots_id_fk", + "tableFrom": "articles", + "tableTo": "corpus_snapshots", + "columnsFrom": [ + "research_snapshot_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "articles_information_gain_run_id_information_gain_runs_id_fk": { + "name": "articles_information_gain_run_id_information_gain_runs_id_fk", + "tableFrom": "articles", + "tableTo": "information_gain_runs", + "columnsFrom": [ + "information_gain_run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cost_log": { + "name": "cost_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "pipeline_run_id": { + "name": "pipeline_run_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "article_id": { + "name": "article_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "stage": { + "name": "stage", + "type": "enum_cost_log_stage", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "provider": { + "name": "provider", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "input_tokens": { + "name": "input_tokens", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "output_tokens": { + "name": "output_tokens", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "web_search_requests": { + "name": "web_search_requests", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "cost_usd": { + "name": "cost_usd", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "request": { + "name": "request", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "response": { + "name": "response", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "cost_log_pipeline_run_id_idx": { + "name": "cost_log_pipeline_run_id_idx", + "columns": [ + { + "expression": "pipeline_run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "cost_log_article_idx": { + "name": "cost_log_article_idx", + "columns": [ + { + "expression": "article_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "cost_log_updated_at_idx": { + "name": "cost_log_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "cost_log_created_at_idx": { + "name": "cost_log_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cost_log_article_id_articles_id_fk": { + "name": "cost_log_article_id_articles_id_fk", + "tableFrom": "cost_log", + "tableTo": "articles", + "columnsFrom": [ + "article_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.article_audit": { + "name": "article_audit", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "article_id": { + "name": "article_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "event": { + "name": "event", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "summary": { + "name": "summary", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "actor_type": { + "name": "actor_type", + "type": "enum_article_audit_actor_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "actor": { + "name": "actor", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "pipeline_run_id": { + "name": "pipeline_run_id", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "stage": { + "name": "stage", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "from_status": { + "name": "from_status", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "to_status": { + "name": "to_status", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "details": { + "name": "details", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "article_audit_article_idx": { + "name": "article_audit_article_idx", + "columns": [ + { + "expression": "article_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "article_audit_event_idx": { + "name": "article_audit_event_idx", + "columns": [ + { + "expression": "event", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "article_audit_pipeline_run_id_idx": { + "name": "article_audit_pipeline_run_id_idx", + "columns": [ + { + "expression": "pipeline_run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "article_audit_updated_at_idx": { + "name": "article_audit_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "article_audit_created_at_idx": { + "name": "article_audit_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "article_audit_article_id_articles_id_fk": { + "name": "article_audit_article_id_articles_id_fk", + "tableFrom": "article_audit", + "tableTo": "articles", + "columnsFrom": [ + "article_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brand_voices_core_values": { + "name": "brand_voices_core_values", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "value": { + "name": "value", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "brand_voices_core_values_order_idx": { + "name": "brand_voices_core_values_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_core_values_parent_id_idx": { + "name": "brand_voices_core_values_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "brand_voices_core_values_parent_id_fk": { + "name": "brand_voices_core_values_parent_id_fk", + "tableFrom": "brand_voices_core_values", + "tableTo": "brand_voices", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brand_voices_voice_adjectives": { + "name": "brand_voices_voice_adjectives", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "adjective": { + "name": "adjective", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "do_example": { + "name": "do_example", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "dont_example": { + "name": "dont_example", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "brand_voices_voice_adjectives_order_idx": { + "name": "brand_voices_voice_adjectives_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_voice_adjectives_parent_id_idx": { + "name": "brand_voices_voice_adjectives_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "brand_voices_voice_adjectives_parent_id_fk": { + "name": "brand_voices_voice_adjectives_parent_id_fk", + "tableFrom": "brand_voices_voice_adjectives", + "tableTo": "brand_voices", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brand_voices_not_traits": { + "name": "brand_voices_not_traits", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "trait": { + "name": "trait", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "boundary_note": { + "name": "boundary_note", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "brand_voices_not_traits_order_idx": { + "name": "brand_voices_not_traits_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_not_traits_parent_id_idx": { + "name": "brand_voices_not_traits_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "brand_voices_not_traits_parent_id_fk": { + "name": "brand_voices_not_traits_parent_id_fk", + "tableFrom": "brand_voices_not_traits", + "tableTo": "brand_voices", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brand_voices_preferred_words": { + "name": "brand_voices_preferred_words", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "word": { + "name": "word", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "brand_voices_preferred_words_order_idx": { + "name": "brand_voices_preferred_words_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_preferred_words_parent_id_idx": { + "name": "brand_voices_preferred_words_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "brand_voices_preferred_words_parent_id_fk": { + "name": "brand_voices_preferred_words_parent_id_fk", + "tableFrom": "brand_voices_preferred_words", + "tableTo": "brand_voices", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brand_voices_banned_words": { + "name": "brand_voices_banned_words", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "word": { + "name": "word", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "brand_voices_banned_words_order_idx": { + "name": "brand_voices_banned_words_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_banned_words_parent_id_idx": { + "name": "brand_voices_banned_words_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "brand_voices_banned_words_parent_id_fk": { + "name": "brand_voices_banned_words_parent_id_fk", + "tableFrom": "brand_voices_banned_words", + "tableTo": "brand_voices", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brand_voices_samples": { + "name": "brand_voices_samples", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "brand_voices_samples_order_idx": { + "name": "brand_voices_samples_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_samples_parent_id_idx": { + "name": "brand_voices_samples_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "brand_voices_samples_parent_id_fk": { + "name": "brand_voices_samples_parent_id_fk", + "tableFrom": "brand_voices_samples", + "tableTo": "brand_voices", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brand_voices": { + "name": "brand_voices", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "enum_brand_voices_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "source": { + "name": "source", + "type": "enum_brand_voices_source", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'onboarding'" + }, + "source_file_id": { + "name": "source_file_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "onboarding_step": { + "name": "onboarding_step", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "activated_at": { + "name": "activated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "activated_by": { + "name": "activated_by", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "essence_one_liner": { + "name": "essence_one_liner", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "essence_mission": { + "name": "essence_mission", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "audience_description": { + "name": "audience_description", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "audience_language_level": { + "name": "audience_language_level", + "type": "enum_brand_voices_audience_language_level", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "audience_interests": { + "name": "audience_interests", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "audience_needs": { + "name": "audience_needs", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "persona": { + "name": "persona", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "voice_in_own_words": { + "name": "voice_in_own_words", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "tone_formality": { + "name": "tone_formality", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 3 + }, + "tone_warmth": { + "name": "tone_warmth", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 3 + }, + "tone_boldness": { + "name": "tone_boldness", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 3 + }, + "tone_energy": { + "name": "tone_energy", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 3 + }, + "extraction_model": { + "name": "extraction_model", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "extraction_provider": { + "name": "extraction_provider", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "extraction_extracted_at": { + "name": "extraction_extracted_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "extraction_source_chars": { + "name": "extraction_source_chars", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "extraction_warnings": { + "name": "extraction_warnings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "brand_voices_status_idx": { + "name": "brand_voices_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_source_file_idx": { + "name": "brand_voices_source_file_idx", + "columns": [ + { + "expression": "source_file_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_updated_at_idx": { + "name": "brand_voices_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voices_created_at_idx": { + "name": "brand_voices_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "brand_voices_source_file_id_brand_voice_files_id_fk": { + "name": "brand_voices_source_file_id_brand_voice_files_id_fk", + "tableFrom": "brand_voices", + "tableTo": "brand_voice_files", + "columnsFrom": [ + "source_file_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brand_voice_files": { + "name": "brand_voice_files", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "url": { + "name": "url", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "thumbnail_u_r_l": { + "name": "thumbnail_u_r_l", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "filename": { + "name": "filename", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "mime_type": { + "name": "mime_type", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "filesize": { + "name": "filesize", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "width": { + "name": "width", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "height": { + "name": "height", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "focal_x": { + "name": "focal_x", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "focal_y": { + "name": "focal_y", + "type": "numeric", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "brand_voice_files_updated_at_idx": { + "name": "brand_voice_files_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voice_files_created_at_idx": { + "name": "brand_voice_files_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_voice_files_filename_idx": { + "name": "brand_voice_files_filename_idx", + "columns": [ + { + "expression": "filename", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.icps_pains_evidence": { + "name": "icps_pains_evidence", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "ref": { + "name": "ref", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "icps_pains_evidence_order_idx": { + "name": "icps_pains_evidence_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_pains_evidence_parent_id_idx": { + "name": "icps_pains_evidence_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "icps_pains_evidence_parent_id_fk": { + "name": "icps_pains_evidence_parent_id_fk", + "tableFrom": "icps_pains_evidence", + "tableTo": "icps_pains", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.icps_pains": { + "name": "icps_pains", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "statement": { + "name": "statement", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "confidence": { + "name": "confidence", + "type": "enum_icps_pains_confidence", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "icps_pains_order_idx": { + "name": "icps_pains_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_pains_parent_id_idx": { + "name": "icps_pains_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "icps_pains_parent_id_fk": { + "name": "icps_pains_parent_id_fk", + "tableFrom": "icps_pains", + "tableTo": "icps", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.icps_solution_sample_lines": { + "name": "icps_solution_sample_lines", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "icps_solution_sample_lines_order_idx": { + "name": "icps_solution_sample_lines_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_solution_sample_lines_parent_id_idx": { + "name": "icps_solution_sample_lines_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "icps_solution_sample_lines_parent_id_fk": { + "name": "icps_solution_sample_lines_parent_id_fk", + "tableFrom": "icps_solution_sample_lines", + "tableTo": "icps", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.icps_competition": { + "name": "icps_competition", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "competitor": { + "name": "competitor", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "claim": { + "name": "claim", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "claimed_at": { + "name": "claimed_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "confidence": { + "name": "confidence", + "type": "enum_icps_competition_confidence", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "icps_competition_order_idx": { + "name": "icps_competition_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_competition_parent_id_idx": { + "name": "icps_competition_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "icps_competition_parent_id_fk": { + "name": "icps_competition_parent_id_fk", + "tableFrom": "icps_competition", + "tableTo": "icps", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.icps_channels": { + "name": "icps_channels", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "channel": { + "name": "channel", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "confidence": { + "name": "confidence", + "type": "enum_icps_channels_confidence", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "icps_channels_order_idx": { + "name": "icps_channels_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_channels_parent_id_idx": { + "name": "icps_channels_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "icps_channels_parent_id_fk": { + "name": "icps_channels_parent_id_fk", + "tableFrom": "icps_channels", + "tableTo": "icps", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.icps_churn_triggers": { + "name": "icps_churn_triggers", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "icps_churn_triggers_order_idx": { + "name": "icps_churn_triggers_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_churn_triggers_parent_id_idx": { + "name": "icps_churn_triggers_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "icps_churn_triggers_parent_id_fk": { + "name": "icps_churn_triggers_parent_id_fk", + "tableFrom": "icps_churn_triggers", + "tableTo": "icps", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.icps_not_our_user": { + "name": "icps_not_our_user", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "icps_not_our_user_order_idx": { + "name": "icps_not_our_user_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_not_our_user_parent_id_idx": { + "name": "icps_not_our_user_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "icps_not_our_user_parent_id_fk": { + "name": "icps_not_our_user_parent_id_fk", + "tableFrom": "icps_not_our_user", + "tableTo": "icps", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.icps": { + "name": "icps", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "enum_icps_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "primary": { + "name": "primary", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "activated_at": { + "name": "activated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "activated_by": { + "name": "activated_by", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "who": { + "name": "who", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "motivation_text": { + "name": "motivation_text", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "motivation_hypothesis": { + "name": "motivation_hypothesis", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "motivation_confidence": { + "name": "motivation_confidence", + "type": "enum_icps_motivation_confidence", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "solution_mechanism": { + "name": "solution_mechanism", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "solution_confidence": { + "name": "solution_confidence", + "type": "enum_icps_solution_confidence", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "why_us_text": { + "name": "why_us_text", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "why_us_confidence": { + "name": "why_us_confidence", + "type": "enum_icps_why_us_confidence", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "icps_status_idx": { + "name": "icps_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_primary_idx": { + "name": "icps_primary_idx", + "columns": [ + { + "expression": "primary", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_updated_at_idx": { + "name": "icps_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "icps_created_at_idx": { + "name": "icps_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.governance_audit": { + "name": "governance_audit", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "subject_global": { + "name": "subject_global", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "event": { + "name": "event", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "summary": { + "name": "summary", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "actor_type": { + "name": "actor_type", + "type": "enum_governance_audit_actor_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "actor": { + "name": "actor", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "from_status": { + "name": "from_status", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "to_status": { + "name": "to_status", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "details": { + "name": "details", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "governance_audit_subject_global_idx": { + "name": "governance_audit_subject_global_idx", + "columns": [ + { + "expression": "subject_global", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "governance_audit_event_idx": { + "name": "governance_audit_event_idx", + "columns": [ + { + "expression": "event", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "governance_audit_updated_at_idx": { + "name": "governance_audit_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "governance_audit_created_at_idx": { + "name": "governance_audit_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.governance_audit_rels": { + "name": "governance_audit_rels", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "order": { + "name": "order", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "parent_id": { + "name": "parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "path": { + "name": "path", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "brand_voices_id": { + "name": "brand_voices_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evidence_sources_id": { + "name": "evidence_sources_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "icps_id": { + "name": "icps_id", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "governance_audit_rels_order_idx": { + "name": "governance_audit_rels_order_idx", + "columns": [ + { + "expression": "order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "governance_audit_rels_parent_idx": { + "name": "governance_audit_rels_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "governance_audit_rels_path_idx": { + "name": "governance_audit_rels_path_idx", + "columns": [ + { + "expression": "path", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "governance_audit_rels_brand_voices_id_idx": { + "name": "governance_audit_rels_brand_voices_id_idx", + "columns": [ + { + "expression": "brand_voices_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "governance_audit_rels_evidence_sources_id_idx": { + "name": "governance_audit_rels_evidence_sources_id_idx", + "columns": [ + { + "expression": "evidence_sources_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "governance_audit_rels_icps_id_idx": { + "name": "governance_audit_rels_icps_id_idx", + "columns": [ + { + "expression": "icps_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "governance_audit_rels_parent_fk": { + "name": "governance_audit_rels_parent_fk", + "tableFrom": "governance_audit_rels", + "tableTo": "governance_audit", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "governance_audit_rels_brand_voices_fk": { + "name": "governance_audit_rels_brand_voices_fk", + "tableFrom": "governance_audit_rels", + "tableTo": "brand_voices", + "columnsFrom": [ + "brand_voices_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "governance_audit_rels_evidence_sources_fk": { + "name": "governance_audit_rels_evidence_sources_fk", + "tableFrom": "governance_audit_rels", + "tableTo": "evidence_sources", + "columnsFrom": [ + "evidence_sources_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "governance_audit_rels_icps_fk": { + "name": "governance_audit_rels_icps_fk", + "tableFrom": "governance_audit_rels", + "tableTo": "icps", + "columnsFrom": [ + "icps_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.evidence_sources": { + "name": "evidence_sources", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "quality_class": { + "name": "quality_class", + "type": "enum_evidence_sources_quality_class", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "evidence_sources_domain_idx": { + "name": "evidence_sources_domain_idx", + "columns": [ + { + "expression": "domain", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_sources_updated_at_idx": { + "name": "evidence_sources_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_sources_created_at_idx": { + "name": "evidence_sources_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.evidence_source_candidates": { + "name": "evidence_source_candidates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "enum_evidence_source_candidates_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "suggested_class": { + "name": "suggested_class", + "type": "enum_evidence_source_candidates_suggested_class", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "citation_count": { + "name": "citation_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "serp_count": { + "name": "serp_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "domain_rating": { + "name": "domain_rating", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "first_seen_at": { + "name": "first_seen_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "sightings": { + "name": "sightings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "resolved_source_id": { + "name": "resolved_source_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "resolved_at": { + "name": "resolved_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "resolved_by": { + "name": "resolved_by", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "evidence_source_candidates_domain_idx": { + "name": "evidence_source_candidates_domain_idx", + "columns": [ + { + "expression": "domain", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_source_candidates_status_idx": { + "name": "evidence_source_candidates_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_source_candidates_last_seen_at_idx": { + "name": "evidence_source_candidates_last_seen_at_idx", + "columns": [ + { + "expression": "last_seen_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_source_candidates_resolved_source_idx": { + "name": "evidence_source_candidates_resolved_source_idx", + "columns": [ + { + "expression": "resolved_source_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_source_candidates_updated_at_idx": { + "name": "evidence_source_candidates_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_source_candidates_created_at_idx": { + "name": "evidence_source_candidates_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "evidence_source_candidates_resolved_source_id_evidence_sources_id_fk": { + "name": "evidence_source_candidates_resolved_source_id_evidence_sources_id_fk", + "tableFrom": "evidence_source_candidates", + "tableTo": "evidence_sources", + "columnsFrom": [ + "resolved_source_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.corpus_snapshots_pages": { + "name": "corpus_snapshots_pages", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "position": { + "name": "position", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "url": { + "name": "url", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "domain": { + "name": "domain", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "domain_rating": { + "name": "domain_rating", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "fetch_status": { + "name": "fetch_status", + "type": "enum_corpus_snapshots_pages_fetch_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "failure_reason": { + "name": "failure_reason", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "chars": { + "name": "chars", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "text_hash": { + "name": "text_hash", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "text": { + "name": "text", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "claim_count": { + "name": "claim_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "unverified_excerpt_count": { + "name": "unverified_excerpt_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "corpus_snapshots_pages_order_idx": { + "name": "corpus_snapshots_pages_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "corpus_snapshots_pages_parent_id_idx": { + "name": "corpus_snapshots_pages_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "corpus_snapshots_pages_parent_id_fk": { + "name": "corpus_snapshots_pages_parent_id_fk", + "tableFrom": "corpus_snapshots_pages", + "tableTo": "corpus_snapshots", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.corpus_snapshots_internal_corpus": { + "name": "corpus_snapshots_internal_corpus", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "article_id": { + "name": "article_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "article_updated_at": { + "name": "article_updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true + }, + "claim_count": { + "name": "claim_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "corpus_snapshots_internal_corpus_order_idx": { + "name": "corpus_snapshots_internal_corpus_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "corpus_snapshots_internal_corpus_parent_id_idx": { + "name": "corpus_snapshots_internal_corpus_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "corpus_snapshots_internal_corpus_article_idx": { + "name": "corpus_snapshots_internal_corpus_article_idx", + "columns": [ + { + "expression": "article_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "corpus_snapshots_internal_corpus_article_id_articles_id_fk": { + "name": "corpus_snapshots_internal_corpus_article_id_articles_id_fk", + "tableFrom": "corpus_snapshots_internal_corpus", + "tableTo": "articles", + "columnsFrom": [ + "article_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "corpus_snapshots_internal_corpus_parent_id_fk": { + "name": "corpus_snapshots_internal_corpus_parent_id_fk", + "tableFrom": "corpus_snapshots_internal_corpus", + "tableTo": "corpus_snapshots", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.corpus_snapshots": { + "name": "corpus_snapshots", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "keyword": { + "name": "keyword", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "keyword_key": { + "name": "keyword_key", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "country": { + "name": "country", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "captured_at": { + "name": "captured_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "enum_corpus_snapshots_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "pipeline_run_id": { + "name": "pipeline_run_id", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "snapshot_hash": { + "name": "snapshot_hash", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "models": { + "name": "models", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "query_cluster": { + "name": "query_cluster", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "baseline_claims": { + "name": "baseline_claims", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "facets": { + "name": "facets", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "gaps": { + "name": "gaps", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "baseline_doc_count": { + "name": "baseline_doc_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "failed_page_count": { + "name": "failed_page_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "corpus_snapshots_keyword_idx": { + "name": "corpus_snapshots_keyword_idx", + "columns": [ + { + "expression": "keyword", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "corpus_snapshots_keyword_key_idx": { + "name": "corpus_snapshots_keyword_key_idx", + "columns": [ + { + "expression": "keyword_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "corpus_snapshots_pipeline_run_id_idx": { + "name": "corpus_snapshots_pipeline_run_id_idx", + "columns": [ + { + "expression": "pipeline_run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "corpus_snapshots_updated_at_idx": { + "name": "corpus_snapshots_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "corpus_snapshots_created_at_idx": { + "name": "corpus_snapshots_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.topic_searches": { + "name": "topic_searches", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "relevance": { + "name": "relevance", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "relevance_fingerprint": { + "name": "relevance_fingerprint", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "relevance_model": { + "name": "relevance_model", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "seed": { + "name": "seed", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "seed_key": { + "name": "seed_key", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "country": { + "name": "country", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "fetched_at": { + "name": "fetched_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true + }, + "result_count": { + "name": "result_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "candidates": { + "name": "candidates", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "topic_searches_seed_key_idx": { + "name": "topic_searches_seed_key_idx", + "columns": [ + { + "expression": "seed_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "topic_searches_fetched_at_idx": { + "name": "topic_searches_fetched_at_idx", + "columns": [ + { + "expression": "fetched_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "topic_searches_updated_at_idx": { + "name": "topic_searches_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "topic_searches_created_at_idx": { + "name": "topic_searches_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.information_gain_runs": { + "name": "information_gain_runs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "article_id": { + "name": "article_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "pipeline_run_id": { + "name": "pipeline_run_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "snapshot_id": { + "name": "snapshot_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "policy_version": { + "name": "policy_version", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "policy": { + "name": "policy", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "models": { + "name": "models", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "decision": { + "name": "decision", + "type": "enum_information_gain_runs_decision", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "reasons": { + "name": "reasons", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "baseline_available": { + "name": "baseline_available", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "calibrated": { + "name": "calibrated", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "scores_consensus_coverage": { + "name": "scores_consensus_coverage", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "scores_potential_gain_units": { + "name": "scores_potential_gain_units", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "scores_verified_gain_units": { + "name": "scores_verified_gain_units", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "scores_verification_ratio": { + "name": "scores_verification_ratio", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "scores_verified_gain_density": { + "name": "scores_verified_gain_density", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "scores_facet_gain_coverage": { + "name": "scores_facet_gain_coverage", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "scores_internal_duplication_rate": { + "name": "scores_internal_duplication_rate", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "claim_summary_total_claims": { + "name": "claim_summary_total_claims", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "claim_summary_materially_novel_claims": { + "name": "claim_summary_materially_novel_claims", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "claim_summary_verified_novel_claims": { + "name": "claim_summary_verified_novel_claims", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "claim_summary_unsupported_novel_claims": { + "name": "claim_summary_unsupported_novel_claims", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "claim_summary_contradictory_claims": { + "name": "claim_summary_contradictory_claims", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "claim_summary_first_party_claims": { + "name": "claim_summary_first_party_claims", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "claim_ids_blocked": { + "name": "claim_ids_blocked", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "claim_ids_review": { + "name": "claim_ids_review", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "claim_ids_materially_novel": { + "name": "claim_ids_materially_novel", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "claim_ids_verified_novel": { + "name": "claim_ids_verified_novel", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "claims": { + "name": "claims", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "token_count": { + "name": "token_count", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "cost_usd": { + "name": "cost_usd", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "draft_updated_at": { + "name": "draft_updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "information_gain_runs_article_idx": { + "name": "information_gain_runs_article_idx", + "columns": [ + { + "expression": "article_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "information_gain_runs_pipeline_run_id_idx": { + "name": "information_gain_runs_pipeline_run_id_idx", + "columns": [ + { + "expression": "pipeline_run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "information_gain_runs_snapshot_idx": { + "name": "information_gain_runs_snapshot_idx", + "columns": [ + { + "expression": "snapshot_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "information_gain_runs_decision_idx": { + "name": "information_gain_runs_decision_idx", + "columns": [ + { + "expression": "decision", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "information_gain_runs_updated_at_idx": { + "name": "information_gain_runs_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "information_gain_runs_created_at_idx": { + "name": "information_gain_runs_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "information_gain_runs_article_id_articles_id_fk": { + "name": "information_gain_runs_article_id_articles_id_fk", + "tableFrom": "information_gain_runs", + "tableTo": "articles", + "columnsFrom": [ + "article_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "information_gain_runs_snapshot_id_corpus_snapshots_id_fk": { + "name": "information_gain_runs_snapshot_id_corpus_snapshots_id_fk", + "tableFrom": "information_gain_runs", + "tableTo": "corpus_snapshots", + "columnsFrom": [ + "snapshot_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pipeline_runs": { + "name": "pipeline_runs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "enum_pipeline_runs_source", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "enum_pipeline_runs_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "mode": { + "name": "mode", + "type": "enum_pipeline_runs_mode", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "template_id": { + "name": "template_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "requested_count": { + "name": "requested_count", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "config_fingerprint": { + "name": "config_fingerprint", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "config_snapshot": { + "name": "config_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "final_statuses": { + "name": "final_statuses", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "warnings": { + "name": "warnings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error_summary": { + "name": "error_summary", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "requested_by": { + "name": "requested_by", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "started_at": { + "name": "started_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "heartbeat_at": { + "name": "heartbeat_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pipeline_runs_run_id_idx": { + "name": "pipeline_runs_run_id_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pipeline_runs_status_idx": { + "name": "pipeline_runs_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pipeline_runs_template_idx": { + "name": "pipeline_runs_template_idx", + "columns": [ + { + "expression": "template_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pipeline_runs_config_fingerprint_idx": { + "name": "pipeline_runs_config_fingerprint_idx", + "columns": [ + { + "expression": "config_fingerprint", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pipeline_runs_updated_at_idx": { + "name": "pipeline_runs_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pipeline_runs_created_at_idx": { + "name": "pipeline_runs_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pipeline_runs_template_id_templates_id_fk": { + "name": "pipeline_runs_template_id_templates_id_fk", + "tableFrom": "pipeline_runs", + "tableTo": "templates", + "columnsFrom": [ + "template_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pipeline_runs_rels": { + "name": "pipeline_runs_rels", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "order": { + "name": "order", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "parent_id": { + "name": "parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "path": { + "name": "path", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "articles_id": { + "name": "articles_id", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "pipeline_runs_rels_order_idx": { + "name": "pipeline_runs_rels_order_idx", + "columns": [ + { + "expression": "order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pipeline_runs_rels_parent_idx": { + "name": "pipeline_runs_rels_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pipeline_runs_rels_path_idx": { + "name": "pipeline_runs_rels_path_idx", + "columns": [ + { + "expression": "path", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pipeline_runs_rels_articles_id_idx": { + "name": "pipeline_runs_rels_articles_id_idx", + "columns": [ + { + "expression": "articles_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pipeline_runs_rels_parent_fk": { + "name": "pipeline_runs_rels_parent_fk", + "tableFrom": "pipeline_runs_rels", + "tableTo": "pipeline_runs", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pipeline_runs_rels_articles_fk": { + "name": "pipeline_runs_rels_articles_fk", + "tableFrom": "pipeline_runs_rels", + "tableTo": "articles", + "columnsFrom": [ + "articles_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_kv": { + "name": "payload_kv", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "key": { + "name": "key", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "payload_kv_key_idx": { + "name": "payload_kv_key_idx", + "columns": [ + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_jobs_log": { + "name": "payload_jobs_log", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "executed_at": { + "name": "executed_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true + }, + "task_slug": { + "name": "task_slug", + "type": "enum_payload_jobs_log_task_slug", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "task_i_d": { + "name": "task_i_d", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "input": { + "name": "input", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "output": { + "name": "output", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "state": { + "name": "state", + "type": "enum_payload_jobs_log_state", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "error": { + "name": "error", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "payload_jobs_log_order_idx": { + "name": "payload_jobs_log_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_log_parent_id_idx": { + "name": "payload_jobs_log_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "payload_jobs_log_parent_id_fk": { + "name": "payload_jobs_log_parent_id_fk", + "tableFrom": "payload_jobs_log", + "tableTo": "payload_jobs", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_jobs": { + "name": "payload_jobs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "input": { + "name": "input", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "total_tried": { + "name": "total_tried", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "has_error": { + "name": "has_error", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "error": { + "name": "error", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "task_slug": { + "name": "task_slug", + "type": "enum_payload_jobs_task_slug", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "queue": { + "name": "queue", + "type": "varchar", + "primaryKey": false, + "notNull": false, + "default": "'default'" + }, + "wait_until": { + "name": "wait_until", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "processing": { + "name": "processing", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "concurrency_key": { + "name": "concurrency_key", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "meta": { + "name": "meta", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "payload_jobs_completed_at_idx": { + "name": "payload_jobs_completed_at_idx", + "columns": [ + { + "expression": "completed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_total_tried_idx": { + "name": "payload_jobs_total_tried_idx", + "columns": [ + { + "expression": "total_tried", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_has_error_idx": { + "name": "payload_jobs_has_error_idx", + "columns": [ + { + "expression": "has_error", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_task_slug_idx": { + "name": "payload_jobs_task_slug_idx", + "columns": [ + { + "expression": "task_slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_queue_idx": { + "name": "payload_jobs_queue_idx", + "columns": [ + { + "expression": "queue", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_wait_until_idx": { + "name": "payload_jobs_wait_until_idx", + "columns": [ + { + "expression": "wait_until", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_processing_idx": { + "name": "payload_jobs_processing_idx", + "columns": [ + { + "expression": "processing", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_concurrency_key_idx": { + "name": "payload_jobs_concurrency_key_idx", + "columns": [ + { + "expression": "concurrency_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_updated_at_idx": { + "name": "payload_jobs_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_jobs_created_at_idx": { + "name": "payload_jobs_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_locked_documents": { + "name": "payload_locked_documents", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "global_slug": { + "name": "global_slug", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "payload_locked_documents_global_slug_idx": { + "name": "payload_locked_documents_global_slug_idx", + "columns": [ + { + "expression": "global_slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_updated_at_idx": { + "name": "payload_locked_documents_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_created_at_idx": { + "name": "payload_locked_documents_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_locked_documents_rels": { + "name": "payload_locked_documents_rels", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "order": { + "name": "order", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "parent_id": { + "name": "parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "path": { + "name": "path", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "setup_suggestions_id": { + "name": "setup_suggestions_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "users_id": { + "name": "users_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "media_id": { + "name": "media_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "templates_id": { + "name": "templates_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "articles_id": { + "name": "articles_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "cost_log_id": { + "name": "cost_log_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "article_audit_id": { + "name": "article_audit_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "brand_voices_id": { + "name": "brand_voices_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "brand_voice_files_id": { + "name": "brand_voice_files_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "icps_id": { + "name": "icps_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "governance_audit_id": { + "name": "governance_audit_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evidence_sources_id": { + "name": "evidence_sources_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evidence_source_candidates_id": { + "name": "evidence_source_candidates_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "corpus_snapshots_id": { + "name": "corpus_snapshots_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "topic_searches_id": { + "name": "topic_searches_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "information_gain_runs_id": { + "name": "information_gain_runs_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "pipeline_runs_id": { + "name": "pipeline_runs_id", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "payload_locked_documents_rels_order_idx": { + "name": "payload_locked_documents_rels_order_idx", + "columns": [ + { + "expression": "order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_parent_idx": { + "name": "payload_locked_documents_rels_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_path_idx": { + "name": "payload_locked_documents_rels_path_idx", + "columns": [ + { + "expression": "path", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_setup_suggestions_id_idx": { + "name": "payload_locked_documents_rels_setup_suggestions_id_idx", + "columns": [ + { + "expression": "setup_suggestions_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_users_id_idx": { + "name": "payload_locked_documents_rels_users_id_idx", + "columns": [ + { + "expression": "users_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_media_id_idx": { + "name": "payload_locked_documents_rels_media_id_idx", + "columns": [ + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_templates_id_idx": { + "name": "payload_locked_documents_rels_templates_id_idx", + "columns": [ + { + "expression": "templates_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_articles_id_idx": { + "name": "payload_locked_documents_rels_articles_id_idx", + "columns": [ + { + "expression": "articles_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_cost_log_id_idx": { + "name": "payload_locked_documents_rels_cost_log_id_idx", + "columns": [ + { + "expression": "cost_log_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_article_audit_id_idx": { + "name": "payload_locked_documents_rels_article_audit_id_idx", + "columns": [ + { + "expression": "article_audit_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_brand_voices_id_idx": { + "name": "payload_locked_documents_rels_brand_voices_id_idx", + "columns": [ + { + "expression": "brand_voices_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_brand_voice_files_id_idx": { + "name": "payload_locked_documents_rels_brand_voice_files_id_idx", + "columns": [ + { + "expression": "brand_voice_files_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_icps_id_idx": { + "name": "payload_locked_documents_rels_icps_id_idx", + "columns": [ + { + "expression": "icps_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_governance_audit_id_idx": { + "name": "payload_locked_documents_rels_governance_audit_id_idx", + "columns": [ + { + "expression": "governance_audit_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_evidence_sources_id_idx": { + "name": "payload_locked_documents_rels_evidence_sources_id_idx", + "columns": [ + { + "expression": "evidence_sources_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_evidence_source_candidates_idx": { + "name": "payload_locked_documents_rels_evidence_source_candidates_idx", + "columns": [ + { + "expression": "evidence_source_candidates_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_corpus_snapshots_id_idx": { + "name": "payload_locked_documents_rels_corpus_snapshots_id_idx", + "columns": [ + { + "expression": "corpus_snapshots_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_topic_searches_id_idx": { + "name": "payload_locked_documents_rels_topic_searches_id_idx", + "columns": [ + { + "expression": "topic_searches_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_information_gain_runs_id_idx": { + "name": "payload_locked_documents_rels_information_gain_runs_id_idx", + "columns": [ + { + "expression": "information_gain_runs_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_locked_documents_rels_pipeline_runs_id_idx": { + "name": "payload_locked_documents_rels_pipeline_runs_id_idx", + "columns": [ + { + "expression": "pipeline_runs_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "payload_locked_documents_rels_parent_fk": { + "name": "payload_locked_documents_rels_parent_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "payload_locked_documents", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_setup_suggestions_fk": { + "name": "payload_locked_documents_rels_setup_suggestions_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "setup_suggestions", + "columnsFrom": [ + "setup_suggestions_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_users_fk": { + "name": "payload_locked_documents_rels_users_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "users", + "columnsFrom": [ + "users_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_media_fk": { + "name": "payload_locked_documents_rels_media_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_templates_fk": { + "name": "payload_locked_documents_rels_templates_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "templates", + "columnsFrom": [ + "templates_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_articles_fk": { + "name": "payload_locked_documents_rels_articles_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "articles", + "columnsFrom": [ + "articles_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_cost_log_fk": { + "name": "payload_locked_documents_rels_cost_log_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "cost_log", + "columnsFrom": [ + "cost_log_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_article_audit_fk": { + "name": "payload_locked_documents_rels_article_audit_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "article_audit", + "columnsFrom": [ + "article_audit_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_brand_voices_fk": { + "name": "payload_locked_documents_rels_brand_voices_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "brand_voices", + "columnsFrom": [ + "brand_voices_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_brand_voice_files_fk": { + "name": "payload_locked_documents_rels_brand_voice_files_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "brand_voice_files", + "columnsFrom": [ + "brand_voice_files_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_icps_fk": { + "name": "payload_locked_documents_rels_icps_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "icps", + "columnsFrom": [ + "icps_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_governance_audit_fk": { + "name": "payload_locked_documents_rels_governance_audit_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "governance_audit", + "columnsFrom": [ + "governance_audit_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_evidence_sources_fk": { + "name": "payload_locked_documents_rels_evidence_sources_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "evidence_sources", + "columnsFrom": [ + "evidence_sources_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_evidence_source_candidates_fk": { + "name": "payload_locked_documents_rels_evidence_source_candidates_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "evidence_source_candidates", + "columnsFrom": [ + "evidence_source_candidates_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_corpus_snapshots_fk": { + "name": "payload_locked_documents_rels_corpus_snapshots_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "corpus_snapshots", + "columnsFrom": [ + "corpus_snapshots_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_topic_searches_fk": { + "name": "payload_locked_documents_rels_topic_searches_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "topic_searches", + "columnsFrom": [ + "topic_searches_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_information_gain_runs_fk": { + "name": "payload_locked_documents_rels_information_gain_runs_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "information_gain_runs", + "columnsFrom": [ + "information_gain_runs_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_locked_documents_rels_pipeline_runs_fk": { + "name": "payload_locked_documents_rels_pipeline_runs_fk", + "tableFrom": "payload_locked_documents_rels", + "tableTo": "pipeline_runs", + "columnsFrom": [ + "pipeline_runs_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_preferences": { + "name": "payload_preferences", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "key": { + "name": "key", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "value": { + "name": "value", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "payload_preferences_key_idx": { + "name": "payload_preferences_key_idx", + "columns": [ + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_preferences_updated_at_idx": { + "name": "payload_preferences_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_preferences_created_at_idx": { + "name": "payload_preferences_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_preferences_rels": { + "name": "payload_preferences_rels", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "order": { + "name": "order", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "parent_id": { + "name": "parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "path": { + "name": "path", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "users_id": { + "name": "users_id", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "payload_preferences_rels_order_idx": { + "name": "payload_preferences_rels_order_idx", + "columns": [ + { + "expression": "order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_preferences_rels_parent_idx": { + "name": "payload_preferences_rels_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_preferences_rels_path_idx": { + "name": "payload_preferences_rels_path_idx", + "columns": [ + { + "expression": "path", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_preferences_rels_users_id_idx": { + "name": "payload_preferences_rels_users_id_idx", + "columns": [ + { + "expression": "users_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "payload_preferences_rels_parent_fk": { + "name": "payload_preferences_rels_parent_fk", + "tableFrom": "payload_preferences_rels", + "tableTo": "payload_preferences", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payload_preferences_rels_users_fk": { + "name": "payload_preferences_rels_users_fk", + "tableFrom": "payload_preferences_rels", + "tableTo": "users", + "columnsFrom": [ + "users_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_migrations": { + "name": "payload_migrations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "batch": { + "name": "batch", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "payload_migrations_updated_at_idx": { + "name": "payload_migrations_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payload_migrations_created_at_idx": { + "name": "payload_migrations_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.setup_suggestion_scan": { + "name": "setup_suggestion_scan", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "audit_cursor": { + "name": "audit_cursor", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "audit_cursor_id": { + "name": "audit_cursor_id", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_profile_competitors": { + "name": "workspace_profile_competitors", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "workspace_profile_competitors_order_idx": { + "name": "workspace_profile_competitors_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_profile_competitors_parent_id_idx": { + "name": "workspace_profile_competitors_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workspace_profile_competitors_parent_id_fk": { + "name": "workspace_profile_competitors_parent_id_fk", + "tableFrom": "workspace_profile_competitors", + "tableTo": "workspace_profile", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_profile": { + "name": "workspace_profile", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_name": { + "name": "company_name", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "target_domain": { + "name": "target_domain", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "site_notes": { + "name": "site_notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "site_pages": { + "name": "site_pages", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "site_pages_fetched_at": { + "name": "site_pages_fetched_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.positioning_core_claims": { + "name": "positioning_core_claims", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "claim": { + "name": "claim", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "evidence_ref": { + "name": "evidence_ref", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "positioning_core_claims_order_idx": { + "name": "positioning_core_claims_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "positioning_core_claims_parent_id_idx": { + "name": "positioning_core_claims_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "positioning_core_claims_parent_id_fk": { + "name": "positioning_core_claims_parent_id_fk", + "tableFrom": "positioning_core_claims", + "tableTo": "positioning", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.positioning_pillars": { + "name": "positioning_pillars", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "one_line": { + "name": "one_line", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "carries": { + "name": "carries", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "positioning_pillars_order_idx": { + "name": "positioning_pillars_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "positioning_pillars_parent_id_idx": { + "name": "positioning_pillars_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "positioning_pillars_parent_id_fk": { + "name": "positioning_pillars_parent_id_fk", + "tableFrom": "positioning_pillars", + "tableTo": "positioning", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.positioning_descriptor_ladder": { + "name": "positioning_descriptor_ladder", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "descriptor": { + "name": "descriptor", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "positioning_descriptor_ladder_order_idx": { + "name": "positioning_descriptor_ladder_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "positioning_descriptor_ladder_parent_id_idx": { + "name": "positioning_descriptor_ladder_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "positioning_descriptor_ladder_parent_id_fk": { + "name": "positioning_descriptor_ladder_parent_id_fk", + "tableFrom": "positioning_descriptor_ladder", + "tableTo": "positioning", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.positioning_vocabulary_reach_for": { + "name": "positioning_vocabulary_reach_for", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "term": { + "name": "term", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "positioning_vocabulary_reach_for_order_idx": { + "name": "positioning_vocabulary_reach_for_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "positioning_vocabulary_reach_for_parent_id_idx": { + "name": "positioning_vocabulary_reach_for_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "positioning_vocabulary_reach_for_parent_id_fk": { + "name": "positioning_vocabulary_reach_for_parent_id_fk", + "tableFrom": "positioning_vocabulary_reach_for", + "tableTo": "positioning", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.positioning_vocabulary_avoid": { + "name": "positioning_vocabulary_avoid", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "term": { + "name": "term", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "positioning_vocabulary_avoid_order_idx": { + "name": "positioning_vocabulary_avoid_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "positioning_vocabulary_avoid_parent_id_idx": { + "name": "positioning_vocabulary_avoid_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "positioning_vocabulary_avoid_parent_id_fk": { + "name": "positioning_vocabulary_avoid_parent_id_fk", + "tableFrom": "positioning_vocabulary_avoid", + "tableTo": "positioning", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.positioning_open_rulings": { + "name": "positioning_open_rulings", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "question": { + "name": "question", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "enum_positioning_open_rulings_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'open'" + }, + "ruling": { + "name": "ruling", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "ruled_at": { + "name": "ruled_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "positioning_open_rulings_order_idx": { + "name": "positioning_open_rulings_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "positioning_open_rulings_parent_id_idx": { + "name": "positioning_open_rulings_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "positioning_open_rulings_parent_id_fk": { + "name": "positioning_open_rulings_parent_id_fk", + "tableFrom": "positioning_open_rulings", + "tableTo": "positioning", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.positioning": { + "name": "positioning", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "category": { + "name": "category", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "goal": { + "name": "goal", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "promise": { + "name": "promise", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "active_position": { + "name": "active_position", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "statement": { + "name": "statement", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "macro_frame": { + "name": "macro_frame", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "landscape": { + "name": "landscape", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "enemy": { + "name": "enemy", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "archetype": { + "name": "archetype", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "essence": { + "name": "essence", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.evidence_bank_verified_claims_cleared_surfaces": { + "name": "evidence_bank_verified_claims_cleared_surfaces", + "schema": "", + "columns": { + "order": { + "name": "order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "parent_id": { + "name": "parent_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "enum_evidence_bank_verified_claims_cleared_surfaces", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + } + }, + "indexes": { + "evidence_bank_verified_claims_cleared_surfaces_order_idx": { + "name": "evidence_bank_verified_claims_cleared_surfaces_order_idx", + "columns": [ + { + "expression": "order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_bank_verified_claims_cleared_surfaces_parent_idx": { + "name": "evidence_bank_verified_claims_cleared_surfaces_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "evidence_bank_verified_claims_cleared_surfaces_parent_fk": { + "name": "evidence_bank_verified_claims_cleared_surfaces_parent_fk", + "tableFrom": "evidence_bank_verified_claims_cleared_surfaces", + "tableTo": "evidence_bank_verified_claims", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.evidence_bank_verified_claims": { + "name": "evidence_bank_verified_claims", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "ref": { + "name": "ref", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "claim": { + "name": "claim", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "primary_source": { + "name": "primary_source", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "source_url": { + "name": "source_url", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "source_date": { + "name": "source_date", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "sample_or_method": { + "name": "sample_or_method", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "verification_depth": { + "name": "verification_depth", + "type": "enum_evidence_bank_verified_claims_verification_depth", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "limits": { + "name": "limits", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "recheck_at": { + "name": "recheck_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "evidence_bank_verified_claims_order_idx": { + "name": "evidence_bank_verified_claims_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_bank_verified_claims_parent_id_idx": { + "name": "evidence_bank_verified_claims_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "evidence_bank_verified_claims_parent_id_fk": { + "name": "evidence_bank_verified_claims_parent_id_fk", + "tableFrom": "evidence_bank_verified_claims", + "tableTo": "evidence_bank", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.evidence_bank_facts": { + "name": "evidence_bank_facts", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "ref": { + "name": "ref", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "fact": { + "name": "fact", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "owner": { + "name": "owner", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "last_confirmed_at": { + "name": "last_confirmed_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "evidence_bank_facts_order_idx": { + "name": "evidence_bank_facts_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_bank_facts_parent_id_idx": { + "name": "evidence_bank_facts_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "evidence_bank_facts_parent_id_fk": { + "name": "evidence_bank_facts_parent_id_fk", + "tableFrom": "evidence_bank_facts", + "tableTo": "evidence_bank", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.evidence_bank_rejected_claims": { + "name": "evidence_bank_rejected_claims", + "schema": "", + "columns": { + "_order": { + "name": "_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "_parent_id": { + "name": "_parent_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "ref": { + "name": "ref", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "claim": { + "name": "claim", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "enum_evidence_bank_rejected_claims_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'rejected'" + }, + "reason": { + "name": "reason", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "replacement": { + "name": "replacement", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "evidence_bank_rejected_claims_order_idx": { + "name": "evidence_bank_rejected_claims_order_idx", + "columns": [ + { + "expression": "_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "evidence_bank_rejected_claims_parent_id_idx": { + "name": "evidence_bank_rejected_claims_parent_id_idx", + "columns": [ + { + "expression": "_parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "evidence_bank_rejected_claims_parent_id_fk": { + "name": "evidence_bank_rejected_claims_parent_id_fk", + "tableFrom": "evidence_bank_rejected_claims", + "tableTo": "evidence_bank", + "columnsFrom": [ + "_parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.evidence_bank": { + "name": "evidence_bank", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "ref_counter": { + "name": "ref_counter", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "notes": { + "name": "notes", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.llm_settings": { + "name": "llm_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "generate_model": { + "name": "generate_model", + "type": "enum_llm_settings_generate_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "fact_check_model": { + "name": "fact_check_model", + "type": "enum_llm_settings_fact_check_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "qualitative_review_model": { + "name": "qualitative_review_model", + "type": "enum_llm_settings_qualitative_review_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "claim_extraction_model": { + "name": "claim_extraction_model", + "type": "enum_llm_settings_claim_extraction_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "information_gain_judge_model": { + "name": "information_gain_judge_model", + "type": "enum_llm_settings_information_gain_judge_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "evidence_verification_model": { + "name": "evidence_verification_model", + "type": "enum_llm_settings_evidence_verification_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "evidence_check_model": { + "name": "evidence_check_model", + "type": "enum_llm_settings_evidence_check_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "brief_angle_model": { + "name": "brief_angle_model", + "type": "enum_llm_settings_brief_angle_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "topic_relevance_model": { + "name": "topic_relevance_model", + "type": "enum_llm_settings_topic_relevance_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "brand_voice_extract_model": { + "name": "brand_voice_extract_model", + "type": "enum_llm_settings_brand_voice_extract_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "setup_assist_model": { + "name": "setup_assist_model", + "type": "enum_llm_settings_setup_assist_model", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.information_gain_policy": { + "name": "information_gain_policy", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "min_consensus_coverage": { + "name": "min_consensus_coverage", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "min_verification_ratio": { + "name": "min_verification_ratio", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "min_novel_factual_integrity": { + "name": "min_novel_factual_integrity", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "min_numeric_temporal_integrity": { + "name": "min_numeric_temporal_integrity", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "require_exact_value_match": { + "name": "require_exact_value_match", + "type": "enum_information_gain_policy_require_exact_value_match", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "require_evidence_lineage": { + "name": "require_evidence_lineage", + "type": "enum_information_gain_policy_require_evidence_lineage", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "block_first_party_measurements": { + "name": "block_first_party_measurements", + "type": "enum_information_gain_policy_block_first_party_measurements", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "max_contradiction_probability": { + "name": "max_contradiction_probability", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "material_novelty_threshold": { + "name": "material_novelty_threshold", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "max_internal_duplication_rate": { + "name": "max_internal_duplication_rate", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "min_verified_novel_claims": { + "name": "min_verified_novel_claims", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.webhook_settings": { + "name": "webhook_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "url": { + "name": "url", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "secret": { + "name": "secret", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payload_jobs_stats": { + "name": "payload_jobs_stats", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "stats": { + "name": "stats", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(3) with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.enum_setup_suggestions_kind": { + "name": "enum_setup_suggestions_kind", + "schema": "public", + "values": [ + "banned_word", + "not_trait", + "unbacked_claim", + "rejected_ref" + ] + }, + "public.enum_setup_suggestions_target": { + "name": "enum_setup_suggestions_target", + "schema": "public", + "values": [ + "brand-voice", + "evidence-bank" + ] + }, + "public.enum_setup_suggestions_status": { + "name": "enum_setup_suggestions_status", + "schema": "public", + "values": [ + "open", + "accepted", + "dismissed", + "obsolete" + ] + }, + "public.enum_templates_company_mentions": { + "name": "enum_templates_company_mentions", + "schema": "public", + "values": [ + "none", + "mention", + "feature" + ] + }, + "public.enum_articles_brief_sections_source": { + "name": "enum_articles_brief_sections_source", + "schema": "public", + "values": [ + "template", + "research", + "editor" + ] + }, + "public.enum_articles_status": { + "name": "enum_articles_status", + "schema": "public", + "values": [ + "topic_selected", + "brief_review", + "researched", + "drafted", + "qa_passed", + "verified", + "needs_review", + "blocked", + "needs_revision", + "approved", + "published" + ] + }, + "public.enum_articles_information_gain_decision": { + "name": "enum_articles_information_gain_decision", + "schema": "public", + "values": [ + "PASS", + "REVISE", + "HUMAN_REVIEW", + "BLOCK" + ] + }, + "public.enum_cost_log_stage": { + "name": "enum_cost_log_stage", + "schema": "public", + "values": [ + "generate", + "factCheck", + "qualitativeReview", + "claimExtraction", + "informationGainJudge", + "evidenceVerification", + "evidenceCheck", + "briefAngle", + "brandVoiceExtract", + "setupAssist", + "topicRelevance" + ] + }, + "public.enum_article_audit_actor_type": { + "name": "enum_article_audit_actor_type", + "schema": "public", + "values": [ + "pipeline", + "user", + "system" + ] + }, + "public.enum_brand_voices_status": { + "name": "enum_brand_voices_status", + "schema": "public", + "values": [ + "draft", + "active", + "archived" + ] + }, + "public.enum_brand_voices_source": { + "name": "enum_brand_voices_source", + "schema": "public", + "values": [ + "onboarding", + "upload" + ] + }, + "public.enum_brand_voices_audience_language_level": { + "name": "enum_brand_voices_audience_language_level", + "schema": "public", + "values": [ + "plain", + "general", + "professional", + "expert" + ] + }, + "public.enum_icps_pains_confidence": { + "name": "enum_icps_pains_confidence", + "schema": "public", + "values": [ + "verified", + "strong_directional", + "qualitative_pattern", + "cultural_signal", + "inference", + "hypothesis" + ] + }, + "public.enum_icps_competition_confidence": { + "name": "enum_icps_competition_confidence", + "schema": "public", + "values": [ + "verified", + "strong_directional", + "qualitative_pattern", + "cultural_signal", + "inference", + "hypothesis" + ] + }, + "public.enum_icps_channels_confidence": { + "name": "enum_icps_channels_confidence", + "schema": "public", + "values": [ + "verified", + "strong_directional", + "qualitative_pattern", + "cultural_signal", + "inference", + "hypothesis" + ] + }, + "public.enum_icps_status": { + "name": "enum_icps_status", + "schema": "public", + "values": [ + "draft", + "active", + "archived" + ] + }, + "public.enum_icps_motivation_confidence": { + "name": "enum_icps_motivation_confidence", + "schema": "public", + "values": [ + "verified", + "strong_directional", + "qualitative_pattern", + "cultural_signal", + "inference", + "hypothesis" + ] + }, + "public.enum_icps_solution_confidence": { + "name": "enum_icps_solution_confidence", + "schema": "public", + "values": [ + "verified", + "strong_directional", + "qualitative_pattern", + "cultural_signal", + "inference", + "hypothesis" + ] + }, + "public.enum_icps_why_us_confidence": { + "name": "enum_icps_why_us_confidence", + "schema": "public", + "values": [ + "verified", + "strong_directional", + "qualitative_pattern", + "cultural_signal", + "inference", + "hypothesis" + ] + }, + "public.enum_governance_audit_actor_type": { + "name": "enum_governance_audit_actor_type", + "schema": "public", + "values": [ + "pipeline", + "user", + "system" + ] + }, + "public.enum_evidence_sources_quality_class": { + "name": "enum_evidence_sources_quality_class", + "schema": "public", + "values": [ + "first_party_dataset", + "primary", + "official_docs", + "secondary", + "unverified", + "blocked" + ] + }, + "public.enum_evidence_source_candidates_status": { + "name": "enum_evidence_source_candidates_status", + "schema": "public", + "values": [ + "pending", + "approved", + "dismissed" + ] + }, + "public.enum_evidence_source_candidates_suggested_class": { + "name": "enum_evidence_source_candidates_suggested_class", + "schema": "public", + "values": [ + "primary", + "official_docs", + "secondary", + "unverified" + ] + }, + "public.enum_corpus_snapshots_pages_fetch_status": { + "name": "enum_corpus_snapshots_pages_fetch_status", + "schema": "public", + "values": [ + "ok", + "failed", + "skipped" + ] + }, + "public.enum_corpus_snapshots_status": { + "name": "enum_corpus_snapshots_status", + "schema": "public", + "values": [ + "complete", + "partial", + "empty" + ] + }, + "public.enum_information_gain_runs_decision": { + "name": "enum_information_gain_runs_decision", + "schema": "public", + "values": [ + "PASS", + "REVISE", + "HUMAN_REVIEW", + "BLOCK" + ] + }, + "public.enum_pipeline_runs_source": { + "name": "enum_pipeline_runs_source", + "schema": "public", + "values": [ + "admin", + "cli", + "selected" + ] + }, + "public.enum_pipeline_runs_status": { + "name": "enum_pipeline_runs_status", + "schema": "public", + "values": [ + "queued", + "running", + "succeeded", + "failed" + ] + }, + "public.enum_pipeline_runs_mode": { + "name": "enum_pipeline_runs_mode", + "schema": "public", + "values": [ + "mock", + "live" + ] + }, + "public.enum_payload_jobs_log_task_slug": { + "name": "enum_payload_jobs_log_task_slug", + "schema": "public", + "values": [ + "inline", + "content-run", + "webhook-deliver", + "publish-due", + "recover-stale-runs", + "collect-setup-suggestions" + ] + }, + "public.enum_payload_jobs_log_state": { + "name": "enum_payload_jobs_log_state", + "schema": "public", + "values": [ + "failed", + "succeeded" + ] + }, + "public.enum_payload_jobs_task_slug": { + "name": "enum_payload_jobs_task_slug", + "schema": "public", + "values": [ + "inline", + "content-run", + "webhook-deliver", + "publish-due", + "recover-stale-runs", + "collect-setup-suggestions" + ] + }, + "public.enum_positioning_open_rulings_status": { + "name": "enum_positioning_open_rulings_status", + "schema": "public", + "values": [ + "open", + "ruled" + ] + }, + "public.enum_evidence_bank_verified_claims_cleared_surfaces": { + "name": "enum_evidence_bank_verified_claims_cleared_surfaces", + "schema": "public", + "values": [ + "web", + "blog", + "ads", + "sales", + "social", + "pr" + ] + }, + "public.enum_evidence_bank_verified_claims_verification_depth": { + "name": "enum_evidence_bank_verified_claims_verification_depth", + "schema": "public", + "values": [ + "primary_document", + "reproduced", + "third_party_audit", + "self_reported" + ] + }, + "public.enum_evidence_bank_rejected_claims_status": { + "name": "enum_evidence_bank_rejected_claims_status", + "schema": "public", + "values": [ + "rejected", + "expired" + ] + }, + "public.enum_llm_settings_generate_model": { + "name": "enum_llm_settings_generate_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_fact_check_model": { + "name": "enum_llm_settings_fact_check_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_qualitative_review_model": { + "name": "enum_llm_settings_qualitative_review_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_claim_extraction_model": { + "name": "enum_llm_settings_claim_extraction_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_information_gain_judge_model": { + "name": "enum_llm_settings_information_gain_judge_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_evidence_verification_model": { + "name": "enum_llm_settings_evidence_verification_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_evidence_check_model": { + "name": "enum_llm_settings_evidence_check_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_brief_angle_model": { + "name": "enum_llm_settings_brief_angle_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_topic_relevance_model": { + "name": "enum_llm_settings_topic_relevance_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_brand_voice_extract_model": { + "name": "enum_llm_settings_brand_voice_extract_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_llm_settings_setup_assist_model": { + "name": "enum_llm_settings_setup_assist_model", + "schema": "public", + "values": [ + "claude-fable-5", + "claude-opus-5", + "claude-sonnet-5", + "claude-haiku-4-5", + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.5", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.4-nano", + "gpt-5", + "gpt-5-mini", + "gpt-5-nano" + ] + }, + "public.enum_information_gain_policy_require_exact_value_match": { + "name": "enum_information_gain_policy_require_exact_value_match", + "schema": "public", + "values": [ + "enabled", + "disabled" + ] + }, + "public.enum_information_gain_policy_require_evidence_lineage": { + "name": "enum_information_gain_policy_require_evidence_lineage", + "schema": "public", + "values": [ + "enabled", + "disabled" + ] + }, + "public.enum_information_gain_policy_block_first_party_measurements": { + "name": "enum_information_gain_policy_block_first_party_measurements", + "schema": "public", + "values": [ + "enabled", + "disabled" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "id": "1e69e7d3-ed95-402d-a730-4b813f23b8ec", + "prevId": "00000000-0000-0000-0000-000000000000" +} \ No newline at end of file diff --git a/cms/src/migrations/20261110_055225_article_slug_unique.ts b/cms/src/migrations/20261110_055225_article_slug_unique.ts new file mode 100644 index 0000000..98b723f --- /dev/null +++ b/cms/src/migrations/20261110_055225_article_slug_unique.ts @@ -0,0 +1,52 @@ +import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres' + +/** + * Article slugs become unique. Existing duplicates are resolved first: within + * each group of rows sharing a slug, the earliest (lowest id) keeps it and + * every later row gets `-` appended. That can itself be taken (ids 1, 2, 3 + * with slugs `guide`, `guide`, `guide-2` would give two `guide-2`), so each + * replacement is checked against every slug in the table, including the ones + * this loop has already assigned, and gets `-2`, `-3`, … more until it is + * free. Empty slugs become NULL, the value the `uniqueArticleSlug` hook writes + * for "no slug", since the index allows any number of NULLs but only one ''. + */ +export async function up({ db }: MigrateUpArgs): Promise { + await db.execute(sql` + UPDATE "articles" SET "slug" = NULL WHERE "slug" = ''; + DO $slugs$ + DECLARE + dup record; + base text; + candidate text; + n integer; + BEGIN + FOR dup IN + SELECT "id", "slug" FROM ( + SELECT "id", "slug", row_number() OVER (PARTITION BY "slug" ORDER BY "id") AS rn + FROM "articles" + WHERE "slug" IS NOT NULL + ) AS d + WHERE d.rn > 1 + ORDER BY "id" + LOOP + base := dup."slug" || '-' || dup."id"; + candidate := base; + n := 1; + WHILE EXISTS (SELECT 1 FROM "articles" WHERE "slug" = candidate) LOOP + n := n + 1; + candidate := base || '-' || n; + END LOOP; + UPDATE "articles" SET "slug" = candidate WHERE "id" = dup."id"; + END LOOP; + END + $slugs$; + DROP INDEX IF EXISTS "articles_slug_idx"; + CREATE UNIQUE INDEX "articles_slug_idx" ON "articles" USING btree ("slug");`) +} + +/** Back to a plain index. The renamed duplicates keep their new slugs. */ +export async function down({ db }: MigrateDownArgs): Promise { + await db.execute(sql` + DROP INDEX IF EXISTS "articles_slug_idx"; + CREATE INDEX "articles_slug_idx" ON "articles" USING btree ("slug");`) +} diff --git a/cms/src/migrations/20261110_055928_clear_published_publish_at.ts b/cms/src/migrations/20261110_055928_clear_published_publish_at.ts new file mode 100644 index 0000000..e0b495c --- /dev/null +++ b/cms/src/migrations/20261110_055928_clear_published_publish_at.ts @@ -0,0 +1,20 @@ +import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres' + +/** + * Clear the used-up schedule on articles that are already published. + * + * The `stampPublication` hook clears `publishAt` on every transition into + * `published`, but rows published before it existed kept their old date. Moved + * back to `approved`, such a row has a `publishAt` long in the past, and the + * next `publish-due` tick republishes it without anyone asking. + */ +export async function up({ db }: MigrateUpArgs): Promise { + await db.execute(sql` + UPDATE "articles" SET "publish_at" = NULL WHERE "status" = 'published' AND "publish_at" IS NOT NULL;`) +} + +/** + * A no-op: the cleared dates were schedules that had already been used, and + * nothing records which rows held one, so there is nothing to put back. + */ +export async function down(_args: MigrateDownArgs): Promise {} diff --git a/cms/src/migrations/index.ts b/cms/src/migrations/index.ts index 1fafeeb..b421c3c 100644 --- a/cms/src/migrations/index.ts +++ b/cms/src/migrations/index.ts @@ -22,6 +22,9 @@ import * as migration_20261007_133736_topic_relevance from './20261007_133736_to import * as migration_20261007_134746_setup_suggestions from './20261007_134746_setup_suggestions'; import * as migration_20261021_145609_article_content_updated_at from './20261021_145609_article_content_updated_at'; import * as migration_20261109_221312_payload_3_91_auth_fields from './20261109_221312_payload_3_91_auth_fields'; +import * as migration_20261110_054316_pipeline_run_lease from './20261110_054316_pipeline_run_lease'; +import * as migration_20261110_055225_article_slug_unique from './20261110_055225_article_slug_unique'; +import * as migration_20261110_055928_clear_published_publish_at from './20261110_055928_clear_published_publish_at'; export const migrations = [ { @@ -142,6 +145,21 @@ export const migrations = [ { up: migration_20261109_221312_payload_3_91_auth_fields.up, down: migration_20261109_221312_payload_3_91_auth_fields.down, - name: '20261109_221312_payload_3_91_auth_fields' + name: '20261109_221312_payload_3_91_auth_fields', + }, + { + up: migration_20261110_054316_pipeline_run_lease.up, + down: migration_20261110_054316_pipeline_run_lease.down, + name: '20261110_054316_pipeline_run_lease', + }, + { + up: migration_20261110_055225_article_slug_unique.up, + down: migration_20261110_055225_article_slug_unique.down, + name: '20261110_055225_article_slug_unique', + }, + { + up: migration_20261110_055928_clear_published_publish_at.up, + down: migration_20261110_055928_clear_published_publish_at.down, + name: '20261110_055928_clear_published_publish_at' }, ]; diff --git a/cms/src/payload-types.ts b/cms/src/payload-types.ts index 7b21242..af41247 100644 --- a/cms/src/payload-types.ts +++ b/cms/src/payload-types.ts @@ -149,6 +149,7 @@ export interface Config { 'content-run': TaskContentRun; 'webhook-deliver': TaskWebhookDeliver; 'publish-due': TaskPublishDue; + 'recover-stale-runs': TaskRecoverStaleRuns; 'collect-setup-suggestions': TaskCollectSetupSuggestions; inline: { input: unknown; @@ -1462,12 +1463,12 @@ export interface PipelineRun { id: number; runId: string; /** - * Where the run came from. `selected` runs the articles a person ticked on the board; `admin` discovers new content-gap topics first. + * Where the run came from. `selected` runs the articles a person ticked on the board; `admin` discovers new content-gap topics first; `cli` is `npm run pipeline:run`, which advances every article waiting at a stage. */ source: 'admin' | 'cli' | 'selected'; status: 'queued' | 'running' | 'succeeded' | 'failed'; mode: 'mock' | 'live'; - template: number | Template; + template?: (number | null) | Template; requestedCount: number; articles?: (number | Article)[] | null; configFingerprint: string; @@ -1501,6 +1502,7 @@ export interface PipelineRun { errorSummary?: string | null; requestedBy: string; startedAt?: string | null; + heartbeatAt?: string | null; completedAt?: string | null; updatedAt: string; createdAt: string; @@ -1574,7 +1576,13 @@ export interface PayloadJob { | { executedAt: string; completedAt: string; - taskSlug: 'inline' | 'content-run' | 'webhook-deliver' | 'publish-due' | 'collect-setup-suggestions'; + taskSlug: + | 'inline' + | 'content-run' + | 'webhook-deliver' + | 'publish-due' + | 'recover-stale-runs' + | 'collect-setup-suggestions'; taskID: string; input?: | { @@ -1607,7 +1615,16 @@ export interface PayloadJob { id?: string | null; }[] | null; - taskSlug?: ('inline' | 'content-run' | 'webhook-deliver' | 'publish-due' | 'collect-setup-suggestions') | null; + taskSlug?: + | ( + | 'inline' + | 'content-run' + | 'webhook-deliver' + | 'publish-due' + | 'recover-stale-runs' + | 'collect-setup-suggestions' + ) + | null; queue?: string | null; waitUntil?: string | null; processing?: boolean | null; @@ -2394,6 +2411,7 @@ export interface PipelineRunsSelect { errorSummary?: T; requestedBy?: T; startedAt?: T; + heartbeatAt?: T; completedAt?: T; updatedAt?: T; createdAt?: T; @@ -2982,7 +3000,7 @@ export interface LlmSetting { ) | null; /** - * Turns an uploaded brand guide into a brand voice draft. Leave blank to use BRAND_VOICE_EXTRACT_MODEL from the environment, or the platform default (Claude Opus 5). + * Turns an uploaded brand guide into a brand voice draft. Leave blank to use BRAND_VOICE_EXTRACT_MODEL from the environment, or the generate model (Claude Opus 5 unless you changed it). */ brandVoiceExtractModel?: | ( @@ -3414,6 +3432,33 @@ export interface TaskPublishDue { | null; }; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "TaskRecover-stale-runs". + */ +export interface TaskRecoverStaleRuns { + input?: unknown; + output: { + recoveredRuns: + | { + [k: string]: unknown; + } + | unknown[] + | string + | number + | boolean + | null; + failedJobs: + | { + [k: string]: unknown; + } + | unknown[] + | string + | number + | boolean + | null; + }; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "TaskCollect-setup-suggestions". diff --git a/cms/src/payload.config.ts b/cms/src/payload.config.ts index 2fea3f1..27e96ec 100644 --- a/cms/src/payload.config.ts +++ b/cms/src/payload.config.ts @@ -32,6 +32,7 @@ import { WebhookSettings } from './globals/WebhookSettings' import { WorkspaceProfile } from './globals/WorkspaceProfile' import { ContentRunTask } from './jobs/contentRun' import { PublishDueTask } from './jobs/publishDue' +import { RecoverStaleRunsTask } from './jobs/recoverStaleRuns' import { WebhookDeliverTask } from './jobs/webhookDeliver' const filename = fileURLToPath(import.meta.url) @@ -190,7 +191,13 @@ export default buildConfig({ WebhookSettings, ], jobs: { - tasks: [ContentRunTask, WebhookDeliverTask, PublishDueTask, CollectSetupSuggestionsTask], + tasks: [ + ContentRunTask, + WebhookDeliverTask, + PublishDueTask, + RecoverStaleRunsTask, + CollectSetupSuggestionsTask, + ], enableConcurrencyControl: true, processingOrder: 'createdAt', // Production runs no queues in-process; the external scheduler calls diff --git a/cms/tests/int/articleEvents.int.spec.ts b/cms/tests/int/articleEvents.int.spec.ts index 7eaa5f1..e3a02d4 100644 --- a/cms/tests/int/articleEvents.int.spec.ts +++ b/cms/tests/int/articleEvents.int.spec.ts @@ -57,10 +57,13 @@ describe('article status events', () => { let events = await queuedEvents(article.id) expect(events).toHaveLength(1) expect(events[0].event).toBe(ARTICLE_STATUS_EVENT) + expect(article.slug).toMatch(/^event-test-article(-\d+)?$/) expect(events[0].body).toMatchObject({ event: ARTICLE_STATUS_EVENT, articleId: article.id, - slug: 'event-test-article', + // Slugs are unique and articles are never deleted, so a re-run of this + // suite gets `event-test-article-2` and so on. + slug: article.slug, from: null, to: 'topic_selected', actorType: 'system', diff --git a/cms/tests/int/articleSlug.int.spec.ts b/cms/tests/int/articleSlug.int.spec.ts new file mode 100644 index 0000000..891f5a4 --- /dev/null +++ b/cms/tests/int/articleSlug.int.spec.ts @@ -0,0 +1,195 @@ +import { randomUUID } from 'node:crypto' +import { sql } from '@payloadcms/db-postgres' +import { getPayload, type Payload } from 'payload' +import { afterAll, beforeAll, describe, expect, it } from 'vitest' + +import config from '@/payload.config' +import { MAX_SLUG_LENGTH, normaliseSlug } from '@/lib/articleSlug' +import * as slugMigration from '@/migrations/20261110_055225_article_slug_unique' + +let payload: Payload +const created: number[] = [] + +type Executor = { execute: (query: unknown) => Promise<{ rows: Array> }> } +const db = () => (payload.db as unknown as { drizzle: Executor }).drizzle + +async function article(slug?: string | null) { + const doc = await payload.create({ + collection: 'articles', + data: { keyword: `slug ${randomUUID()}`, status: 'topic_selected', slug }, + depth: 0, + }) + created.push(doc.id) + return doc +} + +/** A token no other row's slug can contain, so each case owns its slugs. */ +const token = () => randomUUID().slice(0, 8) + +beforeAll(async () => { + payload = await getPayload({ config: await config }) +}) + +afterAll(async () => { + // Articles cannot be deleted; archiving takes them out of every listing. + for (const id of created) { + await payload.update({ + collection: 'articles', + id, + data: { archived: true }, + overrideAccess: true, + }) + } +}) + +describe('normaliseSlug', () => { + it('lower-cases, folds accents and joins words with single hyphens', () => { + expect(normaliseSlug(' Café Tips: The 2026 Guide!! ')).toBe('cafe-tips-the-2026-guide') + expect(normaliseSlug('a--b__c d')).toBe('a-b-c-d') + expect(normaliseSlug('---')).toBe('') + }) + + it('caps the length without leaving a trailing hyphen', () => { + const long = `${'a'.repeat(MAX_SLUG_LENGTH - 1)} bcd` + const slug = normaliseSlug(long) + expect(slug.length).toBeLessThanOrEqual(MAX_SLUG_LENGTH) + expect(slug.endsWith('-')).toBe(false) + }) +}) + +describe('article slugs', () => { + it('normalises a slug on create', async () => { + const t = token() + const doc = await article(` How To ${t.toUpperCase()} Brew! `) + expect(doc.slug).toBe(`how-to-${t}-brew`) + }) + + it('suffixes a slug another article already has', async () => { + const base = `same-${token()}` + const first = await article(base) + const second = await article(base) + const third = await article(base.toUpperCase()) + expect(first.slug).toBe(base) + expect(second.slug).toBe(`${base}-2`) + expect(third.slug).toBe(`${base}-3`) + }) + + it('suffixes on update, and leaves an unchanged slug alone', async () => { + const base = `taken-${token()}` + const owner = await article(base) + const other = await article(`other-${token()}`) + + const moved = await payload.update({ + collection: 'articles', + id: other.id, + data: { slug: base }, + depth: 0, + }) + expect(moved.slug).toBe(`${base}-2`) + + // Re-saving the owner with its own slug must not suffix it against itself. + const resaved = await payload.update({ + collection: 'articles', + id: owner.id, + data: { slug: base, title: 'Retitled' }, + depth: 0, + }) + expect(resaved.slug).toBe(base) + + // Regenerating `other` with the same model slug lands on the slug it holds. + const regenerated = await payload.update({ + collection: 'articles', + id: other.id, + data: { slug: `${base.toUpperCase()} ` }, + depth: 0, + }) + expect(regenerated.slug).toBe(`${base}-2`) + }) + + it('suffixes a purely numeric slug so it cannot shadow the id route', async () => { + const digits = String(Date.now()).slice(-9) + const first = await article(digits) + const second = await article(digits) + expect(first.slug).toBe(`${digits}-2`) + expect(second.slug).toBe(`${digits}-3`) + }) + + it('stores no slug when nothing usable is left', async () => { + expect((await article('!!!')).slug ?? null).toBeNull() + expect((await article('')).slug ?? null).toBeNull() + }) + + it('rejects a duplicate that bypasses the hook', async () => { + const base = `raw-${token()}` + const first = await article(base) + const second = await article(`raw-other-${token()}`) + await expect( + db().execute(sql`UPDATE articles SET slug = ${first.slug} WHERE id = ${second.id}`), + ).rejects.toThrow() + }) +}) + +describe('article_slug_unique migration', () => { + it('renames later duplicates to -, nulls empty slugs, then enforces uniqueness', async () => { + const shared = `legacy-${token()}` + const a = await article(`seed-a-${token()}`) + const b = await article(`seed-b-${token()}`) + const c = await article(`seed-c-${token()}`) + const empty = await article(`seed-e-${token()}`) + const args = { db: db(), payload, req: {} } as never + + // Back to the old schema, and the data it allowed. + await slugMigration.down(args) + try { + await db().execute( + sql`UPDATE articles SET slug = ${shared} WHERE id IN (${a.id}, ${b.id}, ${c.id})`, + ) + await db().execute(sql`UPDATE articles SET slug = '' WHERE id = ${empty.id}`) + } finally { + await slugMigration.up(args) + } + + const { rows } = await db().execute( + sql`SELECT id, slug FROM articles WHERE id IN (${a.id}, ${b.id}, ${c.id}, ${empty.id}) ORDER BY id`, + ) + const slugs = Object.fromEntries(rows.map((row) => [row.id, row.slug])) + expect(slugs[a.id]).toBe(shared) + expect(slugs[b.id]).toBe(`${shared}-${b.id}`) + expect(slugs[c.id]).toBe(`${shared}-${c.id}`) + expect(slugs[empty.id]).toBeNull() + + const { rows: index } = await db().execute( + sql`SELECT indexdef FROM pg_indexes WHERE indexname = 'articles_slug_idx'`, + ) + expect(String(index[0]?.indexdef)).toContain('UNIQUE') + }) + + it('suffixes again when `-` is itself taken', async () => { + const shared = `guide-${token()}` + const a = await article(`seed-a-${token()}`) + const b = await article(`seed-b-${token()}`) + const c = await article(`seed-c-${token()}`) + // `b` would become `-`, which `c` already holds, and + // `--2` is taken too. + const taken = `${shared}-${b.id}` + const d = await article(`${taken}-2`) + const args = { db: db(), payload, req: {} } as never + + await slugMigration.down(args) + try { + await db().execute(sql`UPDATE articles SET slug = ${shared} WHERE id IN (${a.id}, ${b.id})`) + await db().execute(sql`UPDATE articles SET slug = ${taken} WHERE id = ${c.id}`) + } finally { + await slugMigration.up(args) + } + + const { rows } = await db().execute( + sql`SELECT id, slug FROM articles WHERE id IN (${a.id}, ${b.id}, ${c.id}, ${d.id}) ORDER BY id`, + ) + const slugs = Object.fromEntries(rows.map((row) => [row.id, row.slug])) + expect(slugs[a.id]).toBe(shared) + expect(slugs[b.id]).toBe(`${taken}-3`) + expect(slugs[c.id]).toBe(taken) + expect(slugs[d.id]).toBe(`${taken}-2`) + }) +}) diff --git a/cms/tests/int/brandVoiceExtract.int.spec.ts b/cms/tests/int/brandVoiceExtract.int.spec.ts index 327e198..39ede43 100644 --- a/cms/tests/int/brandVoiceExtract.int.spec.ts +++ b/cms/tests/int/brandVoiceExtract.int.spec.ts @@ -59,7 +59,7 @@ describe('extractText', () => { }) describe('brand voice extraction', () => { - it('follows the pipeline mock rule: MOCK_MODE wins, else mock without the model provider key', () => { + it('follows the shared mock rule: MOCK_MODE wins, else live only with a provider key', () => { expect(extractionMockMode({})).toBe(true) expect(extractionMockMode({ ANTHROPIC_API_KEY: 'k' })).toBe(false) expect(extractionMockMode({ ANTHROPIC_API_KEY: 'k', MOCK_MODE: 'true' })).toBe(true) @@ -71,23 +71,28 @@ describe('brand voice extraction', () => { ).toBe('gpt-5.6-terra') }) - it('mocks or not based on the model actually passed in, not just the env default', () => { - expect(extractionMockMode({ OPENAI_API_KEY: 'k' }, 'gpt-5.6-sol')).toBe(false) - expect(extractionMockMode({ ANTHROPIC_API_KEY: 'k' }, 'gpt-5.6-sol')).toBe(true) + it('defaults to the generate model, so an OpenAI-only workspace is not refused', () => { + const env = { OPENAI_API_KEY: 'k', PIPELINE_MODEL_GENERATE: 'gpt-5.6-terra' } + expect(extractionModel(env)).toBe('gpt-5.6-terra') + expect(extractionMockMode(env)).toBe(false) + expect(extractionModel({ OPENAI_API_KEY: 'k' }, { generateModel: 'gpt-5' })).toBe('gpt-5') }) - it('needs the OpenAI key, not the Anthropic one, when the extraction model is a gpt-* id', () => { - expect(extractionMockMode({ OPENAI_API_KEY: 'k', BRAND_VOICE_EXTRACT_MODEL: 'gpt-5' })).toBe(false) - expect(extractionMockMode({ ANTHROPIC_API_KEY: 'k', BRAND_VOICE_EXTRACT_MODEL: 'gpt-5' })).toBe(true) - expect(extractionMockMode({ OPENAI_API_KEY: 'k' })).toBe(true) - }) - - it('never leaves mock mode without the model key, whatever else the environment carries', () => { - // Only the selected model's own key is consent to spend. Nothing else a - // dev machine happens to hold may flip an upload into a live, billed call. + it('does not go live without a key, whatever else the environment carries', () => { expect(extractionMockMode({ SOME_OTHER_CREDENTIAL: 'present' })).toBe(true) expect(extractionMockMode({ ANTHROPIC_API_KEY: '' })).toBe(true) - expect(extractionMockMode({ MOCK_MODE: 'false' })).toBe(false) + }) + + it('in live mode with the model key missing, errors naming the key instead of returning the demo', async () => { + vi.stubEnv('MOCK_MODE', 'false') + vi.stubEnv('ANTHROPIC_API_KEY', '') + try { + await expect( + extractBrandVoiceFromText({ text: 'x', filename: 'guide.md', model: 'claude-opus-5' }), + ).rejects.toThrow(/Brand voice extraction cannot run.*needs ANTHROPIC_API_KEY/) + } finally { + vi.unstubAllEnvs() + } }) it('refuses a model id neither provider serves rather than guessing one', async () => { diff --git a/cms/tests/int/clearPublishedPublishAt.int.spec.ts b/cms/tests/int/clearPublishedPublishAt.int.spec.ts new file mode 100644 index 0000000..4e8365c --- /dev/null +++ b/cms/tests/int/clearPublishedPublishAt.int.spec.ts @@ -0,0 +1,52 @@ +import { randomUUID } from 'node:crypto' +import { sql } from '@payloadcms/db-postgres' +import { getPayload, type Payload } from 'payload' +import { afterAll, beforeAll, expect, it } from 'vitest' + +import config from '@/payload.config' +import * as migration from '@/migrations/20261110_055928_clear_published_publish_at' + +type Executor = { execute: (query: unknown) => Promise<{ rows: Array> }> } + +let payload: Payload +const ids: number[] = [] +const db = () => (payload.db as unknown as { drizzle: Executor }).drizzle + +beforeAll(async () => { + payload = await getPayload({ config: await config }) +}) + +afterAll(async () => { + for (const id of ids) { + await db().execute(sql`UPDATE articles SET archived = true, publish_at = NULL WHERE id = ${id}`) + } +}) + +it('clears a stale publishAt on published articles and leaves approved schedules alone', async () => { + for (let i = 0; i < 2; i += 1) { + const doc = await payload.create({ + collection: 'articles', + data: { keyword: `publish-at ${randomUUID()}`, status: 'topic_selected' }, + depth: 0, + }) + ids.push(doc.id) + } + const [published, approved] = ids + // The state the hook can no longer produce: written straight to the table, + // as rows published before `stampPublication` existed were left. + await db().execute( + sql`UPDATE articles SET status = 'published', publish_at = now() - interval '30 days' WHERE id = ${published}`, + ) + await db().execute( + sql`UPDATE articles SET status = 'approved', publish_at = now() + interval '1 day' WHERE id = ${approved}`, + ) + + await migration.up({ db: db(), payload, req: {} } as never) + + const { rows } = await db().execute( + sql`SELECT id, publish_at FROM articles WHERE id IN (${published}, ${approved})`, + ) + const publishAt = Object.fromEntries(rows.map((row) => [row.id, row.publish_at])) + expect(publishAt[published]).toBeNull() + expect(publishAt[approved]).not.toBeNull() +}) diff --git a/cms/tests/int/cmsLlm.int.spec.ts b/cms/tests/int/cmsLlm.int.spec.ts index f5b1b1d..0d35dba 100644 --- a/cms/tests/int/cmsLlm.int.spec.ts +++ b/cms/tests/int/cmsLlm.int.spec.ts @@ -38,33 +38,30 @@ beforeEach(() => { }) describe('cmsMockMode', () => { - it('lets MOCK_MODE win, and otherwise mocks when the model credential is absent', () => { - const cases: [Record, string, boolean][] = [ - [{}, ANTHROPIC_MODEL, true], - [{ ANTHROPIC_API_KEY: 'k' }, ANTHROPIC_MODEL, false], - [{ ANTHROPIC_API_KEY: 'k', MOCK_MODE: 'true' }, ANTHROPIC_MODEL, true], - [{ MOCK_MODE: 'false' }, ANTHROPIC_MODEL, false], - [{ MOCK_MODE: '' }, ANTHROPIC_MODEL, true], - // The credential is picked per model, not per workspace: an Anthropic key - // does nothing for a gpt-* id and vice versa. - [{ OPENAI_API_KEY: 'k' }, OPENAI_MODEL, false], - [{ ANTHROPIC_API_KEY: 'k' }, OPENAI_MODEL, true], - [{ OPENAI_API_KEY: 'k' }, ANTHROPIC_MODEL, true], + it('is the workspace rule: MOCK_MODE wins, else live only when any provider key is set', () => { + const cases: [Record, boolean][] = [ + [{}, true], + [{ ANTHROPIC_API_KEY: 'k' }, false], + [{ OPENAI_API_KEY: 'k' }, false], + [{ ANTHROPIC_API_KEY: 'k', MOCK_MODE: 'true' }, true], + [{ ANTHROPIC_API_KEY: 'k', MOCK_MODE: '1' }, true], + [{ MOCK_MODE: 'false' }, false], + [{ MOCK_MODE: 'NO' }, false], + [{ MOCK_MODE: '' }, true], + [{ MOCK_MODE: ' ', OPENAI_API_KEY: 'k' }, false], + // Unparseable: mock, even with a key. The readiness check reports it. + [{ MOCK_MODE: 'maybe', ANTHROPIC_API_KEY: 'k' }, true], ] - for (const [env, model, expected] of cases) { - expect(cmsMockMode(env, model), `${model} with ${JSON.stringify(env)}`).toBe(expected) + for (const [env, expected] of cases) { + expect(cmsMockMode(env, ANTHROPIC_MODEL), JSON.stringify(env)).toBe(expected) + // The mode belongs to the workspace, not to the model asked about. + expect(cmsMockMode(env, OPENAI_MODEL), JSON.stringify(env)).toBe(expected) } }) - it('never goes live without the model key, whatever else the environment carries', () => { - // Only ANTHROPIC_API_KEY can lift mock mode for a claude-* model; nothing - // else a dev machine happens to hold is consent to spend. + it('never goes live on anything but a provider key or an explicit false', () => { expect(cmsMockMode({ SOME_OTHER_CREDENTIAL: 'present' }, ANTHROPIC_MODEL)).toBe(true) - expect(cmsMockMode({ OPENAI_API_KEY: 'k' }, ANTHROPIC_MODEL)).toBe(true) expect(cmsMockMode({ ANTHROPIC_API_KEY: '' }, ANTHROPIC_MODEL)).toBe(true) - // Only an explicit MOCK_MODE=false, or the model's own key, goes live. - expect(cmsMockMode({ MOCK_MODE: 'false' }, ANTHROPIC_MODEL)).toBe(false) - expect(cmsMockMode({ ANTHROPIC_API_KEY: 'k' }, ANTHROPIC_MODEL)).toBe(false) }) }) @@ -81,7 +78,7 @@ describe('completeJsonCms', () => { anthropicCreate.mockResolvedValue(anthropicReply('```json\n{"ok":true}\n```')) const result = await completeJsonCms( { system: 'sys', user: 'usr', model: ANTHROPIC_MODEL, maxTokens: 1234 }, - { env: { MOCK_MODE: 'false' } }, + { env: { MOCK_MODE: 'false', ANTHROPIC_API_KEY: 'k' } }, ) expect(result.json).toEqual({ ok: true }) expect(result.provider).toBe('anthropic') @@ -99,7 +96,7 @@ describe('completeJsonCms', () => { openaiCreate.mockResolvedValue(openaiReply('{"ok":1}')) const result = await completeJsonCms( { system: 'sys', user: 'usr', model: OPENAI_MODEL }, - { env: { MOCK_MODE: 'false' } }, + { env: { MOCK_MODE: 'false', OPENAI_API_KEY: 'k' } }, ) expect(result.json).toEqual({ ok: 1 }) expect(result.provider).toBe('openai') @@ -113,6 +110,53 @@ describe('completeJsonCms', () => { }) }) + it('in live mode without that model\'s key, fails naming the key and never calls out', async () => { + // Live because the other provider's key is set; this model's key is not. + await expect( + completeJsonCms( + { system: 's', user: 'u', model: OPENAI_MODEL, label: 'Setup assistant' }, + { env: { ANTHROPIC_API_KEY: 'k' } }, + ), + ).rejects.toThrow(/Setup assistant cannot run: "gpt-5\.6-terra" needs OPENAI_API_KEY set/) + await expect( + completeJsonCms( + { system: 's', user: 'u', model: ANTHROPIC_MODEL }, + { env: { MOCK_MODE: 'false' } }, + ), + ).rejects.toThrow(/needs ANTHROPIC_API_KEY set/) + expect(anthropicCreate).not.toHaveBeenCalled() + expect(openaiCreate).not.toHaveBeenCalled() + }) + + it('names the token cap when a cut-off reply is not valid JSON', async () => { + anthropicCreate.mockResolvedValue({ + content: [{ type: 'text', text: '{"a": [1, 2' }], + stop_reason: 'max_tokens', + usage: { input_tokens: 5, output_tokens: 8000 }, + }) + const failure = await completeJsonCms( + { system: 's', user: 'u', model: ANTHROPIC_MODEL }, + { env: { ANTHROPIC_API_KEY: 'k' } }, + ).then( + () => null, + (error: unknown) => error, + ) + expect(failure).toBeInstanceOf(CmsLlmError) + expect((failure as CmsLlmError).message).toMatch(/not valid JSON \(did not finish normally; stop_reason: max_tokens\)/) + expect((failure as CmsLlmError).billed.usage).toEqual({ inputTokens: 5, outputTokens: 8000 }) + }) + + it('names a refusal instead of calling it malformed JSON', async () => { + anthropicCreate.mockResolvedValue({ + content: [{ type: 'text', text: 'I cannot help with that.' }], + stop_reason: 'refusal', + usage: { input_tokens: 5, output_tokens: 9 }, + }) + await expect( + completeJsonCms({ system: 's', user: 'u', model: ANTHROPIC_MODEL }, { env: { ANTHROPIC_API_KEY: 'k' } }), + ).rejects.toThrow(/stop_reason: refusal/) + }) + it('refuses a model id neither provider serves instead of guessing one', async () => { await expect( completeJsonCms( @@ -132,7 +176,7 @@ describe('completeJsonCms', () => { }) const failure = await completeJsonCms( { system: 'sys', user: 'usr', model: ANTHROPIC_MODEL, label: 'Draft step' }, - { env: { MOCK_MODE: 'false' } }, + { env: { MOCK_MODE: 'false', ANTHROPIC_API_KEY: 'k' } }, ).then( () => null, (error: unknown) => error, @@ -150,7 +194,7 @@ describe('completeJsonCms', () => { openaiCreate.mockResolvedValue(openaiReply('Sorry, I cannot help with that.')) const failure = await completeJsonCms( { system: 'sys', user: 'usr', model: OPENAI_MODEL }, - { env: { MOCK_MODE: 'false' } }, + { env: { MOCK_MODE: 'false', OPENAI_API_KEY: 'k' } }, ).then( () => null, (error: unknown) => error, diff --git a/cms/tests/int/pipelineRunCli.int.spec.ts b/cms/tests/int/pipelineRunCli.int.spec.ts new file mode 100644 index 0000000..7b538d4 --- /dev/null +++ b/cms/tests/int/pipelineRunCli.int.spec.ts @@ -0,0 +1,233 @@ +import { execFile } from 'node:child_process' +import { randomUUID } from 'node:crypto' +import { createRequire } from 'node:module' +import path from 'node:path' +import { pathToFileURL } from 'node:url' +import { promisify } from 'node:util' + +import { getPayload, type Payload, type TypedUser } from 'payload' +import { afterAll, beforeAll, describe, expect, it } from 'vitest' + +import config from '@/payload.config' +import { + ActivePipelineRunError, + ArticleInActiveRunError, + createCliRun, + createPipelineRun, +} from '@/lib/createPipelineRun' +import type { WorkspaceReadiness } from '@/lib/workspaceReadiness' + +const execute = promisify(execFile) +const tsxLoader = pathToFileURL(createRequire(import.meta.url).resolve('tsx')).href + +let payload: Payload +let user: TypedUser +let templateId: number +let articleId: number +const runIds: number[] = [] + +// `createPipelineRun` and `createCliRun` only copy these onto the row. +const readiness = { + mode: 'mock', + configFingerprint: 'cli-test', + runtime: { missing: [] }, + governance: { activeVoiceId: null }, + tenant: { + profile: { targetDomain: 'example.com', competitorCount: 0 }, + icps: { primaryId: null, count: 0 }, + positioning: { status: 'missing' }, + evidenceBank: {}, + }, + content: { models: [] }, +} as unknown as WorkspaceReadiness + +async function settleActiveRuns() { + await payload.update({ + collection: 'pipeline-runs', + where: { status: { in: ['queued', 'running'] } }, + data: { status: 'failed', errorSummary: 'settled by pipelineRunCli test' }, + overrideAccess: true, + }) +} + +beforeAll(async () => { + payload = await getPayload({ config: await config }) + const users = await payload.find({ collection: 'users', limit: 1, overrideAccess: true }) + user = + (users.docs[0] as TypedUser | undefined) ?? + ((await payload.create({ + collection: 'users', + data: { email: `cli-${randomUUID()}@example.com`, password: 'cli-test-password' }, + overrideAccess: true, + })) as TypedUser) + const template = await payload.create({ + collection: 'templates', + data: { name: `CLI ${randomUUID()}` }, + }) + templateId = template.id + const article = await payload.create({ + collection: 'articles', + data: { keyword: `cli ${randomUUID()}`, status: 'topic_selected', template: templateId }, + }) + articleId = article.id + // Leftovers from another suite would make every launch here refuse. + await settleActiveRuns() +}) + +afterAll(async () => { + for (const id of runIds) { + await payload.delete({ collection: 'pipeline-runs', id, overrideAccess: true }) + } + await payload.update({ + collection: 'articles', + id: articleId, + data: { archived: true }, + overrideAccess: true, + }) + await payload.delete({ collection: 'templates', id: templateId, overrideAccess: true }) +}) + +describe('createCliRun', () => { + it('registers a running cli run that lists its articles, with no template', async () => { + const run = await createCliRun(payload, { + runId: randomUUID(), + mode: 'mock', + readiness, + articleIds: [articleId], + requestedBy: 'cli', + }) + runIds.push(run.id) + expect(run.source).toBe('cli') + expect(run.status).toBe('running') + expect(run.template ?? null).toBeNull() + expect(run.heartbeatAt).toBeTruthy() + expect(run.startedAt).toBeTruthy() + expect(run.articles).toEqual([articleId]) + + // While it holds them: an admin run is refused outright, and a selected run + // over one of its articles is refused for the overlap. + await expect( + createPipelineRun(payload, user, { + runId: randomUUID(), + source: 'admin', + templateId, + count: 1, + requestedBy: 'test', + readiness, + }), + ).rejects.toBeInstanceOf(ActivePipelineRunError) + await expect( + createPipelineRun(payload, user, { + runId: randomUUID(), + source: 'selected', + templateId, + count: 1, + requestedBy: 'test', + readiness, + articleIds: [articleId], + }), + ).rejects.toBeInstanceOf(ArticleInActiveRunError) + + // And a second CLI run is refused while the first is active. + await expect( + createCliRun(payload, { + runId: randomUUID(), + mode: 'mock', + readiness, + articleIds: [], + requestedBy: 'cli', + }), + ).rejects.toThrow(`Run ${run.runId} is already in progress.`) + + await settleActiveRuns() + }) + + it('refuses while a worker run is queued', async () => { + const queued = await payload.create({ + collection: 'pipeline-runs', + overrideAccess: true, + data: { + runId: randomUUID(), + source: 'admin', + status: 'queued', + mode: 'mock', + template: templateId, + requestedCount: 1, + requestedBy: 'test', + configFingerprint: 'test', + configSnapshot: {}, + }, + }) + runIds.push(queued.id) + await expect( + createCliRun(payload, { + runId: randomUUID(), + mode: 'mock', + readiness, + articleIds: [articleId], + requestedBy: 'cli', + }), + ).rejects.toBeInstanceOf(ActivePipelineRunError) + const cliRows = await payload.count({ + collection: 'pipeline-runs', + where: { and: [{ source: { equals: 'cli' } }, { status: { equals: 'running' } }] }, + overrideAccess: true, + }) + expect(cliRows.totalDocs).toBe(0) + await settleActiveRuns() + }) +}) + +describe('pipeline run command', () => { + it('refuses to run until setup is finished', async () => { + const { docs: active } = await payload.find({ + collection: 'brand-voices', + where: { status: { equals: 'active' } }, + depth: 0, + overrideAccess: true, + }) + for (const voice of active) { + await payload.update({ + collection: 'brand-voices', + id: voice.id, + data: { status: 'archived' }, + overrideAccess: true, + }) + } + const before = await payload.count({ collection: 'pipeline-runs', overrideAccess: true }) + try { + const outcome = await execute( + process.execPath, + ['--import', tsxLoader, 'pipeline/src/index.ts', 'run'], + { + cwd: path.resolve(process.cwd(), '..'), + timeout: 30_000, + env: { ...process.env, MOCK_MODE: 'true' }, + }, + ).then( + () => ({ code: 0, stderr: '' }), + (error: { code?: number; stderr?: string }) => ({ + code: error.code, + stderr: error.stderr ?? '', + }), + ) + expect(outcome.code).toBe(1) + expect(outcome.stderr).toContain('Finish setup before running the pipeline') + expect(outcome.stderr).toContain('Activate a brand voice') + // Refused before it registered a run or touched an article. + const after = await payload.count({ collection: 'pipeline-runs', overrideAccess: true }) + expect(after.totalDocs).toBe(before.totalDocs) + const article = await payload.findByID({ collection: 'articles', id: articleId, depth: 0 }) + expect(article.status).toBe('topic_selected') + } finally { + for (const voice of active) { + await payload.update({ + collection: 'brand-voices', + id: voice.id, + data: { status: 'active' }, + overrideAccess: true, + }) + } + } + }, 40_000) +}) diff --git a/cms/tests/int/runLease.int.spec.ts b/cms/tests/int/runLease.int.spec.ts new file mode 100644 index 0000000..1e54c8f --- /dev/null +++ b/cms/tests/int/runLease.int.spec.ts @@ -0,0 +1,378 @@ +import { randomUUID } from 'node:crypto' +import { sql } from '@payloadcms/db-postgres' +import { getPayload, type Payload } from 'payload' +import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest' + +// The handler's workspace inputs and the pipeline itself are faked: these +// tests are about the run row's lease, not about what a stage writes. +vi.mock('../../../pipeline/src/runContext', () => ({ + loadStageInputs: vi.fn().mockResolvedValue({ + tenant: { profile: { targetDomain: 'example.com' }, icps: [{ id: 1, primary: true }] }, + brandVoice: { name: 'Test voice' }, + }), + buildStageContext: vi.fn().mockReturnValue({}), +})) +vi.mock('../../../pipeline/src/stages', () => ({ runPipeline: vi.fn() })) + +import config from '@/payload.config' +import { executeContentRun } from '@/jobs/contentRun' +import { recoverStaleRuns, RUN_LEASE_TIMEOUT_MS } from '@/lib/pipelineRunLease' +import type { PipelineRun } from '@/payload-types' +import { runPipeline } from '../../../pipeline/src/stages' + +const runPipelineMock = vi.mocked(runPipeline) + +let payload: Payload +let templateId: number +let articleId: number +const runIds: number[] = [] +const jobIds: Array = [] + +const ago = (ms: number) => new Date(Date.now() - ms).toISOString() + +async function createRun(data: Partial): Promise { + const run = await payload.create({ + collection: 'pipeline-runs', + overrideAccess: true, + data: { + runId: randomUUID(), + source: 'selected', + status: 'queued', + mode: 'mock', + template: templateId, + requestedCount: 1, + articles: [articleId], + requestedBy: 'test', + configFingerprint: 'test', + configSnapshot: {}, + ...data, + }, + }) + runIds.push(run.id) + return run +} + +/** A content-run job the way a worker that died mid-run leaves it: taken, never finished. */ +async function stuckJob(runId: string, updatedAt: string) { + const job = await payload.jobs.queue({ + task: 'content-run', + // Not `content`: nothing in this suite should ever pick it up. + queue: 'lease-test', + input: { runId }, + overrideAccess: true, + }) + jobIds.push(job.id) + // Raw SQL: Payload stamps `updatedAt` itself on every update, and the age of + // the job's last touch is exactly what recovery reads. + await ( + payload.db as unknown as { drizzle: { execute: (query: unknown) => Promise } } + ).drizzle.execute( + sql`UPDATE payload_jobs SET processing = true, updated_at = ${updatedAt} WHERE id = ${job.id}`, + ) + return job.id +} + +type Executor = { execute: (query: unknown) => Promise<{ rows: Array> }> } +const db = () => (payload.db as unknown as { drizzle: Executor }).drizzle + +const readRun = (id: number) => + payload.findByID({ collection: 'pipeline-runs', id, depth: 0, overrideAccess: true }) +const readJob = (id: number | string) => + payload.findByID({ collection: 'payload-jobs', id, depth: 0, overrideAccess: true }) + +beforeAll(async () => { + payload = await getPayload({ config: await config }) + const template = await payload.create({ + collection: 'templates', + data: { name: `Lease ${randomUUID()}` }, + }) + templateId = template.id + const article = await payload.create({ + collection: 'articles', + data: { keyword: `lease ${randomUUID()}`, status: 'topic_selected', template: templateId }, + }) + articleId = article.id +}) + +beforeEach(() => { + runPipelineMock.mockReset() +}) + +afterAll(async () => { + for (const id of jobIds) { + await payload.delete({ collection: 'payload-jobs', id, overrideAccess: true }) + } + for (const id of runIds) { + await payload.delete({ collection: 'pipeline-runs', id, overrideAccess: true }) + } + await payload.update({ + collection: 'articles', + id: articleId, + data: { archived: true }, + overrideAccess: true, + }) + await payload.delete({ collection: 'templates', id: templateId, overrideAccess: true }) +}) + +describe('recover-stale-runs', () => { + it('fails a running run whose heartbeat is stale and releases its stuck job', async () => { + const run = await createRun({ + status: 'running', + startedAt: ago(RUN_LEASE_TIMEOUT_MS * 3), + heartbeatAt: ago(RUN_LEASE_TIMEOUT_MS + 60_000), + }) + const jobId = await stuckJob(run.runId, ago(RUN_LEASE_TIMEOUT_MS * 3)) + + const result = await recoverStaleRuns(payload) + + expect(result.recoveredRuns).toContain(run.runId) + expect(result.failedJobs).toContain(jobId) + const recovered = await readRun(run.id) + expect(recovered.status).toBe('failed') + expect(recovered.errorSummary).toContain('worker stopped responding') + expect(recovered.completedAt).toBeTruthy() + const job = await readJob(jobId) + // Exactly what Payload's runner needs to stop counting the job as holding + // the `content-pipeline` key and to never pick it up again. + expect(job.processing).toBe(false) + expect(job.hasError).toBe(true) + }) + + it('falls back to startedAt for a run that never wrote a heartbeat', async () => { + const run = await createRun({ status: 'running', startedAt: ago(RUN_LEASE_TIMEOUT_MS * 2) }) + const result = await recoverStaleRuns(payload) + expect(result.recoveredRuns).toContain(run.runId) + expect((await readRun(run.id)).status).toBe('failed') + }) + + it('leaves a long run with a fresh heartbeat alone, and its job too', async () => { + const run = await createRun({ + status: 'running', + // Started long ago: elapsed time alone must never release a live run. + startedAt: ago(RUN_LEASE_TIMEOUT_MS * 10), + heartbeatAt: ago(30_000), + }) + const jobId = await stuckJob(run.runId, ago(RUN_LEASE_TIMEOUT_MS * 10)) + + const result = await recoverStaleRuns(payload) + + expect(result.recoveredRuns).not.toContain(run.runId) + expect(result.failedJobs).not.toContain(jobId) + expect((await readRun(run.id)).status).toBe('running') + expect((await readJob(jobId)).processing).toBe(true) + await payload.update({ + collection: 'payload-jobs', + id: jobId, + data: { processing: false }, + overrideAccess: true, + }) + }) + + it('releases a job whose worker died before it claimed the run, and fails the queued run', async () => { + const run = await createRun({ status: 'queued' }) + const jobId = await stuckJob(run.runId, ago(RUN_LEASE_TIMEOUT_MS + 60_000)) + + const result = await recoverStaleRuns(payload) + + expect(result.failedJobs).toContain(jobId) + expect((await readJob(jobId)).hasError).toBe(true) + const failed = await readRun(run.id) + expect(failed.status).toBe('failed') + expect(failed.errorSummary).toContain('stopped responding') + }) + + it('leaves the job alone when its worker claims the queued run while recovery waits', async () => { + const run = await createRun({ status: 'queued' }) + const jobId = await stuckJob(run.runId, ago(RUN_LEASE_TIMEOUT_MS + 60_000)) + + // The worker's claim, holding the row lock and not yet committed when + // recovery reads the run. + const transactionID = await payload.db.beginTransaction() + if (transactionID == null) throw new Error('no transaction') + const session = (payload.db as unknown as { sessions: Record }) + .sessions[String(transactionID)].db + await session.execute(sql`SELECT id FROM pipeline_runs WHERE id = ${run.id} FOR UPDATE`) + await session.execute( + sql`UPDATE pipeline_runs SET status = 'running', started_at = now(), heartbeat_at = now() WHERE id = ${run.id}`, + ) + const recovery = recoverStaleRuns(payload) + await new Promise((resolve) => setTimeout(resolve, 300)) + await payload.db.commitTransaction(transactionID) + const result = await recovery + + expect(result.recoveredRuns).not.toContain(run.runId) + expect(result.failedJobs).not.toContain(jobId) + expect((await readRun(run.id)).status).toBe('running') + const job = await readJob(jobId) + expect(job.processing).toBe(true) + expect(job.hasError ?? false).toBe(false) + + await payload.update({ + collection: 'payload-jobs', + id: jobId, + data: { processing: false }, + overrideAccess: true, + }) + await payload.update({ + collection: 'pipeline-runs', + id: run.id, + data: { status: 'failed' }, + overrideAccess: true, + }) + }) + + it('does not touch a job that was only just taken', async () => { + const run = await createRun({ status: 'queued' }) + const jobId = await stuckJob(run.runId, ago(5_000)) + const result = await recoverStaleRuns(payload) + expect(result.failedJobs).not.toContain(jobId) + expect((await readRun(run.id)).status).toBe('queued') + await payload.update({ + collection: 'payload-jobs', + id: jobId, + data: { processing: false }, + overrideAccess: true, + }) + }) +}) + +describe('content-run lease', () => { + it('claims the run and stamps a heartbeat before any work', async () => { + const run = await createRun({}) + runPipelineMock.mockImplementation(async () => { + const running = await readRun(run.id) + expect(running.status).toBe('running') + expect(running.heartbeatAt).toBeTruthy() + return { + articleIds: [articleId], + finalStatuses: { brief_review: 1 }, + stages: [], + failed: 0, + failures: [], + } + }) + await executeContentRun(payload, run) + const done = await readRun(run.id) + expect(done.status).toBe('succeeded') + expect(done.finalStatuses).toEqual({ brief_review: 1 }) + }) + + it('refuses a run that recovery already failed before the worker reached it', async () => { + const run = await createRun({ status: 'failed', errorSummary: 'recovered earlier' }) + await expect(executeContentRun(payload, run)).rejects.toThrow('no longer running') + expect(runPipelineMock).not.toHaveBeenCalled() + const after = await readRun(run.id) + expect(after.status).toBe('failed') + expect(after.errorSummary).toBe('recovered earlier') + }) + + it('fails its still-queued run when the claim itself errors', async () => { + const run = await createRun({ requestedBy: 'lease-test-refuse-claim' }) + // The claim write fails in the database, the way a dropped connection or + // a failed transaction would; the row is left queued. + await db().execute(sql` + CREATE OR REPLACE FUNCTION lease_test_refuse_claim() RETURNS trigger AS $fn$ + BEGIN + IF NEW.status = 'running' AND NEW.requested_by = 'lease-test-refuse-claim' THEN + RAISE EXCEPTION 'claim refused by the test'; + END IF; + RETURN NEW; + END + $fn$ LANGUAGE plpgsql; + CREATE TRIGGER lease_test_refuse_claim BEFORE UPDATE ON pipeline_runs + FOR EACH ROW EXECUTE FUNCTION lease_test_refuse_claim();`) + try { + await expect(executeContentRun(payload, run)).rejects.toThrow() + } finally { + await db().execute(sql` + DROP TRIGGER IF EXISTS lease_test_refuse_claim ON pipeline_runs; + DROP FUNCTION IF EXISTS lease_test_refuse_claim();`) + } + expect(runPipelineMock).not.toHaveBeenCalled() + // Payload fails the job for good (no retries), so a queued row left here + // would block every later run with nothing to recover it. + const after = await readRun(run.id) + expect(after.status).toBe('failed') + expect(after.errorSummary).toBeTruthy() + expect(after.completedAt).toBeTruthy() + }) + + it('never settles a run another handler is running', async () => { + const heartbeatAt = new Date().toISOString() + const run = await createRun({ status: 'running', startedAt: heartbeatAt, heartbeatAt }) + await expect(executeContentRun(payload, run)).rejects.toThrow('no longer running') + const after = await readRun(run.id) + expect(after.status).toBe('running') + expect(after.errorSummary ?? null).toBeNull() + await payload.update({ + collection: 'pipeline-runs', + id: run.id, + data: { status: 'failed' }, + overrideAccess: true, + }) + }) + + it('does not write over a run that was recovered while it was working', async () => { + const run = await createRun({}) + runPipelineMock.mockImplementation(async () => { + // The worker stalls past the lease; the scheduled task recovers the run. + await payload.update({ + collection: 'pipeline-runs', + id: run.id, + data: { heartbeatAt: ago(RUN_LEASE_TIMEOUT_MS + 60_000) }, + overrideAccess: true, + }) + const { recoveredRuns } = await recoverStaleRuns(payload) + expect(recoveredRuns).toContain(run.runId) + // Then it wakes up and finishes as if nothing happened. + return { + articleIds: [articleId], + finalStatuses: { brief_review: 1 }, + stages: [], + failed: 0, + failures: [], + } + }) + + // A heartbeat interval far longer than the test, so only the fence on the + // final write can stop it. + await expect( + executeContentRun(payload, run, { heartbeatIntervalMs: 60 * 60_000 }), + ).rejects.toThrow('no longer running') + + const after = await readRun(run.id) + expect(after.status).toBe('failed') + expect(after.errorSummary).toContain('worker stopped responding') + expect(after.finalStatuses ?? null).toBeNull() + }) + + it('aborts the pipeline once its heartbeat finds the run recovered', async () => { + const run = await createRun({}) + let sawAbort = false + runPipelineMock.mockImplementation(async (_ctx, options) => { + await payload.update({ + collection: 'pipeline-runs', + id: run.id, + data: { status: 'failed', errorSummary: 'recovered under the worker' }, + overrideAccess: true, + }) + const signal = options?.signal + const deadline = Date.now() + 5_000 + while (!signal?.aborted && Date.now() < deadline) { + await new Promise((resolve) => setTimeout(resolve, 10)) + } + sawAbort = Boolean(signal?.aborted) + // What the real `runPipeline` does before its next write. + signal?.throwIfAborted() + return { articleIds: [], finalStatuses: {}, stages: [], failed: 0, failures: [] } + }) + + await expect(executeContentRun(payload, run, { heartbeatIntervalMs: 20 })).rejects.toThrow( + 'no longer running', + ) + expect(sawAbort).toBe(true) + const after = await readRun(run.id) + expect(after.status).toBe('failed') + expect(after.errorSummary).toBe('recovered under the worker') + }) +}) diff --git a/cms/tests/int/runLeaseFence.int.spec.ts b/cms/tests/int/runLeaseFence.int.spec.ts new file mode 100644 index 0000000..a2551f0 --- /dev/null +++ b/cms/tests/int/runLeaseFence.int.spec.ts @@ -0,0 +1,211 @@ +import { randomUUID } from 'node:crypto' +import { getPayload, type Payload } from 'payload' +import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest' + +import type { Stage } from '../../../pipeline/src/stages' + +// The real stage loop with one fake stage, so these tests exercise the actual +// article write the loop commits; only the workspace inputs are faked. +const fake = vi.hoisted(() => ({ stages: [] as Stage[], ahrefs: {} as unknown })) + +vi.mock('../../../pipeline/src/runContext', () => ({ + loadStageInputs: vi.fn().mockResolvedValue({ + tenant: { profile: { targetDomain: 'example.com' }, icps: [{ id: 1, primary: true }] }, + brandVoice: { name: 'Test voice' }, + }), + buildStageContext: vi.fn((payload: unknown, runId: string, mode: string) => ({ + payload, + runId, + mode, + tenant: { icps: [] }, + ahrefs: fake.ahrefs, + })), +})) +vi.mock('../../../pipeline/src/stages', async (importOriginal) => { + const actual = await importOriginal() + return { + ...actual, + runPipeline: ( + ctx: Parameters[0], + options: Parameters[1], + ) => actual.runPipeline(ctx, { ...options, stages: fake.stages }), + } +}) + +import config from '@/payload.config' +import { executeContentRun } from '@/jobs/contentRun' +import type { PipelineRun } from '@/payload-types' + +let payload: Payload +let templateId: number +const articleIds: number[] = [] +const runIds: number[] = [] + +async function topic() { + const article = await payload.create({ + collection: 'articles', + data: { keyword: `fence ${randomUUID()}`, status: 'topic_selected', template: templateId }, + depth: 0, + }) + articleIds.push(article.id) + return article +} + +async function selectedRun(articleId: number): Promise { + const run = await payload.create({ + collection: 'pipeline-runs', + overrideAccess: true, + data: { + runId: randomUUID(), + source: 'selected', + status: 'queued', + mode: 'mock', + template: templateId, + requestedCount: 1, + articles: [articleId], + requestedBy: 'test', + configFingerprint: 'test', + configSnapshot: {}, + }, + }) + runIds.push(run.id) + return run +} + +const readArticle = (id: number) => + payload.findByID({ collection: 'articles', id, depth: 0, overrideAccess: true }) +const readRun = (id: number) => + payload.findByID({ collection: 'pipeline-runs', id, depth: 0, overrideAccess: true }) + +const quietly = async (body: () => Promise): Promise => { + const spies = (['log', 'warn', 'error'] as const).map((name) => + vi.spyOn(console, name).mockImplementation(() => {}), + ) + try { + return await body() + } finally { + for (const spy of spies) spy.mockRestore() + } +} + +beforeAll(async () => { + payload = await getPayload({ config: await config }) + const template = await payload.create({ + collection: 'templates', + data: { name: `Fence ${randomUUID()}` }, + }) + templateId = template.id +}) + +afterAll(async () => { + for (const id of runIds) { + await payload.delete({ collection: 'pipeline-runs', id, overrideAccess: true }) + } + for (const id of articleIds) { + await payload.update({ + collection: 'articles', + id, + data: { archived: true }, + overrideAccess: true, + }) + } + await payload.delete({ collection: 'templates', id: templateId, overrideAccess: true }) +}) + +describe('the article write a content run commits', () => { + it('lands, with its audit, while the run owns its row', async () => { + const article = await topic() + const run = await selectedRun(article.id) + fake.stages = [ + { + name: 'research', + entryStatus: 'topic_selected', + exitStatus: 'brief_review', + run: async () => ({ data: {}, status: 'brief_review' }), + }, + ] + + await quietly(() => executeContentRun(payload, run, { heartbeatIntervalMs: 60 * 60_000 })) + + expect((await readArticle(article.id)).status).toBe('brief_review') + expect((await readRun(run.id)).status).toBe('succeeded') + }) + + it('is refused once the run was recovered, before the heartbeat notices', async () => { + const article = await topic() + const run = await selectedRun(article.id) + fake.stages = [ + { + name: 'research', + entryStatus: 'topic_selected', + exitStatus: 'brief_review', + run: async () => { + // Recovery fails the run while this article's work is in flight. + await payload.update({ + collection: 'pipeline-runs', + id: run.id, + data: { status: 'failed', errorSummary: 'recovered under the worker' }, + overrideAccess: true, + }) + return { data: {}, status: 'brief_review' } + }, + }, + ] + + // A heartbeat far slower than the test: only the fence can stop the write. + await expect( + quietly(() => executeContentRun(payload, run, { heartbeatIntervalMs: 60 * 60_000 })), + ).rejects.toThrow('no longer running') + + expect((await readArticle(article.id)).status).toBe('topic_selected') + const after = await readRun(run.id) + expect(after.status).toBe('failed') + expect(after.errorSummary).toBe('recovered under the worker') + }) +}) + +describe('the topics a discovery run creates', () => { + it('are refused once the run was recovered, before the heartbeat notices', async () => { + const keyword = `fence discovery ${randomUUID()}` + const run = await payload.create({ + collection: 'pipeline-runs', + overrideAccess: true, + data: { + runId: randomUUID(), + source: 'admin', + status: 'queued', + mode: 'mock', + template: templateId, + requestedCount: 1, + requestedBy: 'test', + configFingerprint: 'test', + configSnapshot: {}, + }, + }) + runIds.push(run.id) + fake.ahrefs = { + contentGapKeywords: async () => { + // Recovery fails the run while discovery is asking for topics. + await payload.update({ + collection: 'pipeline-runs', + id: run.id, + data: { status: 'failed', errorSummary: 'recovered under the worker' }, + overrideAccess: true, + }) + return [{ keyword, volume: 10, difficulty: 1, bestCompetitorPosition: 1 }] + }, + } + + await expect( + quietly(() => executeContentRun(payload, run, { heartbeatIntervalMs: 60 * 60_000 })), + ).rejects.toThrow('no longer running') + + const { totalDocs } = await payload.count({ + collection: 'articles', + where: { keyword: { equals: keyword } }, + overrideAccess: true, + }) + expect(totalDocs).toBe(0) + expect((await readRun(run.id)).errorSummary).toBe('recovered under the worker') + }) +}) diff --git a/docs/operations.md b/docs/operations.md index 301a3c2..94cf30a 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -10,7 +10,7 @@ All background work runs on Payload's jobs queue. In development every queue aut |---|---|---|---| | `content` | `npm run jobs:run --workspace cms` (`payload jobs:run --queue content --limit 1`) | your call (each invocation processes one job) | `content-run`: a full pipeline run | | `webhooks` | `npm run jobs:webhooks --workspace cms` (`payload jobs:run --queue webhooks`) | every minute or faster | `webhook-deliver`: signed status-event POSTs | -| `scheduled` | `npm run jobs:scheduled --workspace cms` (`payload jobs:run --queue scheduled --handle-schedules --limit 1`) | every minute or faster | `publish-due`: publishes due `approved` articles (cron-scheduled every 5 minutes). `collect-setup-suggestions`: the daily 03:00 scan behind the setup suggestions (see [setup-suggestions.md](setup-suggestions.md)). `--handle-schedules` is what enqueues the next occurrence of each | +| `scheduled` | `npm run jobs:scheduled --workspace cms` (`payload jobs:run --queue scheduled --handle-schedules --limit 1`) | every minute or faster | `publish-due`: publishes due `approved` articles (cron-scheduled every 5 minutes). `recover-stale-runs`: fails runs whose worker stopped responding (every 5 minutes; see [Stuck runs](#stuck-runs)). `collect-setup-suggestions`: the daily 03:00 scan behind the setup suggestions (see [setup-suggestions.md](setup-suggestions.md)). `--handle-schedules` is what enqueues the next occurrence of each | Invoke the npm scripts, or set `NODE_ENV=production` yourself if you call `payload jobs:run` directly. The Payload CLI does not set it, and without it the Postgres adapter runs its development schema push against the database on every invocation, outside migrations. The three scripts set `DISABLE_DEV_PUSH=true` so they are safe either way. @@ -20,6 +20,15 @@ Invoke the npm scripts, or set `NODE_ENV=production` yourself if you call `paylo - `content-run` has `retries: 0` and concurrency key `content-pipeline`: a failed run stays failed (its articles keep their statuses and the next run retries them), and two runs never execute concurrently. - One article's failure never fails its batch; it keeps its status and is retried by the next run. A run that advanced nothing and had failures is recorded `failed` with a redacted `errorSummary` on its `pipeline-runs` row. +### Stuck runs + +A run holds a lease on its `pipeline-runs` row while it is `running`. Whatever executes it — the `content-run` worker or `npm run pipeline:run` — writes `heartbeatAt` when it claims the row and every 60 seconds after that. Elapsed time alone never ends a run: a long run whose process is alive keeps refreshing its lease. + +- **Recovery.** `recover-stale-runs` (on the `scheduled` queue, every 5 minutes) fails any `running` run whose `heartbeatAt` — or `startedAt`, for a row with no heartbeat — is more than **15 minutes** old. It also releases the `content-run` job the dead worker left `processing`, by marking it failed (`hasError`), which frees the `content-pipeline` concurrency key so queued runs start again; the job is not re-run. A job that a worker took but never started (its run still `queued`) is released after the same 15 minutes, and its run is failed with it. +- **What an operator sees.** The run turns `failed` in the run bar and in Reports, with the summary "The worker stopped responding: no heartbeat since …". Its articles keep the status they last saved, and the next run picks them up again. No article or audit row is written by recovery. Worst case, from the process dying to the next run starting, is 15 minutes plus one 5-minute tick plus your scheduler cadence. +- **Fencing.** Every write a run makes to its own row after claiming it is conditional on the row still being `running`, and each article write (every topic discovery creates, and every write the stage loop commits) happens in one transaction with a lock on the run row, only while that row is still this run's and `running`. A process that was only stalled (not dead) and comes back after recovery finds its row failed: its next article write is refused and the run stops, model calls stop at the next step once its heartbeat notices, its final write is refused, and the recovered state stands. A worker that fails before it has claimed its run fails the run only if it is still `queued`. +- **Interrupting the CLI.** Ctrl-C (SIGINT) or SIGTERM marks a CLI run failed straight away. A CLI that is killed outright (SIGKILL, a lost machine) is recovered like a dead worker. + ### Scheduled publishing - An `approved` article with a `publishAt` in the past is published by the next `publish-due` occurrence: same update path as a manual publish, so gates, the audit row (`scheduled_publish`, actor `scheduler`), the status webhook, and the cache purge all fire. diff --git a/docs/tenant-context.md b/docs/tenant-context.md index 7b1738b..66d16eb 100644 --- a/docs/tenant-context.md +++ b/docs/tenant-context.md @@ -43,7 +43,8 @@ the second article was written against. ## Gating -A content run needs three things, and refuses to start without any of them: +A content run needs three things, and refuses to start without any of them — +whether it is started in the admin or with `npm run pipeline:run`: - an active brand voice - a target domain, from the global or the environment @@ -57,8 +58,13 @@ competitors and does not ask. and `governance.problems` is the list of what is missing, in the words an operator acts on — every caller interpolates that list rather than writing its own copy, so the setup screen, the content-run action, and the brief all say -the same thing. `cms/src/jobs/contentRun.ts` re-checks the same three before it -spends anything, for a job that was queued before an audience was archived. +the same thing. `runReadinessRefusal` turns it into the one refusal sentence: +the admin's run actions add a live-cost confirmation on top of it, and +`pipeline run` prints it and exits 1 before it registers a run or touches an +article. `cms/src/jobs/contentRun.ts` re-checks the same three before it spends +anything, for a job that was queued before an audience was archived. +`pipeline fetch` and `pipeline report` are not gated: one only buys topics, the +other only reads. An existing workspace is blocked by this until it has all three. "Start with the demo workspace" on `/admin` fills them in for Kettle & Burr, the home-espresso publisher, from the fixtures in @@ -452,7 +458,7 @@ fixtures are all derived from it. The model resolves through `resolveSetupAssistModel`: the Models global's "Setup assistant" field, then `SETUP_ASSIST_MODEL`, then the brand-voice -extraction model, then the platform default. In mock mode the demo workspace's +extraction model, then the generate model. In mock mode the demo workspace's own section comes back instead, put through the same parser, with the warning `Mock mode: returned the demo section instead of calling the model`. diff --git a/pipeline/scripts/ig-e2e.sh b/pipeline/scripts/ig-e2e.sh index ecb4eea..2228db8 100755 --- a/pipeline/scripts/ig-e2e.sh +++ b/pipeline/scripts/ig-e2e.sh @@ -2,10 +2,12 @@ # # The information-gain walkthrough, end to end, in mock mode. # -# Seeds the templates and the evidence-source rules, creates a topic, assigns a -# template, runs all four stages, and asserts on what the scoring stage left -# behind: the article's status, its information-gain summary, the immutable run -# row, and the cost-log rows for the three information-gain LLM passes. Then it +# Seeds the templates, the evidence-source rules and the demo workspace (brand +# voice, target domain, audiences — what `pipeline:run`'s setup gate requires), +# creates a topic, assigns a template, runs all four stages, and asserts on what +# the scoring stage left behind: the article's status, its information-gain +# summary, the immutable run row, and the cost-log rows for the three +# information-gain LLM passes. Then it # runs the pipeline a second time and asserts that nothing moved — the stages # are convergent, so a re-run over a settled article must be a no-op. # @@ -94,12 +96,15 @@ export MOCK_MODE=true info "MOCK_MODE=true (pinned for this run)" # --------------------------------------------------------------------------- -step=$((step + 1)); log "$step. Seed templates, admin user, and evidence sources" +step=$((step + 1)); log "$step. Seed templates, admin user, evidence sources, and the demo workspace" # The evidence-source rules matter as much as the templates here: integrity is # support x sourceQuality x exactness and an unclassified domain is capped at # 0.75, so without the seeded `primary` rows every novel number in the demo # draft is blocked and the walkthrough ends at `blocked` rather than `verified`. -npm run seed +# `--with-brand-voice` adds the demo brand voice, workspace profile and +# audiences: `pipeline:run` refuses to start without them, like a run started +# from the admin. +npm run seed -- --with-brand-voice # --------------------------------------------------------------------------- step=$((step + 1)); log "$step. Fetch content-gap topics" diff --git a/pipeline/src/config.ts b/pipeline/src/config.ts index 432966a..0ac8db3 100644 --- a/pipeline/src/config.ts +++ b/pipeline/src/config.ts @@ -3,6 +3,8 @@ import { fileURLToPath } from 'node:url' import dotenv from 'dotenv' +import { runModeFromEnv } from '../../cms/src/lib/runMode' + const here = path.dirname(fileURLToPath(import.meta.url)) export const repoRoot = path.resolve(here, '..', '..') @@ -30,26 +32,15 @@ export interface PipelineConfig { ahrefsCountry: string } -function parseBool(value: string | undefined): boolean | undefined { - if (value === undefined || value === '') return undefined - if (['true', '1', 'yes'].includes(value.toLowerCase())) return true - if (['false', '0', 'no'].includes(value.toLowerCase())) return false - throw new Error(`Cannot parse boolean env value: ${value}`) -} - function buildConfig(): PipelineConfig { const anthropicApiKey = process.env.ANTHROPIC_API_KEY || undefined const openaiApiKey = process.env.OPENAI_API_KEY || undefined // Per-stage model choice lives in the admin's Models global (see models.ts), // so the per-model key check happens there once the run knows its models. - // Mock is the local default, and only a provider key can lift it: nothing - // else a dev machine happens to carry may flip it into live runs. - const mockMode = - parseBool(process.env.MOCK_MODE) ?? (anthropicApiKey === undefined && openaiApiKey === undefined) - if (!mockMode && anthropicApiKey === undefined && openaiApiKey === undefined) { - throw new Error('MOCK_MODE=false requires ANTHROPIC_API_KEY or OPENAI_API_KEY to be set') - } + // The mock/live rule is shared with the CMS (`runMode.ts`) and never throws: + // this module loads inside the admin, which must stay up on a bad env. + const mockMode = runModeFromEnv(process.env) === 'mock' const ahrefsApiKey = process.env.AHREFS_API_KEY || undefined // Domain and competitors are workspace facts, not deployment facts: the diff --git a/pipeline/src/corpus/snapshot.ts b/pipeline/src/corpus/snapshot.ts index ac12616..d17ce62 100644 --- a/pipeline/src/corpus/snapshot.ts +++ b/pipeline/src/corpus/snapshot.ts @@ -259,6 +259,66 @@ export async function getOrBuildSnapshot( // A skipped page (a PDF, say) is as unusable as a failed one for the baseline. const unusablePages = crawled.length - okPages.length + const unverifiedByPosition = new Map() + const pageRowsFor = (claimCountFor: (docId: string) => number): PageRow[] => + crawled.map(({ page, fetched }) => ({ + position: page.position, + url: page.url, + title: fetched.title ?? page.title, + domain: hostnameOf(page.url), + domainRating: page.domainRating, + fetchStatus: fetched.status, + failureReason: fetched.reason, + chars: fetched.chars, + textHash: fetched.status === 'ok' ? textHash(fetched.text) : null, + text: fetched.status === 'ok' ? fetched.text : null, + claimCount: claimCountFor(`serp:${page.position}`), + unverifiedExcerptCount: unverifiedByPosition.get(page.position) ?? null, + })) + + // Nothing readable on the SERP: the snapshot is `empty` whatever else we + // could add, so record the failed crawl and stop before paying for internal + // corpus extraction and clustering that cannot rescue it. + if (okPages.length === 0) { + const created = await ctx.payload.create({ + collection: 'corpus-snapshots', + overrideAccess: true, + data: { + keyword: article.keyword, + keywordKey: key, + country, + capturedAt: now.toISOString(), + status: 'empty', + pipelineRunId: ctx.runId, + snapshotHash: snapshotHash([]), + models: { claimExtraction: ctx.models.claimExtraction }, + queryCluster, + pages: pageRowsFor(() => 0), + internalCorpus: [], + baselineClaims: [], + facets: [], + gaps: [], + baselineDocCount: 0, + failedPageCount: unusablePages, + }, + }) + console.log( + `[research] built corpus snapshot ${created.id} for "${article.keyword}": ` + + `0/${crawled.length} pages read; skipped internal corpus and clustering`, + ) + throw new Error( + emptySnapshotMessage({ + snapshotId: created.id, + keyword: article.keyword, + okPages: 0, + crawledPages: crawled.length, + unusablePages, + internalDocs: 0, + claims: 0, + }), + ) + } + const serpClaims = await mapWithConcurrency(okPages, CONCURRENCY, async ({ page, fetched }) => { const { json } = await completeJSONLogged(ctx, 'claimExtraction', article.id, { system: PAGE_CLAIM_EXTRACTION_SYSTEM, @@ -331,9 +391,6 @@ export async function getOrBuildSnapshot( ...serpClaims.flatMap((entry) => entry.claims), ...internalEntries.flatMap((entry) => entry.claims), ] - const unverifiedByPosition = new Map( - serpClaims.map((entry) => [entry.position, entry.unverified]), - ) const baselineDocCount = okPages.length + internalEntries.length // Cluster the pooled claims into consensus facets and the gaps they leave. @@ -364,20 +421,8 @@ export async function getOrBuildSnapshot( const claimCountFor = (docId: string): number => claims.filter((claim) => claim.source.docId === docId).length - const pageRows: PageRow[] = crawled.map(({ page, fetched }) => ({ - position: page.position, - url: page.url, - title: fetched.title ?? page.title, - domain: hostnameOf(page.url), - domainRating: page.domainRating, - fetchStatus: fetched.status, - failureReason: fetched.reason, - chars: fetched.chars, - textHash: fetched.status === 'ok' ? textHash(fetched.text) : null, - text: fetched.status === 'ok' ? fetched.text : null, - claimCount: claimCountFor(`serp:${page.position}`), - unverifiedExcerptCount: unverifiedByPosition.get(page.position) ?? null, - })) + for (const entry of serpClaims) unverifiedByPosition.set(entry.position, entry.unverified) + const pageRows = pageRowsFor(claimCountFor) const status = snapshotStatus(okPages.length, unusablePages, claims.length) diff --git a/pipeline/src/fetchTopics.ts b/pipeline/src/fetchTopics.ts index 54bd9f2..836c0a6 100644 --- a/pipeline/src/fetchTopics.ts +++ b/pipeline/src/fetchTopics.ts @@ -1,9 +1,14 @@ +import type { PayloadRequest } from 'payload' + import { notOurUserMatch } from './tenant' import { opportunityScore } from './ahrefs' -import type { StageContext } from './stages' +import type { RunPipelineOptions, StageContext } from './stages' /** fetch is Ahrefs-only — no LLM call — so it needs none of StageContext's model/voice/style-guide fields. */ -export type FetchContext = Pick +export type FetchContext = Pick< + StageContext, + 'ahrefs' | 'payload' | 'runId' | 'mode' | 'tenant' | 'signal' +> export interface FetchTopicsOptions { count: number @@ -14,6 +19,12 @@ export interface FetchTopicsOptions { * means the board shows the audience before research has run. */ icpId?: number | null + /** + * Commits each topic only while the run still owns its row, as the stage + * loop does for article writes (`RunPipelineOptions.commitArticle`). + * Discovery stops once it refuses. + */ + commitArticle?: RunPipelineOptions['commitArticle'] } export interface FetchTopicsResult { @@ -28,6 +39,7 @@ export async function fetchTopics( options: FetchTopicsOptions, ): Promise { const count = Math.max(1, Math.min(5, Math.round(options.count))) + ctx.signal?.throwIfAborted() const gaps = await ctx.ahrefs.contentGapKeywords() const ranked = [...gaps].sort( (a, b) => opportunityScore(b.volume, b.difficulty) - opportunityScore(a.volume, a.difficulty), @@ -59,37 +71,50 @@ export async function fetchTopics( skippedIds.push(existingId) continue } - const article = await ctx.payload.create({ - collection: 'articles', - data: { - keyword: gap.keyword, - title: sentenceCase(gap.keyword), - status: 'topic_selected', - template: options.templateId, - ...(options.icpId != null ? { icp: options.icpId } : {}), - }, - context: { - articleAudit: { - actor: 'pipeline', - actorType: 'pipeline', - event: 'topic_created', - pipelineRunId: ctx.runId, - stage: 'fetch', - summary: `Topic created from ${ctx.mode} content-gap research`, - details: { - mode: ctx.mode, - keyword: gap.keyword, - volume: gap.volume, - difficulty: gap.difficulty, - bestCompetitorPosition: gap.bestCompetitorPosition, + // A run that lost its lease creates no further topics. + ctx.signal?.throwIfAborted() + const created: { id?: number } = {} + const create = async (req?: PayloadRequest) => { + const doc = await ctx.payload.create({ + collection: 'articles', + ...(req ? { req } : {}), + data: { + keyword: gap.keyword, + title: sentenceCase(gap.keyword), + status: 'topic_selected', + template: options.templateId, + ...(options.icpId != null ? { icp: options.icpId } : {}), + }, + context: { + articleAudit: { + actor: 'pipeline', + actorType: 'pipeline', + event: 'topic_created', + pipelineRunId: ctx.runId, + stage: 'fetch', + summary: `Topic created from ${ctx.mode} content-gap research`, + details: { + mode: ctx.mode, + keyword: gap.keyword, + volume: gap.volume, + difficulty: gap.difficulty, + bestCompetitorPosition: gap.bestCompetitorPosition, + }, }, }, - }, - }) - existingByKeyword.set(gap.keyword, article.id) - createdIds.push(article.id) + }) + created.id = doc.id + } + const owned = options.commitArticle + ? await options.commitArticle(create) + : (await create(), true) + if (!owned || created.id === undefined) { + throw ctx.signal?.reason ?? new Error(`Run ${ctx.runId} no longer owns its row.`) + } + existingByKeyword.set(gap.keyword, created.id) + createdIds.push(created.id) console.log( - `[fetch] created article ${article.id} "${gap.keyword}" (volume ${gap.volume}, difficulty ${gap.difficulty}, best competitor position ${gap.bestCompetitorPosition})`, + `[fetch] created article ${created.id} "${gap.keyword}" (volume ${gap.volume}, difficulty ${gap.difficulty}, best competitor position ${gap.bestCompetitorPosition})`, ) } console.log(`[fetch] created ${createdIds.length} article(s) at status topic_selected`) diff --git a/pipeline/src/index.ts b/pipeline/src/index.ts index e4cb65c..c1465f6 100644 --- a/pipeline/src/index.ts +++ b/pipeline/src/index.ts @@ -1,12 +1,26 @@ import { buildStageContext, loadStageInputs } from './runContext' import { randomUUID } from 'node:crypto' +import type { Payload } from 'payload' + +import type { PipelineRun } from '../../cms/src/payload-types' + +import { ActivePipelineRunError, createCliRun } from '../../cms/src/lib/createPipelineRun' +import { loadWorkspaceSetup } from '../../cms/src/lib/loadWorkspaceReadiness' +import { + RunLeaseLostError, + safeRunError, + settledRunData, + startRunHeartbeat, + updateRunIfStatus, +} from '../../cms/src/lib/pipelineRunLease' +import { runReadinessRefusal } from '../../cms/src/lib/workspaceReadiness' import { createAhrefsClient } from './ahrefs' import { config } from './config' import { type FetchContext, fetchTopics } from './fetchTopics' import { initPayload } from './payloadClient' import { printReport, type ReportPeriod } from './report' -import { describeFailures, runPipeline } from './stages' +import { describeFailures, type RunPipelineResult, runPipeline, stages } from './stages' import { loadTenantContext } from './tenant' interface CliArgs { @@ -21,6 +35,7 @@ function usage(): never { 'Usage: pipeline [--count N] [--template NAME_OR_ID] [--period week|month]\n' + ' fetch --template NAME_OR_ID --count N create up to N templated topics (1-5, default 5)\n' + ' run advance all articles with a template through research -> generate -> qa -> informationGain\n' + + ' (refused until setup is finished, or while another run is active)\n' + ' report --period week|month print pass rates, spend, and failure digest (default week)', ) process.exit(1) @@ -80,6 +95,135 @@ async function resolveTemplateId( return result.docs[0].id } +/** Every article some stage would pick up now: the CLI run's whole batch. */ +async function waitingArticleIds(payload: Payload): Promise { + const { docs } = await payload.find({ + collection: 'articles', + where: { + and: [ + { status: { in: [...new Set(stages.map((stage) => stage.entryStatus))] } }, + { template: { exists: true } }, + { archived: { not_equals: true } }, + ], + }, + select: { status: true }, + pagination: false, + limit: 0, + depth: 0, + }) + return docs.map((doc) => doc.id) +} + +/** + * `pipeline run`: the same setup gate as a run started in the CMS, then a + * `cli` row on `pipeline-runs` under the same lock, with a heartbeat, so the + * CLI cannot overlap the content worker or another CLI on the same articles. + */ +async function runCommand( + payload: Payload, + runId: string, + mode: 'mock' | 'live', +): Promise { + const { readiness } = await loadWorkspaceSetup(payload) + const refusal = runReadinessRefusal(readiness) + if (refusal) { + console.error(`[pipeline] ${refusal}`) + return 1 + } + + const inputs = await loadStageInputs(payload, mode) + const { brandVoice } = inputs + console.log(`[pipeline] brand voice: ${brandVoice ? `"${brandVoice.name}"` : 'none'}`) + const ctx = buildStageContext(payload, runId, mode, inputs) + + // Listed on the row so admin and selected runs refuse these articles while + // this run holds them. Only these are advanced: a piece created mid-run + // waits for the next run rather than being touched unlisted. + const articleIds = await waitingArticleIds(payload) + let runRow: PipelineRun + try { + runRow = await createCliRun(payload, { + runId, + mode, + readiness, + articleIds, + requestedBy: 'cli', + }) + } catch (error) { + if (error instanceof ActivePipelineRunError) { + console.error(`[pipeline] ${error.message} Wait for it to finish, then run again.`) + return 1 + } + throw error + } + const heartbeat = startRunHeartbeat(payload, runRow) + + // Ctrl-C ends the run on its row now, rather than leaving it to block every + // other run until recovery notices the missing heartbeat. + const interrupt = (signal: NodeJS.Signals) => { + heartbeat.stop() + console.error(`[pipeline] ${signal}: marking run ${runId} failed`) + void updateRunIfStatus(payload, runRow.id, 'running', { + status: 'failed', + errorSummary: `Interrupted by ${signal} before it finished.`, + completedAt: new Date().toISOString(), + }) + .catch(() => false) + .then(() => exitAfterFlush(130)) + } + process.once('SIGINT', interrupt) + process.once('SIGTERM', interrupt) + + try { + // `runPipeline` treats an empty id list as "no restriction", so a run with + // nothing waiting must not reach it. + const summary: RunPipelineResult = + articleIds.length === 0 + ? { articleIds: [], finalStatuses: {}, stages: [], failed: 0, failures: [] } + : await runPipeline(ctx, { + articleIds, + signal: heartbeat.signal, + commitArticle: heartbeat.commit, + }) + if (!(await updateRunIfStatus(payload, runRow.id, 'running', settledRunData(summary)))) { + throw new RunLeaseLostError(runId) + } + const warned = summary.stages.reduce((sum, entry) => sum + entry.warned, 0) + if (warned > 0) { + // Not a failure: these articles advanced. Printed so a scheduled run's log + // shows bookkeeping that silently did not happen. + const detail = summary.stages + .filter((entry) => entry.warned > 0) + .map((entry) => `${entry.stage} ${entry.warned}/${entry.total}`) + .join(', ') + console.warn(`[pipeline] ${warned} article(s) advanced with warnings (${detail})`) + } + if (summary.failed > 0) { + // Exit non-zero so a scheduled run's alerting and retry policy see the + // stuck articles; the batch itself already ran to completion. + console.error( + `[pipeline] ${summary.failed} article(s) failed (${describeFailures(summary)}); ` + + 'they kept their status and the next run retries them', + ) + return 1 + } + return 0 + } catch (error) { + if (!(error instanceof RunLeaseLostError)) { + await updateRunIfStatus(payload, runRow.id, 'running', { + status: 'failed', + errorSummary: safeRunError(error, 'Pipeline run failed'), + completedAt: new Date().toISOString(), + }) + } + throw error + } finally { + heartbeat.stop() + process.off('SIGINT', interrupt) + process.off('SIGTERM', interrupt) + } +} + /** `0` unless something failed; `main` sets it and the single exit at the end reads it. */ async function main(): Promise { const args = parseArgs(process.argv.slice(2)) @@ -115,30 +259,7 @@ async function main(): Promise { icpId: (tenant.icps.find((icp) => icp.primary)?.id as number | undefined) ?? null, }) } else if (args.command === 'run') { - const inputs = await loadStageInputs(payload, mode) - const { brandVoice } = inputs - console.log(`[pipeline] brand voice: ${brandVoice ? `"${brandVoice.name}"` : 'none'}`) - const ctx = buildStageContext(payload, runId, mode, inputs) - const summary = await runPipeline(ctx) - const warned = summary.stages.reduce((sum, entry) => sum + entry.warned, 0) - if (warned > 0) { - // Not a failure: these articles advanced. Printed so a scheduled run's log - // shows bookkeeping that silently did not happen. - const detail = summary.stages - .filter((entry) => entry.warned > 0) - .map((entry) => `${entry.stage} ${entry.warned}/${entry.total}`) - .join(', ') - console.warn(`[pipeline] ${warned} article(s) advanced with warnings (${detail})`) - } - if (summary.failed > 0) { - // Exit non-zero so a scheduled run's alerting and retry policy see the - // stuck articles; the batch itself already ran to completion. - console.error( - `[pipeline] ${summary.failed} article(s) failed (${describeFailures(summary)}); ` + - 'they kept their status and the next run retries them', - ) - return 1 - } + return runCommand(payload, runId, mode) } return 0 } diff --git a/pipeline/src/llm.ts b/pipeline/src/llm.ts index ae7a636..21a0b6a 100644 --- a/pipeline/src/llm.ts +++ b/pipeline/src/llm.ts @@ -32,6 +32,37 @@ export interface LlmClient { completeJSON(stage: LlmStage, request: LlmRequest, model: string): Promise } +export interface LlmBilled { + provider: LlmProvider + model: string + usage: LlmResult['usage'] +} + +export type LlmReplyErrorCode = + | 'max_tokens' + | 'refusal' + | 'pause_turn' + | 'incomplete' + | 'no_text' + | 'invalid_json' + +/** + * The provider answered (and billed) but the reply is unusable: cut off at the + * token cap, refused, paused, empty, or not JSON. Carries what was billed so + * `completeJSONLogged` can still write the cost row; without it a retry buys + * the same call again and nothing records the first. + */ +export class LlmReplyError extends Error { + constructor( + message: string, + public readonly code: LlmReplyErrorCode, + public readonly billed: LlmBilled, + ) { + super(message) + this.name = 'LlmReplyError' + } +} + const JSON_ONLY = 'Reply with only a single JSON object. No prose, no code fences.' let anthropicClient: Anthropic | undefined @@ -74,42 +105,116 @@ function parseJsonReply(text: string, stage: LlmStage): unknown { } } +/** + * `web_search_20260209` (dynamic filtering) is served by the Fable/Mythos + * models, Opus 4.6 and later, Sonnet 4.6 and later. Older models, Haiku + * included, only know the basic `web_search_20250305`. + */ +const DYNAMIC_WEB_SEARCH_MODEL = + /^claude-(?:(?:fable|mythos)-|opus-(?:5|4-[6-9])|sonnet-(?:5|4-[6-9]))/ + +export function webSearchToolFor(model: string) { + const type = DYNAMIC_WEB_SEARCH_MODEL.test(model.trim()) + ? ('web_search_20260209' as const) + : ('web_search_20250305' as const) + return { type, name: 'web_search' as const, max_uses: 5 } +} + +/** + * The reply text: the text blocks after the last non-text block, joined. A + * search reply interleaves narration, tool calls and results, and the answer + * is whatever follows the last of them; cited text is split across several + * blocks (one per citation), so taking only the final block would keep a + * fragment of the JSON. + */ +export function anthropicReplyText(content: readonly { type: string; text?: string }[]): string { + let start = 0 + content.forEach((block, index) => { + if (block.type !== 'text' && block.type !== 'thinking' && block.type !== 'redacted_thinking') { + start = index + 1 + } + }) + return content + .slice(start) + .filter((block) => block.type === 'text') + .map((block) => block.text ?? '') + .join('') +} + +function parseOrThrow(text: string, stage: LlmStage, billed: LlmBilled): unknown { + try { + return parseJsonReply(text, stage) + } catch (error) { + throw new LlmReplyError( + error instanceof Error ? error.message : String(error), + 'invalid_json', + billed, + ) + } +} + +/** Provider SDK clients, injectable so tests can supply fakes. */ +export interface LlmSdkClients { + anthropic?: Pick + openai?: Pick +} + async function completeJSONAnthropic( stage: LlmStage, request: LlmRequest, model: string, + sdk: LlmSdkClients, ): Promise { try { - const response = await getClient().messages.create({ + const response = await (sdk.anthropic ?? getClient()).messages.create({ model, max_tokens: 16000, system: `${request.system}\n\n${JSON_ONLY}`, messages: [{ role: 'user', content: request.user }], - ...(request.needWebSearch - ? { - tools: [{ type: 'web_search_20260209', name: 'web_search', max_uses: 5 }], - } - : {}), + ...(request.needWebSearch ? { tools: [webSearchToolFor(model)] } : {}), }) - const textBlocks = response.content.filter( - (block): block is Anthropic.TextBlock => block.type === 'text', - ) - const finalText = textBlocks.at(-1)?.text - if (!finalText) { - throw new Error( - `[llm:${stage}] response contained no text block (stop_reason: ${response.stop_reason})`, - ) - } - return { - json: parseJsonReply(finalText, stage), + const billed: LlmBilled = { + provider: 'anthropic', + model, usage: { inputTokens: response.usage.input_tokens, outputTokens: response.usage.output_tokens, webSearchRequests: response.usage.server_tool_use?.web_search_requests ?? 0, }, - provider: 'anthropic', - model, } + if (response.stop_reason === 'max_tokens') { + throw new LlmReplyError( + `[llm:${stage}] reply truncated at max_tokens (16000) before it was complete`, + 'max_tokens', + billed, + ) + } + if (response.stop_reason === 'refusal') { + const details = response.stop_details + throw new LlmReplyError( + `[llm:${stage}] the model refused this request (stop_reason: refusal` + + `${details?.category ? `, category: ${details.category}` : ''}` + + `${details?.explanation ? `, ${details.explanation}` : ''})`, + 'refusal', + billed, + ) + } + if (response.stop_reason === 'pause_turn') { + throw new LlmReplyError( + `[llm:${stage}] the model paused its turn (stop_reason: pause_turn) before answering; resuming a paused turn is not supported`, + 'pause_turn', + billed, + ) + } + const finalText = anthropicReplyText(response.content) + if (!finalText) { + throw new LlmReplyError( + `[llm:${stage}] response contained no text block (stop_reason: ${response.stop_reason})`, + 'no_text', + billed, + ) + } + return { json: parseOrThrow(finalText, stage, billed), usage: billed.usage, provider: 'anthropic', model } } catch (error) { if (error instanceof Anthropic.AuthenticationError) { throw new Error(`[llm:${stage}] invalid ANTHROPIC_API_KEY: ${error.message}`) @@ -133,9 +238,10 @@ async function completeJSONOpenAI( stage: LlmStage, request: LlmRequest, model: string, + sdk: LlmSdkClients, ): Promise { try { - const response = await getOpenAI().responses.create({ + const response = await (sdk.openai ?? getOpenAI()).responses.create({ model, instructions: `${request.system}\n\n${JSON_ONLY}`, // `JSON_ONLY` is repeated on the input, not just the instructions: @@ -158,29 +264,49 @@ async function completeJSONOpenAI( : { text: { format: { type: 'json_object' as const } } }), }) const finalText = response.output_text + const billed: LlmBilled = { + provider: 'openai', + model, + usage: { + inputTokens: response.usage?.input_tokens ?? 0, + outputTokens: response.usage?.output_tokens ?? 0, + webSearchRequests: response.output.filter((item) => item.type === 'web_search_call').length, + }, + } // A reply cut off at the token cap is still *text*, and valid JSON right up // to the point it stops — so it slips past the empty check below and dies in // the parser as "not valid JSON", which sends whoever reads the log hunting // for a prompt bug that isn't there. Name the real cause. if (response.status === 'incomplete') { - throw new Error( + throw new LlmReplyError( `[llm:${stage}] reply truncated before it was complete ` + `(reason: ${response.incomplete_details?.reason ?? 'unknown'}, ` + `max_output_tokens: ${response.max_output_tokens ?? 'n/a'})`, + 'incomplete', + billed, + ) + } + // A refusal arrives as a `refusal` part on the message, with no output text. + const refusal = response.output + .flatMap((item) => (item.type === 'message' ? item.content : [])) + .find((part) => part.type === 'refusal') + if (!finalText && refusal) { + throw new LlmReplyError( + `[llm:${stage}] the model refused this request: ${refusal.refusal.slice(0, 300)}`, + 'refusal', + billed, ) } if (!finalText) { - throw new Error( + throw new LlmReplyError( `[llm:${stage}] response contained no text (status: ${response.status}, reason: ${response.incomplete_details?.reason ?? 'n/a'})`, + 'no_text', + billed, ) } return { - json: parseJsonReply(finalText, stage), - usage: { - inputTokens: response.usage?.input_tokens ?? 0, - outputTokens: response.usage?.output_tokens ?? 0, - webSearchRequests: response.output.filter((item) => item.type === 'web_search_call').length, - }, + json: parseOrThrow(finalText, stage, billed), + usage: billed.usage, provider: 'openai', model, } @@ -216,12 +342,17 @@ async function completeJSONMock( } } -function completeJSONLive(stage: LlmStage, request: LlmRequest, model: string): Promise { +function completeJSONLive( + stage: LlmStage, + request: LlmRequest, + model: string, + sdk: LlmSdkClients, +): Promise { switch (providerForModel(model)) { case 'openai': - return completeJSONOpenAI(stage, request, model) + return completeJSONOpenAI(stage, request, model, sdk) case 'anthropic': - return completeJSONAnthropic(stage, request, model) + return completeJSONAnthropic(stage, request, model, sdk) // `loadStageModels` rejects these before a run starts; this is the second // line of the same fence, for any caller that did not go through it. case 'unknown': @@ -232,14 +363,14 @@ function completeJSONLive(stage: LlmStage, request: LlmRequest, model: string): } /** Build a run-scoped adapter so queued runs do not depend on mutable module state. */ -export function createLlmClient(mode: 'mock' | 'live'): LlmClient { +export function createLlmClient(mode: 'mock' | 'live', sdk: LlmSdkClients = {}): LlmClient { return { completeJSON(stage, request, model) { // `fixtureKey` must survive: a `claimExtraction` request without it gets // the whole `{ page, facets }` fixture object instead of the one it asked // for, and the parsers reject that. if (mode === 'mock') return completeJSONMock(stage, model, request.fixtureKey) - return completeJSONLive(stage, request, model) + return completeJSONLive(stage, request, model, sdk) }, } } @@ -252,6 +383,8 @@ export interface CostContext { /** The run's mode. Decides the fallback client when `llm` is not supplied. */ mode?: 'mock' | 'live' llm?: LlmClient + /** The run's lease signal; an aborted run makes no further model calls. */ + signal?: AbortSignal } function jsonSnapshot(value: unknown): NonNullable { @@ -266,9 +399,14 @@ function jsonSnapshot(value: unknown): NonNullable { * with no cost row, or a missing migration behind it, must stop the stage. */ export class CostLogWriteError extends Error { - constructor(stage: LlmStage, cause: unknown) { + /** `afterFailure`: the unusable-reply error this row was being written for, if any. */ + constructor(stage: LlmStage, cause: unknown, afterFailure?: Error) { const reason = cause instanceof Error ? cause.message : String(cause) - super(`cost-log write failed for ${stage}: ${reason}`, { cause }) + super( + `cost-log write failed for ${stage}: ${reason}` + + (afterFailure ? ` (the model call had also failed: ${afterFailure.message})` : ''), + { cause }, + ) this.name = 'CostLogWriteError' } } @@ -283,12 +421,34 @@ export async function completeJSONLogged( articleId: number, request: LlmRequest, ): Promise { + ctx.signal?.throwIfAborted() const mode = ctx.mode ?? (config.mockMode ? 'mock' : 'live') - const result = await (ctx.llm ?? createLlmClient(mode)).completeJSON( - stage, - request, - ctx.models[stage], - ) + let result: LlmResult + try { + result = await (ctx.llm ?? createLlmClient(mode)).completeJSON(stage, request, ctx.models[stage]) + } catch (error) { + // The provider answered and billed, but the reply was unusable. The row + // goes in before the error is rethrown so the spend is on record and the + // retry does not look free; a row that cannot be written stops the stage + // the same way it does after a good reply. + if (error instanceof LlmReplyError) { + await writeCostRow(ctx, stage, articleId, request, error.billed, { error: error.message }, error) + } + throw error + } + await writeCostRow(ctx, stage, articleId, request, result, result.json) + return result +} + +async function writeCostRow( + ctx: CostContext, + stage: LlmStage, + articleId: number, + request: LlmRequest, + billed: LlmBilled | LlmResult, + response: unknown, + afterFailure?: Error, +): Promise { try { await ctx.payload.create({ collection: 'cost-log', @@ -297,23 +457,22 @@ export async function completeJSONLogged( pipelineRunId: ctx.runId, article: articleId, stage, - provider: result.provider, - model: result.model, - inputTokens: result.usage.inputTokens, - outputTokens: result.usage.outputTokens, - webSearchRequests: result.usage.webSearchRequests, + provider: billed.provider, + model: billed.model, + inputTokens: billed.usage.inputTokens, + outputTokens: billed.usage.outputTokens, + webSearchRequests: billed.usage.webSearchRequests, costUsd: costUsd( - result.model, - result.usage.inputTokens, - result.usage.outputTokens, - result.usage.webSearchRequests, + billed.model, + billed.usage.inputTokens, + billed.usage.outputTokens, + billed.usage.webSearchRequests, ), request: jsonSnapshot(request), - response: jsonSnapshot(result.json), + response: jsonSnapshot(response), }, }) } catch (error) { - throw new CostLogWriteError(stage, error) + throw new CostLogWriteError(stage, error, afterFailure) } - return result } diff --git a/pipeline/src/research.ts b/pipeline/src/research.ts index 9baffaa..cfa7a60 100644 --- a/pipeline/src/research.ts +++ b/pipeline/src/research.ts @@ -80,7 +80,7 @@ export const researchStage: Stage = { icp, }) return { - status: ctx.pauseForBrief === false ? 'researched' : 'brief_review', + status: 'brief_review', warnings: angles.warning ? [angles.warning] : [], data: { brief, diff --git a/pipeline/src/stages.ts b/pipeline/src/stages.ts index 8bafb22..8cf79bb 100644 --- a/pipeline/src/stages.ts +++ b/pipeline/src/stages.ts @@ -1,4 +1,4 @@ -import type { Payload, Where } from 'payload' +import type { Payload, PayloadRequest, Where } from 'payload' import type { Article, Template } from '../../cms/src/payload-types' @@ -42,11 +42,11 @@ export interface StageContext { /** Run-scoped provider adapter. Optional for backwards-compatible test contexts. */ llm?: LlmClient /** - * Stop at `brief_review` after research so a person approves the brief - * before writing is paid for. Defaults to on; only the onboarding smoke test - * turns it off, because nobody is there to approve. + * Aborted when the run loses its lease. Discovery checks it before each + * write and `completeJSONLogged` before each model call, so a long stage + * stops between steps instead of finishing work a recovered run gave up. */ - pauseForBrief?: boolean + signal?: AbortSignal } export interface StageOutcome { @@ -73,6 +73,20 @@ export interface RunPipelineOptions { articleIds?: number[] /** Stages to walk; defaults to the real pipeline. Tests pass their own. */ stages?: Stage[] + /** + * Aborted when the run's lease is lost (`cms/src/lib/pipelineRunLease.ts`): + * the run row was recovered under it. The run then throws the abort reason + * before it reads another batch or writes another article, rather than + * advancing work a newer run may now hold. + */ + signal?: AbortSignal + /** + * Commits one article write, given the request to write with, only while + * the run still owns its row; resolves false without calling `write` once it + * does not, and the run then stops. The CMS passes the run row lock here, so + * the ownership check and the write share one transaction. + */ + commitArticle?: (write: (req?: PayloadRequest) => Promise) => Promise } /** What one stage did to its batch in a single run. */ @@ -133,7 +147,18 @@ export async function runPipeline( const stageSummaries: StageRunSummary[] = [] const failures: StageFailure[] = [] let totalFailed = 0 + const signal = options.signal ?? ctx.signal + const stageCtx: StageContext = signal ? { ...ctx, signal } : ctx + const commit = + options.commitArticle ?? + (async (write: (req?: PayloadRequest) => Promise) => { + await write() + return true + }) + // Set when `commit` refuses a write: the run no longer owns its row. + let leaseLost: unknown = null for (const stage of options.stages ?? stages) { + signal?.throwIfAborted() // `archived` is deliberately part of the entry query rather than a board-only // filter: an archived topic still holds a pipeline status, so leaving it out // here would let a run pick up work somebody explicitly took off the board. @@ -160,31 +185,40 @@ export async function runPipeline( // which is the same convergent-rerun property the whole loop relies on. // The counts still come back in the result, so `index.ts` exits non-zero // and a scheduled run's alerting sees stuck articles. + signal?.throwIfAborted() try { - const outcome = await stage.run(article, ctx) + const outcome = await stage.run(article, stageCtx) const warnings = outcome.warnings ?? [] - await ctx.payload.update({ - collection: 'articles', - depth: 0, - id: article.id, - data: { ...outcome.data, status: outcome.status }, - context: { - articleAudit: { - actor: 'pipeline', - actorType: 'pipeline', - event: `${stage.name}_completed`, - pipelineRunId: ctx.runId, - stage: stage.name, - summary: `${stage.name} completed in ${ctx.mode} mode`, - details: { - mode: ctx.mode, - keyword: article.keyword, - output: outcome.data, - ...(warnings.length > 0 ? { warnings } : {}), + signal?.throwIfAborted() + const write = async (req?: PayloadRequest) => { + await ctx.payload.update({ + collection: 'articles', + depth: 0, + id: article.id, + ...(req ? { req } : {}), + data: { ...outcome.data, status: outcome.status }, + context: { + articleAudit: { + actor: 'pipeline', + actorType: 'pipeline', + event: `${stage.name}_completed`, + pipelineRunId: ctx.runId, + stage: stage.name, + summary: `${stage.name} completed in ${ctx.mode} mode`, + details: { + mode: ctx.mode, + keyword: article.keyword, + output: outcome.data, + ...(warnings.length > 0 ? { warnings } : {}), + }, }, }, - }, - }) + }) + } + if (!(await commit(write))) { + leaseLost = signal?.reason ?? new Error(`Run ${ctx.runId} no longer owns its row.`) + throw leaseLost + } // A stage outcome is only progress once the article write succeeds. // Keep the last persisted status when a later stage fails to save. processed.add(article.id) @@ -199,6 +233,9 @@ export async function runPipeline( `[${stage.name}] article ${article.id} "${article.keyword}" -> ${outcome.status}`, ) } catch (error) { + // A lost lease ends the whole run, not this one article. + if (signal?.aborted) throw signal.reason + if (leaseLost) throw leaseLost failed += 1 const message = error instanceof Error ? error.message : String(error) failures.push({ diff --git a/pipeline/test/fetchTopics.test.ts b/pipeline/test/fetchTopics.test.ts index 24d587c..44b393c 100644 --- a/pipeline/test/fetchTopics.test.ts +++ b/pipeline/test/fetchTopics.test.ts @@ -61,3 +61,70 @@ it('skips excluded keywords without spending a model call or exhausting the crea await fetchTopics(ctx,{count:1,templateId:1}) assert.deepEqual(created,['espresso grinder']) }) + +it('creates no topic once the run signal is aborted', async () => { + const created: string[] = [] + let asked = false + const controller = new AbortController() + controller.abort(new Error('lease lost')) + const ctx = { + tenant: emptyTenantContext(), + runId: 'aborted', + mode: 'mock' as const, + signal: controller.signal, + payload: { + find: async () => ({ docs: [] }), + create: async ({ data }: { data: { keyword: string } }) => { + created.push(data.keyword) + return { id: created.length } + }, + } as unknown as Payload, + ahrefs: { + contentGapKeywords: async () => { + asked = true + return [{ keyword: 'espresso grinder', volume: 10, difficulty: 1 }] + }, + } as unknown as AhrefsClient, + } + await assert.rejects(fetchTopics(ctx, { count: 1, templateId: 1 }), /lease lost/) + assert.equal(asked, false) + assert.deepEqual(created, []) +}) + +it('creates each topic through the run fence, and stops when it refuses', async () => { + const created: string[] = [] + const requests: unknown[] = [] + const fence = { req: { transactionID: 'lock' }, owns: true } + const ctx = { + tenant: emptyTenantContext(), + runId: 'fenced', + mode: 'mock' as const, + payload: { + find: async () => ({ docs: [] }), + create: async ({ data, req }: { data: { keyword: string }; req?: unknown }) => { + created.push(data.keyword) + requests.push(req) + // Recovery takes the row after the first topic lands. + fence.owns = false + return { id: created.length } + }, + } as unknown as Payload, + ahrefs: { + contentGapKeywords: async () => [ + { keyword: 'first topic', volume: 20, difficulty: 1, bestCompetitorPosition: 1 }, + { keyword: 'second topic', volume: 10, difficulty: 1, bestCompetitorPosition: 2 }, + ], + } as unknown as AhrefsClient, + } + const commitArticle = async (write: (req?: never) => Promise) => { + if (!fence.owns) return false + await write(fence.req as never) + return true + } + await assert.rejects( + fetchTopics(ctx, { count: 2, templateId: 1, commitArticle }), + /no longer owns its row/, + ) + assert.deepEqual(created, ['first topic']) + assert.deepEqual(requests, [fence.req]) +}) diff --git a/pipeline/test/llmPricing.test.ts b/pipeline/test/llmPricing.test.ts new file mode 100644 index 0000000..1e56995 --- /dev/null +++ b/pipeline/test/llmPricing.test.ts @@ -0,0 +1,22 @@ +import assert from 'node:assert/strict' +import test from 'node:test' + +import { LLM_CATALOG } from '../../cms/src/lib/llmCatalog' +import { costUsd } from '../src/pricing' + +// Anthropic list prices, USD per 1M tokens (https://platform.claude.com/docs/en/about-claude/pricing). +const ANTHROPIC_LIST_PRICES: Record = { + 'claude-fable-5': [10, 50], + 'claude-opus-5': [5, 25], + 'claude-sonnet-5': [2, 10], + 'claude-haiku-4-5': [1, 5], +} + +test('the catalog carries Anthropic list prices', () => { + for (const [id, [input, output]] of Object.entries(ANTHROPIC_LIST_PRICES)) { + const entry = LLM_CATALOG.find((model) => model.id === id) + assert.ok(entry, id) + assert.deepEqual([entry.input, entry.output], [input, output], id) + } + assert.equal(costUsd('claude-sonnet-5', 1_000_000, 1_000_000), 12) +}) diff --git a/pipeline/test/llmReplyErrors.test.ts b/pipeline/test/llmReplyErrors.test.ts new file mode 100644 index 0000000..f35855d --- /dev/null +++ b/pipeline/test/llmReplyErrors.test.ts @@ -0,0 +1,306 @@ +import assert from 'node:assert/strict' +import { describe, it } from 'node:test' +import type { Payload } from 'payload' + +import { + anthropicReplyText, + CostLogWriteError, + completeJSONLogged, + createLlmClient, + type CostContext, + LlmReplyError, + type LlmSdkClients, + webSearchToolFor, +} from '../src/llm' + +const USAGE = { input_tokens: 120, output_tokens: 340 } + +/** A fake Anthropic SDK whose `messages.create` returns the queued replies. */ +function fakeAnthropic(reply: unknown, seen: unknown[] = []): LlmSdkClients { + return { + anthropic: { + messages: { + create: async (params: unknown) => { + seen.push(params) + return reply + }, + }, + } as unknown as LlmSdkClients['anthropic'], + } +} + +function fakeOpenAI(reply: unknown): LlmSdkClients { + return { + openai: { responses: { create: async () => reply } } as unknown as LlmSdkClients['openai'], + } +} + +const anthropicReply = (over: Record) => ({ + content: [{ type: 'text', text: '{"ok":true}' }], + stop_reason: 'end_turn', + stop_details: null, + usage: USAGE, + ...over, +}) + +async function rejection(promise: Promise): Promise { + return promise.then( + () => assert.fail('expected a rejection'), + (error: unknown) => error, + ) +} + +const call = (sdk: LlmSdkClients, model = 'claude-opus-5', needWebSearch = false) => + createLlmClient('live', sdk).completeJSON('generate', { system: 's', user: 'u', needWebSearch }, model) + +describe('Anthropic reply errors carry what was billed', () => { + const billed = { + provider: 'anthropic', + model: 'claude-opus-5', + usage: { inputTokens: 120, outputTokens: 340, webSearchRequests: 2 }, + } + const usage = { ...USAGE, server_tool_use: { web_search_requests: 2 } } + + it('names max_tokens', async () => { + const error = await rejection( + call(fakeAnthropic(anthropicReply({ stop_reason: 'max_tokens', content: [{ type: 'text', text: '{"a":' }], usage }))), + ) + assert.ok(error instanceof LlmReplyError) + assert.equal(error.code, 'max_tokens') + assert.match(error.message, /truncated at max_tokens/) + assert.deepEqual(error.billed, billed) + }) + + it('names a refusal and its category', async () => { + const error = await rejection( + call( + fakeAnthropic( + anthropicReply({ + stop_reason: 'refusal', + content: [], + stop_details: { type: 'refusal', category: 'cyber', explanation: 'declined' }, + usage, + }), + ), + ), + ) + assert.ok(error instanceof LlmReplyError) + assert.equal(error.code, 'refusal') + assert.match(error.message, /refused.*category: cyber/) + assert.deepEqual(error.billed, billed) + }) + + it('names pause_turn', async () => { + const error = await rejection(call(fakeAnthropic(anthropicReply({ stop_reason: 'pause_turn', usage })))) + assert.ok(error instanceof LlmReplyError) + assert.equal(error.code, 'pause_turn') + assert.match(error.message, /pause_turn/) + }) + + it('names a reply with no text block', async () => { + const error = await rejection(call(fakeAnthropic(anthropicReply({ content: [], usage })))) + assert.ok(error instanceof LlmReplyError) + assert.equal(error.code, 'no_text') + assert.deepEqual(error.billed, billed) + }) + + it('keeps usage on a reply that is not JSON', async () => { + const error = await rejection( + call(fakeAnthropic(anthropicReply({ content: [{ type: 'text', text: 'Sorry, no.' }], usage }))), + ) + assert.ok(error instanceof LlmReplyError) + assert.equal(error.code, 'invalid_json') + assert.match(error.message, /not valid JSON/) + assert.deepEqual(error.billed, billed) + }) +}) + +describe('OpenAI reply errors carry what was billed', () => { + const response = (over: Record) => ({ + output_text: '{"ok":true}', + status: 'completed', + incomplete_details: null, + output: [{ type: 'web_search_call' }], + usage: { input_tokens: 7, output_tokens: 8 }, + ...over, + }) + const billed = { + provider: 'openai', + model: 'gpt-5.6-terra', + usage: { inputTokens: 7, outputTokens: 8, webSearchRequests: 1 }, + } + + it('names an incomplete reply', async () => { + const error = await rejection( + call( + fakeOpenAI( + response({ status: 'incomplete', incomplete_details: { reason: 'max_output_tokens' }, output_text: '{"a":' }), + ), + 'gpt-5.6-terra', + ), + ) + assert.ok(error instanceof LlmReplyError) + assert.equal(error.code, 'incomplete') + assert.match(error.message, /truncated.*max_output_tokens/) + assert.deepEqual(error.billed, billed) + }) + + it('names a refusal, which comes as a message part with no output text', async () => { + const error = await rejection( + call( + fakeOpenAI( + response({ + output_text: '', + output: [ + { type: 'web_search_call' }, + { type: 'message', content: [{ type: 'refusal', refusal: 'I can not help with that.' }] }, + ], + }), + ), + 'gpt-5.6-terra', + ), + ) + assert.ok(error instanceof LlmReplyError) + assert.equal(error.code, 'refusal') + assert.match(error.message, /refused this request: I can not help with that\./) + assert.deepEqual(error.billed, billed) + }) + + it('names an empty reply and a non-JSON reply', async () => { + const empty = await rejection(call(fakeOpenAI(response({ output_text: '' })), 'gpt-5.6-terra')) + assert.ok(empty instanceof LlmReplyError) + assert.equal(empty.code, 'no_text') + assert.deepEqual(empty.billed, billed) + const bad = await rejection(call(fakeOpenAI(response({ output_text: 'nope' })), 'gpt-5.6-terra')) + assert.ok(bad instanceof LlmReplyError) + assert.equal(bad.code, 'invalid_json') + assert.deepEqual(bad.billed, billed) + }) +}) + +describe('anthropicReplyText', () => { + it('joins the text blocks that follow the last tool result', () => { + const text = anthropicReplyText([ + { type: 'text', text: 'Let me search.' }, + { type: 'server_tool_use' }, + { type: 'web_search_tool_result' }, + { type: 'text', text: '{"claims": [' }, + { type: 'text', text: '{"id": 1}' }, + { type: 'text', text: ']}' }, + ]) + assert.equal(text, '{"claims": [{"id": 1}]}') + }) + + it('ignores thinking blocks and keeps every text block when there is no tool', () => { + assert.equal( + anthropicReplyText([ + { type: 'thinking' }, + { type: 'text', text: '{"a":' }, + { type: 'text', text: '1}' }, + ]), + '{"a":1}', + ) + }) + + it('parses a search reply whose JSON is split across cited blocks', async () => { + const result = await call( + fakeAnthropic( + anthropicReply({ + content: [ + { type: 'text', text: 'Searching' }, + { type: 'web_search_tool_result' }, + { type: 'text', text: '{"verdicts": [' }, + { type: 'text', text: '"supported"]}' }, + ], + }), + ), + 'claude-opus-5', + true, + ) + assert.deepEqual(result.json, { verdicts: ['supported'] }) + }) +}) + +describe('webSearchToolFor', () => { + it('uses the dynamic-filtering tool only on models that serve it', () => { + for (const model of ['claude-fable-5', 'claude-opus-5', 'claude-opus-5-5', 'claude-opus-4-6', 'claude-sonnet-5', 'claude-sonnet-5-5', 'claude-sonnet-4-6']) { + assert.equal(webSearchToolFor(model).type, 'web_search_20260209', model) + } + for (const model of ['claude-haiku-4-5', 'claude-sonnet-4-5', 'claude-opus-4-5', 'claude-haiku-5-5']) { + assert.equal(webSearchToolFor(model).type, 'web_search_20250305', model) + } + }) + + it('is sent on the request for a search stage', async () => { + const seen: { tools?: { type: string }[] }[] = [] + await call(fakeAnthropic(anthropicReply({}), seen), 'claude-haiku-4-5', true) + assert.equal(seen[0].tools?.[0].type, 'web_search_20250305') + }) +}) + +describe('completeJSONLogged writes a cost row for a billed failure', () => { + function harness(failWrite = false) { + const rows: Record[] = [] + const payload = { + async create({ collection, data }: { collection: string; data: Record }) { + assert.equal(collection, 'cost-log') + if (failWrite) throw new Error('db down') + rows.push(data) + return { id: rows.length } + }, + } as unknown as Payload + const ctx = (llm: CostContext['llm']): CostContext => ({ + payload, + runId: 'run-1', + mode: 'live', + models: { generate: 'claude-opus-5' } as CostContext['models'], + llm, + }) + return { rows, ctx } + } + + const failing = (error: unknown): CostContext['llm'] => ({ + completeJSON: async () => { + throw error + }, + }) + + it('records the spend, then rethrows the same error', async () => { + const { rows, ctx } = harness() + const original = new LlmReplyError('[llm:generate] reply truncated at max_tokens', 'max_tokens', { + provider: 'anthropic', + model: 'claude-opus-5', + usage: { inputTokens: 1_000_000, outputTokens: 0, webSearchRequests: 3 }, + }) + const error = await rejection(completeJSONLogged(ctx(failing(original)), 'generate', 5, { system: 's', user: 'u' })) + assert.equal(error, original) + assert.equal(rows.length, 1) + assert.equal(rows[0].inputTokens, 1_000_000) + assert.equal(rows[0].webSearchRequests, 3) + assert.equal(rows[0].provider, 'anthropic') + assert.equal(rows[0].article, 5) + // 1M input tokens at the catalog price plus three searches. + assert.equal(rows[0].costUsd, 5 + 0.03) + assert.deepEqual(rows[0].response, { error: original.message }) + }) + + it('stops with CostLogWriteError when the row for a billed failure cannot be written', async () => { + const { ctx } = harness(true) + const original = new LlmReplyError('[llm:generate] no text', 'no_text', { + provider: 'anthropic', + model: 'claude-opus-5', + usage: { inputTokens: 1, outputTokens: 1, webSearchRequests: 0 }, + }) + const error = await rejection(completeJSONLogged(ctx(failing(original)), 'generate', 5, { system: 's', user: 'u' })) + assert.ok(error instanceof CostLogWriteError) + assert.match(error.message, /db down.*the model call had also failed: \[llm:generate\] no text/) + }) + + it('writes no row when the provider never answered (transport or API error)', async () => { + const { rows, ctx } = harness() + const original = new Error('[llm:generate] rate limited by the Claude API') + const error = await rejection(completeJSONLogged(ctx(failing(original)), 'generate', 5, { system: 's', user: 'u' })) + assert.equal(error, original) + assert.equal(rows.length, 0) + }) +}) diff --git a/pipeline/test/llmSettings.test.ts b/pipeline/test/llmSettings.test.ts index 732e32b..31994c6 100644 --- a/pipeline/test/llmSettings.test.ts +++ b/pipeline/test/llmSettings.test.ts @@ -72,7 +72,14 @@ describe('resolveModel precedence', () => { it('resolves the brand-voice extraction model the same way', () => { assert.equal(resolveExtractionModel({ brandVoiceExtractModel: 'gpt-5.6-luna' }, {}).model, 'gpt-5.6-luna') assert.equal(resolveExtractionModel(null, { BRAND_VOICE_EXTRACT_MODEL: 'gpt-5' }).model, 'gpt-5') - assert.equal(resolveExtractionModel(null, {}).model, 'claude-opus-5') + // Unset: the generate model itself, so an OpenAI-only workspace is not asked + // for an Anthropic key, and an Opus workspace keeps Opus for this drafting. + assert.deepEqual(resolveExtractionModel(null, {}), { model: 'claude-opus-5', source: 'default' }) + assert.equal(resolveExtractionModel({ generateModel: 'gpt-5.6-terra' }, {}).model, 'gpt-5.6-terra') + assert.equal(resolveExtractionModel(null, { PIPELINE_MODEL_GENERATE: 'o3' }).model, 'o3') + assert.equal(resolveExtractionModel({ generateModel: 'claude-sonnet-5' }, {}).model, 'claude-sonnet-5') + // A generate id no provider serves is not inherited. + assert.equal(resolveExtractionModel(null, { PIPELINE_MODEL_GENERATE: 'codex/x' }).model, 'claude-opus-5') }) /** @@ -102,6 +109,8 @@ describe('resolveModel precedence', () => { model: 'claude-opus-5', source: 'default', }) + // An OpenAI-only workspace's assistant follows its writer too. + assert.equal(resolveSetupAssistModel({ generateModel: 'gpt-5.6-terra' }, {}).model, 'gpt-5.6-terra') // Its own env var beats the extractor's admin choice: the more specific // answer wins wherever both are given. assert.equal( diff --git a/pipeline/test/llmSettlement.test.ts b/pipeline/test/llmSettlement.test.ts index 95d2131..08c835e 100644 --- a/pipeline/test/llmSettlement.test.ts +++ b/pipeline/test/llmSettlement.test.ts @@ -56,6 +56,17 @@ function harness(internal = false) { let costWrites = 0 const llm: LlmClient = { async completeJSON(stage, request, model) { + // The internal-corpus variant needs one readable SERP page (an unreadable + // SERP stops the build before any internal extraction); answer that + // page's extraction at once so only the internal calls are held. + if (internal && /\nPage #\d+:/.test(request.user)) { + return { + model, + provider: 'mock', + usage: { inputTokens: 1, outputTokens: 1, webSearchRequests: 0 }, + json: mockFixture(stage, request.fixtureKey), + } + } const index = started.length started.push(stage) if (index === 1) throw failure @@ -82,8 +93,15 @@ function harness(internal = false) { async find({ collection }: { collection: string }) { return { docs: internal && collection === 'articles' ? docs : [] } }, - async create({ collection, data }: { collection: string; data: { stage: string } }) { + async create({ + collection, + data, + }: { + collection: string + data: { stage: string; request?: { user?: string } } + }) { assert.equal(collection, 'cost-log', 'failed snapshot must not be persisted') + if (internal && /\nPage #\d+:/.test(data.request?.user ?? '')) return { id: 0 } costWrites++ await writes.promise costs.push(data.stage) @@ -175,13 +193,11 @@ for (const internal of [false, true]) { test(`${internal ? 'internal' : 'SERP'} corpus extraction drains LLM calls and cost writes`, async () => { assert.equal(config.mockMode, true, 'corpus test must never crawl live pages') const serp = { - pages: internal - ? [] - : Array.from({ length: 5 }, (_, index) => ({ - position: index + 1, - url: `https://example.com/page-${index + 1}`, - title: 'Stream games', - })), + pages: Array.from({ length: internal ? 1 : 5 }, (_, index) => ({ + position: index + 1, + url: `https://example.com/page-${index + 1}`, + title: 'Stream games', + })), } as SerpResearch await assertDrains( (ctx) => getOrBuildSnapshot(ctx, article, article.template as Template, serp, []), diff --git a/pipeline/test/llmSignal.test.ts b/pipeline/test/llmSignal.test.ts new file mode 100644 index 0000000..1656735 --- /dev/null +++ b/pipeline/test/llmSignal.test.ts @@ -0,0 +1,33 @@ +import assert from 'node:assert/strict' +import { it } from 'node:test' + +import type { Payload } from 'payload' + +import { type CostContext, completeJSONLogged, type LlmClient } from '../src/llm' + +it('makes no model call, and so buys nothing, once the run signal is aborted', async () => { + let calls = 0 + let costRows = 0 + const llm: LlmClient = { + completeJSON: async () => { + calls += 1 + throw new Error('must not be called') + }, + } + const controller = new AbortController() + controller.abort(new Error('lease lost')) + const ctx = { + payload: { create: async () => (costRows += 1) } as unknown as Payload, + runId: 'aborted', + mode: 'mock', + models: {}, + llm, + signal: controller.signal, + } as unknown as CostContext + await assert.rejects( + completeJSONLogged(ctx, 'generate', 1, { system: 's', user: 'u' }), + /lease lost/, + ) + assert.equal(calls, 0) + assert.equal(costRows, 0) +}) diff --git a/pipeline/test/runMode.test.ts b/pipeline/test/runMode.test.ts new file mode 100644 index 0000000..dc0f756 --- /dev/null +++ b/pipeline/test/runMode.test.ts @@ -0,0 +1,107 @@ +import assert from 'node:assert/strict' +import { spawnSync } from 'node:child_process' +import path from 'node:path' +import { describe, it } from 'node:test' +import { fileURLToPath } from 'node:url' + +import { resolveWorkspaceProfile } from '../../cms/src/lib/tenant' +import { runModeFromEnv, runModeProblem } from '../../cms/src/lib/runMode' +import { evaluateRuntimeReadiness, modeFromEnv } from '../../cms/src/lib/workspaceReadiness' + +const pipelineDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..') + +type Env = Record + +describe('runModeFromEnv', () => { + const table: [Env, 'mock' | 'live'][] = [ + [{ MOCK_MODE: 'true' }, 'mock'], + [{ MOCK_MODE: 'TRUE' }, 'mock'], + [{ MOCK_MODE: '1' }, 'mock'], + [{ MOCK_MODE: 'yes' }, 'mock'], + [{ MOCK_MODE: 'true', ANTHROPIC_API_KEY: 'k' }, 'mock'], + [{ MOCK_MODE: 'false' }, 'live'], + [{ MOCK_MODE: '0' }, 'live'], + [{ MOCK_MODE: 'No' }, 'live'], + // false with no key is live: the per-stage key check refuses the run. + [{ MOCK_MODE: 'false' }, 'live'], + [{}, 'mock'], + [{ MOCK_MODE: '' }, 'mock'], + [{ MOCK_MODE: ' ' }, 'mock'], + [{ ANTHROPIC_API_KEY: 'k' }, 'live'], + [{ OPENAI_API_KEY: 'k' }, 'live'], + [{ MOCK_MODE: '', OPENAI_API_KEY: 'k' }, 'live'], + [{ ANTHROPIC_API_KEY: ' ', OPENAI_API_KEY: '' }, 'mock'], + [{ SOME_OTHER_CREDENTIAL: 'x' }, 'mock'], + // Unparseable: mock, with or without a key. + [{ MOCK_MODE: 'maybe' }, 'mock'], + [{ MOCK_MODE: 'maybe', ANTHROPIC_API_KEY: 'k' }, 'mock'], + [{ MOCK_MODE: 'truee', OPENAI_API_KEY: 'k' }, 'mock'], + ] + for (const [env, expected] of table) { + it(`${JSON.stringify(env)} -> ${expected}`, () => { + assert.equal(runModeFromEnv(env), expected) + assert.equal(modeFromEnv(env), expected) + }) + } + + it('reports only an unrecognised value as a problem', () => { + for (const env of [{}, { MOCK_MODE: '' }, { MOCK_MODE: 'true' }, { MOCK_MODE: 'No' }]) { + assert.equal(runModeProblem(env), undefined) + } + assert.equal( + runModeProblem({ MOCK_MODE: ' tru ' }), + 'MOCK_MODE has an unrecognised value: "tru". Treated as mock mode until it is set to true or false', + ) + }) +}) + +describe('readiness reports an unrecognised MOCK_MODE', () => { + const run = (env: Env) => + evaluateRuntimeReadiness({ + env, + models: {}, + profile: resolveWorkspaceProfile(null, env, { mockDefault: modeFromEnv(env) === 'mock' }), + }) + + it('as a runtime problem, in mock mode, so the operator sees it', () => { + const readiness = run({ MOCK_MODE: 'flase', ANTHROPIC_API_KEY: 'k' }) + assert.equal(readiness.mode, 'mock') + assert.equal(readiness.runtime.ready, false) + assert.ok( + readiness.runtime.problems.some((p) => p.startsWith('MOCK_MODE has an unrecognised value: "flase"')), + ) + }) + + it('and says nothing for a valid value', () => { + assert.deepEqual(run({ MOCK_MODE: 'true' }).runtime.problems, []) + }) +}) + +describe('pipeline config at import', () => { + const importConfig = (env: Env) => { + // A fresh process: `config` is built when the module first loads. + const result = spawnSync( + process.execPath, + [ + '--import', + 'tsx', + '-e', + "import('./src/config.ts').then((m) => console.log('MODE=' + m.config.mockMode))", + ], + { cwd: pipelineDir, env: { NODE_ENV: 'test', PATH: process.env.PATH, ...env }, encoding: 'utf8' }, + ) + return { status: result.status, out: result.stdout, err: result.stderr } + } + + it('does not throw for MOCK_MODE=false with no provider key (live; models.ts refuses the run)', () => { + const { status, out, err } = importConfig({ MOCK_MODE: 'false' }) + assert.equal(status, 0, err) + assert.match(out, /MODE=false/) + }) + + it('does not throw for an unparseable MOCK_MODE and runs mock', () => { + const { status, out, err } = importConfig({ MOCK_MODE: 'sometimes', ANTHROPIC_API_KEY: 'k' }) + assert.equal(status, 0, err) + assert.match(out, /MODE=true/) + }) +}) diff --git a/pipeline/test/runPipeline.test.ts b/pipeline/test/runPipeline.test.ts index 524d3d9..daa7ae5 100644 --- a/pipeline/test/runPipeline.test.ts +++ b/pipeline/test/runPipeline.test.ts @@ -262,3 +262,115 @@ describe('the brief checkpoint', () => { assert.deepEqual(summary.finalStatuses, {}) }) }) + +describe('runPipeline with a lost lease', () => { + it('stops before the next write once its signal aborts, and rethrows the reason', async () => { + const { ctx, updates } = fakeCtx([ + articleAt(1, 'topic_selected'), + articleAt(2, 'topic_selected'), + ]) + const controller = new AbortController() + const lost = new Error('lease lost') + let ran = 0 + const stage: Stage = { + name: 'research', + entryStatus: 'topic_selected', + exitStatus: 'brief_review', + run: async () => { + ran += 1 + // The heartbeat finds the run recovered while this article's paid work + // is in flight. + controller.abort(lost) + return { data: {}, status: 'brief_review' } + }, + } + await quietly(async () => { + await assert.rejects( + runPipeline(ctx, { + stages: [stage, stubStage('generate', 'researched', 'drafted')], + signal: controller.signal, + }), + (error) => error === lost, + ) + }) + assert.equal(ran, 1, 'the second article must not be started') + assert.deepEqual(updates, [], 'nothing may be written after the lease is lost') + }) + + it('does not start at all with an already-aborted signal', async () => { + const { ctx, updates } = fakeCtx([articleAt(1, 'topic_selected')]) + const controller = new AbortController() + controller.abort(new Error('lease lost')) + await quietly(async () => { + await assert.rejects( + runPipeline(ctx, { + stages: [stubStage('research', 'topic_selected', 'brief_review')], + signal: controller.signal, + }), + /lease lost/, + ) + }) + assert.deepEqual(updates, []) + }) +}) + +describe('runPipeline with a fenced commit', () => { + it('writes through commitArticle with the request it is given', async () => { + const { ctx } = fakeCtx([articleAt(1, 'topic_selected')]) + const reqs: unknown[] = [] + ctx.payload.update = (async ({ req }: { req?: unknown }) => { + reqs.push(req) + return { id: 1 } + }) as unknown as StageContext['payload']['update'] + const lockedReq = { transactionID: 'tx' } + await quietly(() => + runPipeline(ctx, { + stages: [stubStage('research', 'topic_selected', 'brief_review')], + commitArticle: async (write) => { + await write(lockedReq as never) + return true + }, + }), + ) + assert.deepEqual(reqs, [lockedReq], 'the write must run inside the fence transaction') + }) + + it('writes nothing and stops the whole run once the run no longer owns its row', async () => { + const { ctx, updates } = fakeCtx([ + articleAt(1, 'topic_selected'), + articleAt(2, 'topic_selected'), + ]) + let ran = 0 + const stage: Stage = { + ...stubStage('research', 'topic_selected', 'brief_review'), + run: async () => { + ran += 1 + return { data: {}, status: 'brief_review' } + }, + } + await quietly(async () => { + await assert.rejects( + // No signal: the heartbeat has not noticed yet, only the fence has. + runPipeline(ctx, { stages: [stage], commitArticle: async () => false }), + /no longer owns its row/, + ) + }) + assert.equal(ran, 1, 'a refused write ends the run, not just that article') + assert.deepEqual(updates, []) + }) + + it('hands the run signal to every stage', async () => { + const { ctx } = fakeCtx([articleAt(1, 'topic_selected')]) + const controller = new AbortController() + let seen: AbortSignal | undefined + const stage: Stage = { + ...stubStage('research', 'topic_selected', 'brief_review'), + run: async (_article, stageCtx) => { + seen = stageCtx.signal + return { data: {}, status: 'brief_review' } + }, + } + await quietly(() => runPipeline(ctx, { stages: [stage], signal: controller.signal })) + assert.equal(seen, controller.signal) + }) +}) diff --git a/pipeline/test/scopedPipeline.test.ts b/pipeline/test/scopedPipeline.test.ts index 1b43b02..fd55902 100644 --- a/pipeline/test/scopedPipeline.test.ts +++ b/pipeline/test/scopedPipeline.test.ts @@ -60,20 +60,9 @@ it('advances only the article ids assigned to a scoped run', async () => { where?: Record }) => { if (collection === 'cost-log') { - // Two shapes reach this collection: qa's `{ article: { equals } }` and - // the informationGain stage's `{ and: [...] }`, which additionally - // scopes by run id and stage. - const and = - (where?.and as Array>) ?? [] - const articleId = - (where?.article as { equals?: number } | undefined)?.equals ?? - (and.find((clause) => clause.article)?.article.equals as number | undefined) - const stages = and.find((clause) => clause.stage)?.stage.in as string[] | undefined - return { - docs: costRows.filter( - (row) => row.article === articleId && (!stages || stages.includes(row.stage as string)), - ), - } + // Every stage that reads cost rows sums one article's: `{ article: { equals } }`. + const articleId = (where?.article as { equals?: number } | undefined)?.equals + return { docs: costRows.filter((row) => row.article === articleId) } } // The research stage looks for a reusable corpus snapshot and for its own // published articles; this scoped run has neither, so both come back empty @@ -148,10 +137,6 @@ it('advances only the article ids assigned to a scoped run', async () => { ahrefs, runId: 'scope-1', mode: 'mock', - // This test is about *which* articles a scoped run touches, not the brief - // checkpoint, so the stop after research is switched off to let the run - // walk all four stages in one pass. - pauseForBrief: false, styleGuide: loadStyleGuide(), models: { generate: 'claude-opus-5', @@ -176,6 +161,15 @@ it('advances only the article ids assigned to a scoped run', async () => { tenant: emptyTenantContext(), } + // Research stops at the brief checkpoint; nothing else moves in that run. + const researched = await runPipeline(ctx, { articleIds: [1] }) + assert.equal(researched.failed, 0, 'research should not have failed any article') + assert.equal(articles.get(1)?.status, 'brief_review') + assert.deepEqual(researched.finalStatuses, { brief_review: 1 }) + + // Approving the brief is what moves a piece to `researched`; the next run + // writes, checks and scores it. + articles.set(1, { ...articles.get(1)!, status: 'researched' }) const result = await runPipeline(ctx, { articleIds: [1] }) assert.equal(result.failed, 0, 'the scoped run should not have failed any article') diff --git a/pipeline/test/snapshotUnreadableSerp.test.ts b/pipeline/test/snapshotUnreadableSerp.test.ts new file mode 100644 index 0000000..c45c42c --- /dev/null +++ b/pipeline/test/snapshotUnreadableSerp.test.ts @@ -0,0 +1,87 @@ +import assert from 'node:assert/strict' +import test from 'node:test' +import type { Payload } from 'payload' + +import type { Article, Template } from '../../cms/src/payload-types' +import type { SerpResearch } from '../src/ahrefs' +// Initialise the stage registry before its circular QA dependency. +import type { StageContext } from '../src/stages' +import { getOrBuildSnapshot } from '../src/corpus/snapshot' +import type { LlmClient } from '../src/llm' +import { loadStyleGuide } from '../src/styleGuide' +import { emptyTenantContext } from '../src/tenant' + +const article = { + id: 1, + keyword: 'stream games', + title: 'Stream games', + status: 'topic_selected', + template: { id: 1, name: 'How-To' } as Template, +} as Article + +test('an unreadable SERP writes the empty row and throws before any extraction or clustering', async () => { + const llmCalls: string[] = [] + const created: { collection: string; data: Record }[] = [] + const finds: string[] = [] + const llm: LlmClient = { + async completeJSON(stage) { + llmCalls.push(stage) + throw new Error('no model call expected') + }, + } + const publishedDocs = Array.from({ length: 5 }, (_, index) => ({ + id: index + 10, + keyword: article.keyword, + title: article.title, + updatedAt: '2026-10-06T00:00:00.000Z', + })) + const payload = { + async find({ collection }: { collection: string }) { + finds.push(collection) + // Published articles on the topic are available: before the fix they were + // sent to paid claim extraction even though the SERP gave no baseline. + return { docs: collection === 'articles' ? publishedDocs : [] } + }, + async create(args: { collection: string; data: Record }) { + created.push(args) + return { id: 77 } + }, + } as unknown as Payload + const ctx = { + payload, + llm, + // Live, so pages are really "fetched" — loopback addresses are refused by + // the address guard before any DNS lookup or request. + mode: 'live', + runId: 'unreadable-serp', + tenant: emptyTenantContext(), + styleGuide: loadStyleGuide(), + brandVoice: null, + models: { claimExtraction: 'claude-opus-5' }, + evidenceSources: [], + } as unknown as StageContext + const serp = { + pages: [1, 2, 3].map((position) => ({ + position, + url: `http://127.0.0.1/page-${position}`, + title: 'Stream games', + })), + } as SerpResearch + + await assert.rejects( + getOrBuildSnapshot(ctx, article, article.template as Template, serp, []), + /corpus snapshot 77 for "stream games" is empty: no page could be read.*0\/3 ranking page\(s\) read/, + ) + + assert.deepEqual(llmCalls, [], 'no extraction or clustering call') + assert.ok(!finds.includes('articles'), 'internal corpus was not even loaded') + const snapshots = created.filter((entry) => entry.collection === 'corpus-snapshots') + assert.equal(snapshots.length, 1) + const row = snapshots[0].data + assert.equal(row.status, 'empty') + assert.equal(row.failedPageCount, 3) + assert.deepEqual(row.baselineClaims, []) + assert.deepEqual(row.internalCorpus, []) + assert.equal((row.pages as unknown[]).length, 3) + assert.equal(created.filter((entry) => entry.collection === 'cost-log').length, 0) +})