{
  "before": {
    "ledger": [
      [
        1,
        "OrchestrationEvents"
      ],
      [
        2,
        "OrchestrationCommandReceipts"
      ],
      [
        3,
        "CheckpointDiffBlobs"
      ],
      [
        4,
        "ProviderSessionRuntime"
      ],
      [
        5,
        "Projections"
      ],
      [
        6,
        "ProjectionThreadSessionRuntimeModeColumns"
      ],
      [
        7,
        "ProjectionThreadMessageAttachments"
      ],
      [
        8,
        "ProjectionThreadActivitySequence"
      ],
      [
        9,
        "ProviderSessionRuntimeMode"
      ],
      [
        10,
        "ProjectionThreadsRuntimeMode"
      ],
      [
        11,
        "OrchestrationThreadCreatedRuntimeMode"
      ],
      [
        12,
        "ProjectionThreadsInteractionMode"
      ],
      [
        13,
        "ProjectionThreadProposedPlans"
      ],
      [
        14,
        "ProjectionThreadProposedPlanImplementation"
      ],
      [
        15,
        "ProjectionTurnsSourceProposedPlan"
      ],
      [
        16,
        "CanonicalizeModelSelections"
      ],
      [
        17,
        "ProjectionThreadsArchivedAt"
      ],
      [
        18,
        "ProjectionThreadsArchivedAtIndex"
      ],
      [
        19,
        "ProjectionSnapshotLookupIndexes"
      ],
      [
        20,
        "AuthAccessManagement"
      ],
      [
        21,
        "AuthSessionClientMetadata"
      ],
      [
        22,
        "AuthSessionLastConnectedAt"
      ],
      [
        23,
        "ProjectionThreadShellSummary"
      ],
      [
        24,
        "BackfillProjectionThreadShellSummary"
      ],
      [
        25,
        "CleanupInvalidProjectionPendingApprovals"
      ],
      [
        26,
        "CanonicalizeModelSelectionOptions"
      ],
      [
        27,
        "ProviderSessionRuntimeInstanceId"
      ],
      [
        28,
        "ProjectionThreadSessionInstanceId"
      ],
      [
        29,
        "ProjectionThreadDetailOrderingIndexes"
      ],
      [
        30,
        "ProjectionThreadShellArchiveIndexes"
      ],
      [
        31,
        "AuthAuthorizationScopes"
      ],
      [
        32,
        "AuthPairingProofKeyThumbprint"
      ],
      [
        33,
        "ProjectionThreadsSettled"
      ],
      [
        34,
        "ProjectionThreadsSnoozed"
      ],
      [
        35,
        "ProjectionThreadTitleRegeneration"
      ],
      [
        36,
        "ProjectionThreadsPinned"
      ],
      [
        37,
        "ProjectionTurnsKeysetIndex"
      ],
      [
        38,
        "ProjectionThreadsPinOrderKey"
      ],
      [
        39,
        "ProjectionProjectsDefaultThreadEnvMode"
      ],
      [
        40,
        "ProjectionProjectFaviconPath"
      ],
      [
        41,
        "AuthSessionClientConnection"
      ],
      [
        42,
        "ProjectionThreadLinkedPullRequest"
      ],
      [
        43,
        "ProjectionThreadsUnsettledAt"
      ],
      [
        44,
        "ClearAutomaticProjectModelDefaults"
      ],
      [
        45,
        "ProjectionProjectsAutoPull"
      ],
      [
        46,
        "RepairAutomaticSettlementTimestamps"
      ],
      [
        47,
        "ProjectionProjectIcon"
      ],
      [
        48,
        "ProjectionThreadBranchPullRequest"
      ],
      [
        49,
        "ProjectionThreadsActiveOrderKey"
      ],
      [
        50,
        "ProjectionThreadPullRequests"
      ],
      [
        51,
        "ProjectionThreadMessageContext"
      ],
      [
        52,
        "ProjectionThreadTitleState"
      ],
      [
        53,
        "PullRequestFilesViewed"
      ],
      [
        54,
        "ProjectionThreadsAutoSettleDisabledAt"
      ],
      [
        55,
        "OrchestrationV2"
      ],
      [
        56,
        "RemoveRedundantProjectionIndexes"
      ],
      [
        57,
        "ScheduledTaskWebhooks"
      ],
      [
        58,
        "WebhookRelayDeliveries"
      ],
      [
        59,
        "McpAppModelContext"
      ],
      [
        60,
        "ThreadSnapshotWindowIndexes"
      ],
      [
        61,
        "PullRequestReviewGuides"
      ],
      [
        62,
        "ThreadFailureLookupIndex"
      ],
      [
        63,
        "DropUnusedV1Projections"
      ],
      [
        64,
        "CanonicalizeThreadPullRequestLinks"
      ],
      [
        65,
        "CodexUsageNativeTurnIndex"
      ],
      [
        66,
        "RepairClientSettlementTimestamps"
      ],
      [
        67,
        "WebhookDedupe"
      ],
      [
        68,
        "ShellStopRequestIndex"
      ],
      [
        69,
        "ThreadMessageSearch"
      ],
      [
        70,
        "PeerLinks"
      ],
      [
        71,
        "PeerLinkFence"
      ],
      [
        72,
        "WaitingLinkRequestIndex"
      ],
      [
        73,
        "ActiveTurnItemIndexes"
      ],
      [
        74,
        "ExcludeAttachmentPlaceholdersFromSearch"
      ],
      [
        75,
        "SubagentDeliveryState"
      ],
      [
        76,
        "ProjectionProjectsPinArchive"
      ],
      [
        77,
        "RepairBooleanSettledOverride"
      ],
      [
        78,
        "DropOrchestrationEventCorrelationIndex"
      ],
      [
        79,
        "DelegatedRecoveryIndexes"
      ],
      [
        80,
        "ScheduledTaskThreadMode"
      ]
    ],
    "schema": [
      [
        "index",
        "idx_auth_pairing_links_active",
        "CREATE INDEX idx_auth_pairing_links_active\n    ON auth_pairing_links(revoked_at, consumed_at, expires_at)\n  "
      ],
      [
        "index",
        "idx_auth_sessions_active",
        "CREATE INDEX idx_auth_sessions_active\n    ON auth_sessions(revoked_at, expires_at, issued_at)\n  "
      ],
      [
        "index",
        "idx_orch_command_receipts_aggregate",
        "CREATE INDEX idx_orch_command_receipts_aggregate\n    ON orchestration_command_receipts(aggregate_kind, aggregate_id)\n  "
      ],
      [
        "index",
        "idx_orch_command_receipts_sequence",
        "CREATE INDEX idx_orch_command_receipts_sequence\n    ON orchestration_command_receipts(result_sequence)\n  "
      ],
      [
        "index",
        "idx_orch_events_command_id",
        "CREATE INDEX idx_orch_events_command_id\n    ON orchestration_events(command_id)\n  "
      ],
      [
        "index",
        "idx_orch_events_stream_sequence",
        "CREATE INDEX idx_orch_events_stream_sequence\n    ON orchestration_events(aggregate_kind, stream_id, sequence)\n  "
      ],
      [
        "index",
        "idx_orch_events_stream_version",
        "CREATE UNIQUE INDEX idx_orch_events_stream_version\n    ON orchestration_events(aggregate_kind, stream_id, stream_version)\n  "
      ],
      [
        "index",
        "idx_orchestration_events_agent_stream_sequence",
        "CREATE INDEX idx_orchestration_events_agent_stream_sequence\n    ON orchestration_events(stream_id, sequence)\n    WHERE application_event_version = 2 AND aggregate_kind = 'thread'\n  "
      ],
      [
        "index",
        "idx_orchestration_events_application_high_water",
        "CREATE INDEX idx_orchestration_events_application_high_water\n    ON orchestration_events(sequence)\n    WHERE aggregate_kind = 'project'\n      OR (application_event_version = 2 AND aggregate_kind = 'thread')\n  "
      ],
      [
        "index",
        "idx_orchestration_events_application_sequence",
        "CREATE INDEX idx_orchestration_events_application_sequence\n    ON orchestration_events(application_event_version, sequence)\n  "
      ],
      [
        "index",
        "idx_projection_projects_updated_at",
        "CREATE INDEX idx_projection_projects_updated_at\n    ON projection_projects(updated_at)\n  "
      ],
      [
        "index",
        "idx_projection_projects_workspace_root_deleted_at",
        "CREATE INDEX idx_projection_projects_workspace_root_deleted_at\n    ON projection_projects(workspace_root, deleted_at)\n  "
      ],
      [
        "index",
        "idx_projection_thread_messages_thread_created_id",
        "CREATE INDEX idx_projection_thread_messages_thread_created_id\n    ON projection_thread_messages(thread_id, created_at, message_id)\n  "
      ],
      [
        "index",
        "idx_projection_thread_pull_requests_pr",
        "CREATE INDEX idx_projection_thread_pull_requests_pr\n    ON projection_thread_pull_requests(host, repository, number)\n  "
      ],
      [
        "index",
        "idx_projection_thread_sessions_instance",
        "CREATE INDEX idx_projection_thread_sessions_instance\n    ON projection_thread_sessions(provider_instance_id)\n  "
      ],
      [
        "index",
        "idx_projection_thread_sessions_provider_session",
        "CREATE INDEX idx_projection_thread_sessions_provider_session\n    ON projection_thread_sessions(provider_session_id)\n  "
      ],
      [
        "index",
        "idx_projection_threads_project_archived_at",
        "CREATE INDEX idx_projection_threads_project_archived_at\n    ON projection_threads(project_id, archived_at)\n  "
      ],
      [
        "index",
        "idx_projection_threads_project_deleted_created",
        "CREATE INDEX idx_projection_threads_project_deleted_created\n    ON projection_threads(project_id, deleted_at, created_at)\n  "
      ],
      [
        "index",
        "idx_projection_threads_shell_active",
        "CREATE INDEX idx_projection_threads_shell_active\n    ON projection_threads(deleted_at, archived_at, project_id, created_at, thread_id)\n  "
      ],
      [
        "index",
        "idx_projection_threads_shell_archived",
        "CREATE INDEX idx_projection_threads_shell_archived\n    ON projection_threads(deleted_at, archived_at, project_id, thread_id)\n  "
      ],
      [
        "index",
        "idx_provider_session_runtime_instance",
        "CREATE INDEX idx_provider_session_runtime_instance\n    ON provider_session_runtime(provider_instance_id)\n  "
      ],
      [
        "index",
        "idx_provider_session_runtime_provider",
        "CREATE INDEX idx_provider_session_runtime_provider\n    ON provider_session_runtime(provider_name)\n  "
      ],
      [
        "index",
        "idx_provider_session_runtime_status",
        "CREATE INDEX idx_provider_session_runtime_status\n    ON provider_session_runtime(status)\n  "
      ],
      [
        "index",
        "idx_scheduled_task_webhook_deliveries_task",
        "CREATE INDEX idx_scheduled_task_webhook_deliveries_task\n    ON scheduled_task_webhook_deliveries(task_id, received_at)\n  "
      ],
      [
        "index",
        "idx_scheduled_task_webhook_relay_deliveries_seen",
        "CREATE INDEX idx_scheduled_task_webhook_relay_deliveries_seen\n    ON scheduled_task_webhook_relay_deliveries(seen_at)\n  "
      ],
      [
        "index",
        "idx_scheduled_tasks_due",
        "CREATE INDEX idx_scheduled_tasks_due\n    ON scheduled_tasks(enabled, next_run_at)\n    WHERE enabled = 1 AND next_run_at IS NOT NULL\n  "
      ],
      [
        "index",
        "idx_scheduled_tasks_project",
        "CREATE INDEX idx_scheduled_tasks_project\n    ON scheduled_tasks(project_id, updated_at)\n  "
      ],
      [
        "index",
        "idx_webhook_pending_due",
        "CREATE INDEX idx_webhook_pending_due ON scheduled_task_webhook_pending(state, due_at)"
      ],
      [
        "index",
        "idx_webhook_pending_key",
        "CREATE UNIQUE INDEX idx_webhook_pending_key\n    ON scheduled_task_webhook_pending(task_id, coalesce_key) WHERE state = 'pending'"
      ],
      [
        "index",
        "idx_webhook_replay_delivery",
        "CREATE INDEX idx_webhook_replay_delivery ON scheduled_task_webhook_replay_keys(delivery_id)"
      ],
      [
        "index",
        "idx_webhook_replay_expiry",
        "CREATE INDEX idx_webhook_replay_expiry ON scheduled_task_webhook_replay_keys(expires_at)"
      ],
      [
        "index",
        "orchestration_events_v2_created_threads_idx",
        "CREATE INDEX orchestration_events_v2_created_threads_idx\n    ON orchestration_events(stream_id)\n    WHERE application_event_version = 2\n      AND aggregate_kind = 'thread'\n      AND event_type = 'thread.created'\n  "
      ],
      [
        "index",
        "orchestration_v2_command_receipts_thread_sequence_idx",
        "CREATE INDEX orchestration_v2_command_receipts_thread_sequence_idx ON orchestration_v2_command_receipts(thread_id, result_sequence)"
      ],
      [
        "index",
        "orchestration_v2_effect_outbox_claim_idx",
        "CREATE INDEX orchestration_v2_effect_outbox_claim_idx\n    ON orchestration_v2_effect_outbox(status, available_at, lease_expires_at, created_at)\n  "
      ],
      [
        "index",
        "orchestration_v2_effect_outbox_command_idx",
        "CREATE INDEX orchestration_v2_effect_outbox_command_idx\n    ON orchestration_v2_effect_outbox(command_id, effect_id)\n  "
      ],
      [
        "index",
        "orchestration_v2_effect_outbox_thread_status_idx",
        "CREATE INDEX orchestration_v2_effect_outbox_thread_status_idx\n    ON orchestration_v2_effect_outbox(thread_id, status, effect_type)\n  "
      ],
      [
        "index",
        "orchestration_v2_events_command_idx",
        "CREATE INDEX orchestration_v2_events_command_idx ON orchestration_v2_events(command_id, sequence)"
      ],
      [
        "index",
        "orchestration_v2_events_instance_sequence_idx",
        "CREATE INDEX orchestration_v2_events_instance_sequence_idx ON orchestration_v2_events(provider_instance_id, sequence)"
      ],
      [
        "index",
        "orchestration_v2_events_node_sequence_idx",
        "CREATE INDEX orchestration_v2_events_node_sequence_idx ON orchestration_v2_events(node_id, sequence)"
      ],
      [
        "index",
        "orchestration_v2_events_raw_event_idx",
        "CREATE INDEX orchestration_v2_events_raw_event_idx ON orchestration_v2_events(raw_event_id)"
      ],
      [
        "index",
        "orchestration_v2_events_run_sequence_idx",
        "CREATE INDEX orchestration_v2_events_run_sequence_idx ON orchestration_v2_events(run_id, sequence)"
      ],
      [
        "index",
        "orchestration_v2_events_thread_sequence_idx",
        "CREATE INDEX orchestration_v2_events_thread_sequence_idx ON orchestration_v2_events(thread_id, sequence)"
      ],
      [
        "index",
        "orchestration_v2_events_thread_type_sequence_idx",
        "CREATE INDEX orchestration_v2_events_thread_type_sequence_idx ON orchestration_v2_events(thread_id, event_type, sequence)"
      ],
      [
        "index",
        "orchestration_v2_legacy_imports_pending_transcript_idx",
        "CREATE INDEX orchestration_v2_legacy_imports_pending_transcript_idx\n    ON orchestration_v2_legacy_imports(transcript_imported_at, shell_imported_at, thread_id)\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_checkpoint_scopes_parent_idx",
        "CREATE INDEX orchestration_v2_projection_checkpoint_scopes_parent_idx ON orchestration_v2_projection_checkpoint_scopes(parent_scope_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_checkpoint_scopes_thread_idx",
        "CREATE INDEX orchestration_v2_projection_checkpoint_scopes_thread_idx ON orchestration_v2_projection_checkpoint_scopes(thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_checkpoints_parent_idx",
        "CREATE INDEX orchestration_v2_projection_checkpoints_parent_idx ON orchestration_v2_projection_checkpoints(parent_checkpoint_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_checkpoints_scope_ordinal_idx",
        "CREATE UNIQUE INDEX orchestration_v2_projection_checkpoints_scope_ordinal_idx ON orchestration_v2_projection_checkpoints(scope_id, ordinal_within_scope)"
      ],
      [
        "index",
        "orchestration_v2_projection_checkpoints_thread_idx",
        "CREATE INDEX orchestration_v2_projection_checkpoints_thread_idx ON orchestration_v2_projection_checkpoints(thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_context_handoffs_target_run_idx",
        "CREATE INDEX orchestration_v2_projection_context_handoffs_target_run_idx ON orchestration_v2_projection_context_handoffs(target_run_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_context_handoffs_thread_idx",
        "CREATE INDEX orchestration_v2_projection_context_handoffs_thread_idx ON orchestration_v2_projection_context_handoffs(thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_context_transfers_source_thread_idx",
        "CREATE INDEX orchestration_v2_projection_context_transfers_source_thread_idx ON orchestration_v2_projection_context_transfers(source_thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_context_transfers_target_run_idx",
        "CREATE INDEX orchestration_v2_projection_context_transfers_target_run_idx ON orchestration_v2_projection_context_transfers(target_run_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_context_transfers_target_thread_idx",
        "CREATE INDEX orchestration_v2_projection_context_transfers_target_thread_idx ON orchestration_v2_projection_context_transfers(target_thread_id, status)"
      ],
      [
        "index",
        "orchestration_v2_projection_messages_latest_user_idx",
        "CREATE INDEX orchestration_v2_projection_messages_latest_user_idx\n    ON orchestration_v2_projection_messages(thread_id, updated_at DESC, message_id DESC)\n    WHERE role = 'user'\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_messages_node_idx",
        "CREATE INDEX orchestration_v2_projection_messages_node_idx ON orchestration_v2_projection_messages(node_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_messages_run_idx",
        "CREATE INDEX orchestration_v2_projection_messages_run_idx ON orchestration_v2_projection_messages(run_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_messages_thread_created_idx",
        "CREATE INDEX orchestration_v2_projection_messages_thread_created_idx ON orchestration_v2_projection_messages(thread_id, created_at, message_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_nodes_live_idx",
        "CREATE INDEX orchestration_v2_projection_nodes_live_idx\n    ON orchestration_v2_projection_nodes(thread_id)\n    WHERE status IN ('pending', 'starting', 'running', 'waiting')\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_nodes_parent_idx",
        "CREATE INDEX orchestration_v2_projection_nodes_parent_idx ON orchestration_v2_projection_nodes(parent_node_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_nodes_provider_turn_idx",
        "CREATE INDEX orchestration_v2_projection_nodes_provider_turn_idx ON orchestration_v2_projection_nodes(provider_turn_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_nodes_thread_run_idx",
        "CREATE INDEX orchestration_v2_projection_nodes_thread_run_idx ON orchestration_v2_projection_nodes(thread_id, run_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_plans_run_idx",
        "CREATE INDEX orchestration_v2_projection_plans_run_idx ON orchestration_v2_projection_plans(run_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_plans_thread_idx",
        "CREATE INDEX orchestration_v2_projection_plans_thread_idx ON orchestration_v2_projection_plans(thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_session_bindings_thread_idx",
        "CREATE INDEX orchestration_v2_projection_provider_session_bindings_thread_idx\n    ON orchestration_v2_projection_provider_session_bindings(thread_id)\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_provider_sessions_instance_status_idx",
        "CREATE INDEX orchestration_v2_projection_provider_sessions_instance_status_idx ON orchestration_v2_projection_provider_sessions(provider_instance_id, status)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_sessions_provider_status_idx",
        "CREATE INDEX orchestration_v2_projection_provider_sessions_provider_status_idx ON orchestration_v2_projection_provider_sessions(provider, status)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_sessions_thread_idx",
        "CREATE INDEX orchestration_v2_projection_provider_sessions_thread_idx ON orchestration_v2_projection_provider_sessions(thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_threads_instance_status_idx",
        "CREATE INDEX orchestration_v2_projection_provider_threads_instance_status_idx ON orchestration_v2_projection_provider_threads(provider_instance_id, status)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_threads_owner_idx",
        "CREATE INDEX orchestration_v2_projection_provider_threads_owner_idx ON orchestration_v2_projection_provider_threads(owner_node_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_threads_session_idx",
        "CREATE INDEX orchestration_v2_projection_provider_threads_session_idx ON orchestration_v2_projection_provider_threads(provider_session_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_threads_thread_idx",
        "CREATE INDEX orchestration_v2_projection_provider_threads_thread_idx ON orchestration_v2_projection_provider_threads(thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_turns_thread_idx",
        "CREATE INDEX orchestration_v2_projection_provider_turns_thread_idx ON orchestration_v2_projection_provider_turns(thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_turns_thread_ordinal_idx",
        "CREATE UNIQUE INDEX orchestration_v2_projection_provider_turns_thread_ordinal_idx ON orchestration_v2_projection_provider_turns(provider_thread_id, ordinal)"
      ],
      [
        "index",
        "orchestration_v2_projection_requests_recovery_idx",
        "CREATE INDEX orchestration_v2_projection_requests_recovery_idx\n    ON orchestration_v2_projection_runtime_requests(thread_id)\n    WHERE status = 'pending'\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_run_attempts_run_ordinal_idx",
        "CREATE UNIQUE INDEX orchestration_v2_projection_run_attempts_run_ordinal_idx ON orchestration_v2_projection_run_attempts(run_id, attempt_ordinal)"
      ],
      [
        "index",
        "orchestration_v2_projection_run_attempts_thread_idx",
        "CREATE INDEX orchestration_v2_projection_run_attempts_thread_idx ON orchestration_v2_projection_run_attempts(thread_id, run_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_runs_delegated_delivery_idx",
        "CREATE INDEX orchestration_v2_projection_runs_delegated_delivery_idx\n    ON orchestration_v2_projection_runs(thread_id)\n    WHERE CASE WHEN json_valid(payload_json)\n      THEN json_type(payload_json, '$.delegatedCompletion.delivery') = 'object'\n      ELSE 0 END\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_runs_provider_thread_idx",
        "CREATE INDEX orchestration_v2_projection_runs_provider_thread_idx ON orchestration_v2_projection_runs(provider_thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_runs_recovery_idx",
        "CREATE INDEX orchestration_v2_projection_runs_recovery_idx\n    ON orchestration_v2_projection_runs(status, thread_id)\n    WHERE status IN ('queued', 'preparing', 'starting', 'running', 'waiting')\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_runs_thread_ordinal_idx",
        "CREATE UNIQUE INDEX orchestration_v2_projection_runs_thread_ordinal_idx ON orchestration_v2_projection_runs(thread_id, ordinal)"
      ],
      [
        "index",
        "orchestration_v2_projection_runs_thread_status_idx",
        "CREATE INDEX orchestration_v2_projection_runs_thread_status_idx ON orchestration_v2_projection_runs(thread_id, status)"
      ],
      [
        "index",
        "orchestration_v2_projection_runtime_requests_provider_turn_idx",
        "CREATE INDEX orchestration_v2_projection_runtime_requests_provider_turn_idx ON orchestration_v2_projection_runtime_requests(provider_turn_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_runtime_requests_thread_status_idx",
        "CREATE INDEX orchestration_v2_projection_runtime_requests_thread_status_idx ON orchestration_v2_projection_runtime_requests(thread_id, status)"
      ],
      [
        "index",
        "orchestration_v2_projection_subagents_child_thread_idx",
        "CREATE INDEX orchestration_v2_projection_subagents_child_thread_idx ON orchestration_v2_projection_subagents(child_thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_subagents_parent_node_idx",
        "CREATE INDEX orchestration_v2_projection_subagents_parent_node_idx ON orchestration_v2_projection_subagents(parent_node_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_subagents_provider_thread_idx",
        "CREATE INDEX orchestration_v2_projection_subagents_provider_thread_idx ON orchestration_v2_projection_subagents(provider_thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_subagents_settled_idx",
        "CREATE INDEX orchestration_v2_projection_subagents_settled_idx\n    ON orchestration_v2_projection_subagents(thread_id, status, completion_delivery_state, run_id)\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_subagents_thread_idx",
        "CREATE INDEX orchestration_v2_projection_subagents_thread_idx ON orchestration_v2_projection_subagents(thread_id, started_at, subagent_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_threads_project_updated_idx",
        "CREATE INDEX orchestration_v2_projection_threads_project_updated_idx ON orchestration_v2_projection_threads(project_id, updated_at)"
      ],
      [
        "index",
        "orchestration_v2_projection_threads_subagent_result_idx",
        "CREATE INDEX orchestration_v2_projection_threads_subagent_result_idx\n    ON orchestration_v2_projection_threads(\n      thread_id, json_extract(payload_json, '$.lineage.parentThreadId')\n    )\n    WHERE CASE WHEN json_valid(payload_json) THEN\n      json_extract(payload_json, '$.lineage.relationshipToParent') = 'subagent'\n      AND json_extract(payload_json, '$.lineage.parentThreadId') IS NOT NULL\n      AND json_extract(payload_json, '$.forkedFrom.type') = 'node'\n      ELSE 0 END\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_active_ordinal_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_active_ordinal_idx\n    ON orchestration_v2_projection_turn_items(thread_id, ordinal, turn_item_id)\n    WHERE status IN ('pending', 'running', 'waiting')\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_active_run_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_active_run_idx\n    ON orchestration_v2_projection_turn_items(thread_id, run_id)\n    WHERE status IN ('pending', 'running', 'waiting')\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_failed_error_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_failed_error_idx\n    ON orchestration_v2_projection_turn_items(\n      thread_id, run_id, node_id, updated_at DESC, ordinal DESC, turn_item_id DESC\n    )\n    WHERE type = 'error' AND status = 'failed'\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_node_ordinal_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_node_ordinal_idx ON orchestration_v2_projection_turn_items(node_id, ordinal)"
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_provider_turn_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_provider_turn_idx ON orchestration_v2_projection_turn_items(provider_turn_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_recovery_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_recovery_idx\n    ON orchestration_v2_projection_turn_items(thread_id)\n    WHERE type IN ('command_execution', 'dynamic_tool', 'subagent')\n      AND status IN ('pending', 'running', 'waiting')\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_run_ordinal_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_run_ordinal_idx ON orchestration_v2_projection_turn_items(run_id, ordinal)"
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_shell_pending_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_shell_pending_idx\n    ON orchestration_v2_projection_turn_items(thread_id, run_id)\n    WHERE type IN ('command_execution', 'dynamic_tool', 'subagent')\n      AND status NOT IN ('completed', 'interrupted', 'failed', 'cancelled')\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_stop_request_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_stop_request_idx\n    ON orchestration_v2_projection_turn_items(thread_id, run_id)\n    WHERE type = 'run_interrupt_request'\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_thread_ordinal_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_thread_ordinal_idx ON orchestration_v2_projection_turn_items(thread_id, ordinal, turn_item_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_thread_run_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_thread_run_idx\n    ON orchestration_v2_projection_turn_items(thread_id, run_id)\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_user_message_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_user_message_idx\n    ON orchestration_v2_projection_turn_items(thread_id, ordinal, turn_item_id)\n    WHERE type = 'user_message'\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_waiting_link_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_waiting_link_idx\n    ON orchestration_v2_projection_turn_items(thread_id, updated_at DESC, turn_item_id DESC)\n    WHERE type = 'link_request' AND status = 'waiting'\n  "
      ],
      [
        "index",
        "orchestration_v2_provider_turns_codex_native_id_idx",
        "CREATE INDEX orchestration_v2_provider_turns_codex_native_id_idx\n    ON orchestration_v2_projection_provider_turns (\n      json_extract(payload_json, '$.nativeTurnRef.nativeId')\n    )\n    WHERE json_extract(payload_json, '$.nativeTurnRef.driver') = 'codex'\n  "
      ],
      [
        "table",
        "auth_pairing_links",
        "CREATE TABLE auth_pairing_links (\n      id TEXT PRIMARY KEY,\n      credential TEXT NOT NULL UNIQUE,\n      method TEXT NOT NULL,\n      scopes TEXT NOT NULL,\n      subject TEXT NOT NULL,\n      label TEXT,\n      created_at TEXT NOT NULL,\n      expires_at TEXT NOT NULL,\n      consumed_at TEXT,\n      revoked_at TEXT\n    , proof_key_thumbprint TEXT)"
      ],
      [
        "table",
        "auth_sessions",
        "CREATE TABLE auth_sessions (\n      session_id TEXT PRIMARY KEY,\n      subject TEXT NOT NULL,\n      scopes TEXT NOT NULL,\n      method TEXT NOT NULL,\n      client_label TEXT,\n      client_ip_address TEXT,\n      client_user_agent TEXT,\n      client_device_type TEXT NOT NULL DEFAULT 'unknown',\n      client_os TEXT,\n      client_browser TEXT,\n      issued_at TEXT NOT NULL,\n      expires_at TEXT NOT NULL,\n      last_connected_at TEXT,\n      revoked_at TEXT\n    , client_surface TEXT, client_app_version TEXT)"
      ],
      [
        "table",
        "effect_sql_migrations",
        "CREATE TABLE \"effect_sql_migrations\" (\n  migration_id integer PRIMARY KEY NOT NULL,\n  created_at datetime NOT NULL DEFAULT current_timestamp,\n  name VARCHAR(255) NOT NULL\n)"
      ],
      [
        "table",
        "mcp_app_model_context",
        "CREATE TABLE mcp_app_model_context (\n      thread_id TEXT NOT NULL,\n      item_id TEXT NOT NULL,\n      server TEXT NOT NULL,\n      tool TEXT NOT NULL,\n      text TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      PRIMARY KEY (thread_id, item_id)\n    )"
      ],
      [
        "table",
        "orchestration_command_receipts",
        "CREATE TABLE orchestration_command_receipts (\n      command_id TEXT PRIMARY KEY,\n      aggregate_kind TEXT NOT NULL,\n      aggregate_id TEXT NOT NULL,\n      accepted_at TEXT NOT NULL,\n      result_sequence INTEGER NOT NULL,\n      status TEXT NOT NULL,\n      error TEXT\n    , command_type TEXT NOT NULL DEFAULT 'legacy')"
      ],
      [
        "table",
        "orchestration_events",
        "CREATE TABLE orchestration_events (\n      sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n      event_id TEXT NOT NULL UNIQUE,\n      aggregate_kind TEXT NOT NULL,\n      stream_id TEXT NOT NULL,\n      stream_version INTEGER NOT NULL,\n      event_type TEXT NOT NULL,\n      occurred_at TEXT NOT NULL,\n      command_id TEXT,\n      causation_event_id TEXT,\n      correlation_id TEXT,\n      actor_kind TEXT NOT NULL,\n      payload_json TEXT NOT NULL,\n      metadata_json TEXT NOT NULL\n    , application_event_version INTEGER NOT NULL DEFAULT 1)"
      ],
      [
        "table",
        "orchestration_v2_command_receipts",
        "CREATE TABLE orchestration_v2_command_receipts (\n      command_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      command_type TEXT NOT NULL,\n      accepted_at TEXT NOT NULL,\n      result_sequence INTEGER NOT NULL,\n      status TEXT NOT NULL,\n      error TEXT\n    )"
      ],
      [
        "table",
        "orchestration_v2_effect_outbox",
        "CREATE TABLE \"orchestration_v2_effect_outbox\" (\n      effect_id TEXT PRIMARY KEY,\n      command_id TEXT NOT NULL,\n      thread_id TEXT NOT NULL,\n      effect_type TEXT NOT NULL,\n      payload_json TEXT NOT NULL,\n      status TEXT NOT NULL CHECK (\n        status IN ('pending', 'running', 'succeeded', 'failed', 'cancelled')\n      ),\n      attempt_count INTEGER NOT NULL DEFAULT 0,\n      available_at TEXT NOT NULL,\n      lease_owner TEXT,\n      lease_expires_at TEXT,\n      created_at TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      completed_at TEXT,\n      last_error TEXT\n    )"
      ],
      [
        "table",
        "orchestration_v2_events",
        "CREATE TABLE orchestration_v2_events (\n      sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n      event_id TEXT NOT NULL UNIQUE,\n      command_id TEXT,\n      thread_id TEXT NOT NULL,\n      run_id TEXT,\n      node_id TEXT,\n      provider TEXT,\n      raw_event_id TEXT,\n      event_type TEXT NOT NULL,\n      occurred_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    , driver TEXT, provider_instance_id TEXT)"
      ],
      [
        "table",
        "orchestration_v2_legacy_imports",
        "CREATE TABLE orchestration_v2_legacy_imports (\n      thread_id TEXT PRIMARY KEY,\n      source_updated_at TEXT NOT NULL,\n      shell_imported_at TEXT NOT NULL,\n      transcript_imported_at TEXT,\n      imported_message_count INTEGER NOT NULL DEFAULT 0,\n      last_error TEXT\n    )"
      ],
      [
        "table",
        "orchestration_v2_message_search",
        "CREATE VIRTUAL TABLE orchestration_v2_message_search USING fts5(\n      text,\n      content = '',\n      contentless_delete = 1,\n      tokenize = 'trigram remove_diacritics 1'\n    )"
      ],
      [
        "table",
        "orchestration_v2_message_search_config",
        "CREATE TABLE 'orchestration_v2_message_search_config'(k PRIMARY KEY, v) WITHOUT ROWID"
      ],
      [
        "table",
        "orchestration_v2_message_search_data",
        "CREATE TABLE 'orchestration_v2_message_search_data'(id INTEGER PRIMARY KEY, block BLOB)"
      ],
      [
        "table",
        "orchestration_v2_message_search_docsize",
        "CREATE TABLE 'orchestration_v2_message_search_docsize'(id INTEGER PRIMARY KEY, sz BLOB, origin INTEGER)"
      ],
      [
        "table",
        "orchestration_v2_message_search_idx",
        "CREATE TABLE 'orchestration_v2_message_search_idx'(segid, term, pgno, PRIMARY KEY(segid, term)) WITHOUT ROWID"
      ],
      [
        "table",
        "orchestration_v2_projection_checkpoint_scopes",
        "CREATE TABLE orchestration_v2_projection_checkpoint_scopes (\n      scope_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      run_id TEXT,\n      node_id TEXT NOT NULL,\n      parent_scope_id TEXT,\n      provider_thread_id TEXT,\n      kind TEXT NOT NULL,\n      ordinal_within_parent INTEGER NOT NULL,\n      advances_app_run_count INTEGER NOT NULL,\n      created_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_checkpoints",
        "CREATE TABLE orchestration_v2_projection_checkpoints (\n      checkpoint_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      scope_id TEXT NOT NULL,\n      run_id TEXT,\n      node_id TEXT NOT NULL,\n      parent_checkpoint_id TEXT,\n      ordinal_within_scope INTEGER NOT NULL,\n      app_run_ordinal INTEGER,\n      status TEXT NOT NULL,\n      captured_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_context_handoffs",
        "CREATE TABLE orchestration_v2_projection_context_handoffs (\n      context_handoff_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      target_run_id TEXT NOT NULL,\n      to_provider_thread_id TEXT NOT NULL,\n      strategy TEXT NOT NULL,\n      status TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_context_transfers",
        "CREATE TABLE orchestration_v2_projection_context_transfers (\n      context_transfer_id TEXT PRIMARY KEY,\n      source_thread_id TEXT NOT NULL,\n      target_thread_id TEXT NOT NULL,\n      target_run_id TEXT,\n      type TEXT NOT NULL,\n      status TEXT NOT NULL,\n      source_provider TEXT,\n      target_provider TEXT,\n      updated_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    , source_provider_instance_id TEXT, target_provider_instance_id TEXT)"
      ],
      [
        "table",
        "orchestration_v2_projection_messages",
        "CREATE TABLE orchestration_v2_projection_messages (\n      message_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      run_id TEXT,\n      node_id TEXT,\n      role TEXT NOT NULL,\n      streaming INTEGER NOT NULL,\n      created_at TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_metadata",
        "CREATE TABLE orchestration_v2_projection_metadata (\n      projection_name TEXT PRIMARY KEY,\n      schema_version INTEGER NOT NULL,\n      last_sequence INTEGER NOT NULL,\n      updated_at TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_nodes",
        "CREATE TABLE orchestration_v2_projection_nodes (\n      node_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      run_id TEXT,\n      parent_node_id TEXT,\n      root_node_id TEXT NOT NULL,\n      kind TEXT NOT NULL,\n      status TEXT NOT NULL,\n      provider_thread_id TEXT,\n      provider_turn_id TEXT,\n      runtime_request_id TEXT,\n      checkpoint_scope_id TEXT,\n      started_at TEXT,\n      completed_at TEXT,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_plans",
        "CREATE TABLE orchestration_v2_projection_plans (\n      plan_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      run_id TEXT,\n      node_id TEXT NOT NULL,\n      kind TEXT NOT NULL,\n      status TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_provider_session_bindings",
        "CREATE TABLE orchestration_v2_projection_provider_session_bindings (\n      provider_session_id TEXT NOT NULL,\n      thread_id TEXT NOT NULL,\n      PRIMARY KEY (provider_session_id, thread_id)\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_provider_sessions",
        "CREATE TABLE orchestration_v2_projection_provider_sessions (\n      provider_session_id TEXT PRIMARY KEY,\n      thread_id TEXT,\n      provider TEXT NOT NULL,\n      status TEXT NOT NULL,\n      model TEXT,\n      updated_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    , driver TEXT, provider_instance_id TEXT)"
      ],
      [
        "table",
        "orchestration_v2_projection_provider_threads",
        "CREATE TABLE orchestration_v2_projection_provider_threads (\n      provider_thread_id TEXT PRIMARY KEY,\n      thread_id TEXT,\n      owner_node_id TEXT,\n      provider TEXT NOT NULL,\n      provider_session_id TEXT,\n      status TEXT NOT NULL,\n      first_run_ordinal INTEGER,\n      last_run_ordinal INTEGER,\n      updated_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    , driver TEXT, provider_instance_id TEXT)"
      ],
      [
        "table",
        "orchestration_v2_projection_provider_turns",
        "CREATE TABLE orchestration_v2_projection_provider_turns (\n      provider_turn_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      provider_thread_id TEXT NOT NULL,\n      node_id TEXT NOT NULL,\n      run_attempt_id TEXT,\n      ordinal INTEGER NOT NULL,\n      status TEXT NOT NULL,\n      started_at TEXT,\n      completed_at TEXT,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_run_attempts",
        "CREATE TABLE orchestration_v2_projection_run_attempts (\n      attempt_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      run_id TEXT NOT NULL,\n      attempt_ordinal INTEGER NOT NULL,\n      root_node_id TEXT NOT NULL,\n      provider TEXT NOT NULL,\n      provider_thread_id TEXT NOT NULL,\n      provider_turn_id TEXT,\n      status TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    , provider_instance_id TEXT)"
      ],
      [
        "table",
        "orchestration_v2_projection_runs",
        "CREATE TABLE orchestration_v2_projection_runs (\n      run_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      ordinal INTEGER NOT NULL,\n      provider TEXT NOT NULL,\n      provider_thread_id TEXT,\n      status TEXT NOT NULL,\n      requested_at TEXT NOT NULL,\n      completed_at TEXT,\n      payload_json TEXT NOT NULL\n    , provider_instance_id TEXT)"
      ],
      [
        "table",
        "orchestration_v2_projection_runtime_requests",
        "CREATE TABLE orchestration_v2_projection_runtime_requests (\n      runtime_request_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      node_id TEXT NOT NULL,\n      provider_turn_id TEXT,\n      kind TEXT NOT NULL,\n      status TEXT NOT NULL,\n      created_at TEXT NOT NULL,\n      resolved_at TEXT,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_subagents",
        "CREATE TABLE orchestration_v2_projection_subagents (\n      subagent_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      run_id TEXT,\n      parent_node_id TEXT NOT NULL,\n      provider TEXT NOT NULL,\n      provider_thread_id TEXT,\n      child_thread_id TEXT,\n      origin TEXT NOT NULL,\n      status TEXT NOT NULL,\n      started_at TEXT,\n      completed_at TEXT,\n      updated_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    , driver TEXT, provider_instance_id TEXT, completion_delivery_state TEXT)"
      ],
      [
        "table",
        "orchestration_v2_projection_threads",
        "CREATE TABLE orchestration_v2_projection_threads (\n      thread_id TEXT PRIMARY KEY,\n      project_id TEXT NOT NULL,\n      title TEXT NOT NULL,\n      default_provider TEXT NOT NULL,\n      runtime_mode TEXT NOT NULL,\n      interaction_mode TEXT NOT NULL,\n      active_provider_thread_id TEXT,\n      created_at TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      archived_at TEXT,\n      deleted_at TEXT,\n      payload_json TEXT NOT NULL\n    , provider_instance_id TEXT)"
      ],
      [
        "table",
        "orchestration_v2_projection_turn_items",
        "CREATE TABLE orchestration_v2_projection_turn_items (\n      turn_item_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      run_id TEXT,\n      node_id TEXT,\n      provider_thread_id TEXT,\n      provider_turn_id TEXT,\n      parent_item_id TEXT,\n      ordinal INTEGER NOT NULL,\n      type TEXT NOT NULL,\n      status TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_thread_launch_workflows",
        "CREATE TABLE orchestration_v2_thread_launch_workflows (\n      command_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      project_id TEXT NOT NULL,\n      status TEXT NOT NULL,\n      title TEXT NOT NULL,\n      worktree_path TEXT,\n      branch TEXT,\n      setup_committed INTEGER NOT NULL DEFAULT 0,\n      thread_committed INTEGER NOT NULL DEFAULT 0,\n      message_committed INTEGER NOT NULL DEFAULT 0,\n      last_error TEXT,\n      created_at TEXT NOT NULL,\n      updated_at TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_turn_item_positions",
        "CREATE TABLE orchestration_v2_turn_item_positions (\n      thread_id TEXT NOT NULL,\n      turn_item_id TEXT NOT NULL,\n      ordinal INTEGER NOT NULL,\n      PRIMARY KEY (thread_id, turn_item_id),\n      UNIQUE (thread_id, ordinal)\n    )"
      ],
      [
        "table",
        "peer_environment_links",
        "CREATE TABLE peer_environment_links (\n      environment_id TEXT PRIMARY KEY,\n      secret_name TEXT NOT NULL,\n      label TEXT NOT NULL,\n      urls_json TEXT NOT NULL,\n      access TEXT NOT NULL,\n      linked_at TEXT NOT NULL,\n      expires_at TEXT NOT NULL,\n      last_reached_at TEXT,\n      last_error TEXT\n    , fenced INTEGER NOT NULL DEFAULT 0)"
      ],
      [
        "table",
        "projection_projects",
        "CREATE TABLE projection_projects (\n      project_id TEXT PRIMARY KEY,\n      title TEXT NOT NULL,\n      workspace_root TEXT NOT NULL,\n      scripts_json TEXT NOT NULL,\n      created_at TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      deleted_at TEXT\n    , default_model_selection_json TEXT, default_thread_env_mode TEXT, favicon_path TEXT, auto_pull INTEGER NOT NULL DEFAULT 0, project_icon_json TEXT, pinned_at TEXT, archived_at TEXT)"
      ],
      [
        "table",
        "projection_thread_messages",
        "CREATE TABLE projection_thread_messages (\n      message_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      turn_id TEXT,\n      role TEXT NOT NULL,\n      text TEXT NOT NULL,\n      is_streaming INTEGER NOT NULL,\n      created_at TEXT NOT NULL,\n      updated_at TEXT NOT NULL\n    , attachments_json TEXT, context_json TEXT)"
      ],
      [
        "table",
        "projection_thread_pull_requests",
        "CREATE TABLE projection_thread_pull_requests (\n      thread_id TEXT NOT NULL,\n      host TEXT NOT NULL,\n      repository TEXT NOT NULL,\n      number INTEGER NOT NULL,\n      url TEXT NOT NULL,\n      source TEXT NOT NULL,\n      linked_at TEXT NOT NULL,\n      snapshot_json TEXT,\n      stack_json TEXT,\n      PRIMARY KEY (thread_id, host, repository, number)\n    )"
      ],
      [
        "table",
        "projection_thread_sessions",
        "CREATE TABLE projection_thread_sessions (\n      thread_id TEXT PRIMARY KEY,\n      status TEXT NOT NULL,\n      provider_name TEXT,\n      provider_session_id TEXT,\n      provider_thread_id TEXT,\n      active_turn_id TEXT,\n      last_error TEXT,\n      updated_at TEXT NOT NULL\n    , runtime_mode TEXT NOT NULL DEFAULT 'full-access', provider_instance_id TEXT)"
      ],
      [
        "table",
        "projection_threads",
        "CREATE TABLE projection_threads (\n      thread_id TEXT PRIMARY KEY,\n      project_id TEXT NOT NULL,\n      title TEXT NOT NULL,\n      branch TEXT,\n      worktree_path TEXT,\n      latest_turn_id TEXT,\n      created_at TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      deleted_at TEXT\n    , runtime_mode TEXT NOT NULL DEFAULT 'full-access', interaction_mode TEXT NOT NULL DEFAULT 'default', model_selection_json TEXT, archived_at TEXT, latest_user_message_at TEXT, pending_approval_count INTEGER NOT NULL DEFAULT 0, pending_user_input_count INTEGER NOT NULL DEFAULT 0, has_actionable_proposed_plan INTEGER NOT NULL DEFAULT 0, settled_override TEXT, settled_at TEXT, snoozed_until TEXT, snoozed_at TEXT, title_regeneration_request_id TEXT, title_regeneration_started_at TEXT, pinned_at TEXT, pin_order_key TEXT, linked_pull_request_json TEXT, unsettled_at TEXT, branch_pull_request_json TEXT, active_order_key TEXT, title_state_json TEXT, auto_settle_disabled_at TEXT)"
      ],
      [
        "table",
        "provider_session_runtime",
        "CREATE TABLE provider_session_runtime (\n      thread_id TEXT PRIMARY KEY,\n      provider_name TEXT NOT NULL,\n      adapter_key TEXT NOT NULL,\n      runtime_mode TEXT NOT NULL DEFAULT 'full-access',\n      status TEXT NOT NULL,\n      last_seen_at TEXT NOT NULL,\n      resume_cursor_json TEXT,\n      runtime_payload_json TEXT\n    , provider_instance_id TEXT)"
      ],
      [
        "table",
        "pull_request_files_viewed",
        "CREATE TABLE pull_request_files_viewed (\n      provider TEXT NOT NULL,\n      host TEXT NOT NULL,\n      repository TEXT NOT NULL,\n      number INTEGER NOT NULL,\n      viewer TEXT NOT NULL,\n      path TEXT NOT NULL,\n      revision TEXT,\n      viewed_at TEXT NOT NULL,\n      PRIMARY KEY (provider, host, repository, number, viewer, path)\n    ) WITHOUT ROWID\n  "
      ],
      [
        "table",
        "pull_request_review_guides",
        "CREATE TABLE pull_request_review_guides (\n      host TEXT NOT NULL,\n      repository TEXT NOT NULL,\n      number INTEGER NOT NULL,\n      guide_json TEXT NOT NULL,\n      PRIMARY KEY (host, repository, number)\n    ) WITHOUT ROWID\n  "
      ],
      [
        "table",
        "scheduled_task_webhook_deliveries",
        "CREATE TABLE scheduled_task_webhook_deliveries (\n      delivery_id TEXT PRIMARY KEY,\n      task_id TEXT NOT NULL,\n      received_at TEXT NOT NULL,\n      method TEXT NOT NULL,\n      query TEXT NOT NULL,\n      headers_json TEXT NOT NULL,\n      body TEXT NOT NULL,\n      body_bytes INTEGER NOT NULL,\n      body_truncated INTEGER NOT NULL,\n      outcome TEXT NOT NULL,\n      signature_verified INTEGER NOT NULL,\n      missing_fields_json TEXT NOT NULL,\n      rendered_prompt TEXT,\n      error TEXT\n    )"
      ],
      [
        "table",
        "scheduled_task_webhook_pending",
        "CREATE TABLE scheduled_task_webhook_pending (\n    delivery_id TEXT PRIMARY KEY,\n    task_id TEXT NOT NULL REFERENCES scheduled_tasks(task_id) ON DELETE CASCADE,\n    coalesce_key TEXT NOT NULL,\n    due_at INTEGER NOT NULL,\n    state TEXT NOT NULL DEFAULT 'pending',\n    task_json TEXT NOT NULL,\n    request_json TEXT NOT NULL,\n    delivery_ids_json TEXT NOT NULL\n  )"
      ],
      [
        "table",
        "scheduled_task_webhook_relay_deliveries",
        "CREATE TABLE scheduled_task_webhook_relay_deliveries (\n      relay_delivery_id TEXT PRIMARY KEY,\n      task_id TEXT NOT NULL,\n      seen_at TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "scheduled_task_webhook_replay_keys",
        "CREATE TABLE scheduled_task_webhook_replay_keys (\n    task_id TEXT NOT NULL REFERENCES scheduled_tasks(task_id) ON DELETE CASCADE,\n    replay_key TEXT NOT NULL,\n    delivery_id TEXT NOT NULL,\n    expires_at INTEGER NOT NULL,\n    PRIMARY KEY (task_id, replay_key)\n  )"
      ],
      [
        "table",
        "scheduled_tasks",
        "CREATE TABLE scheduled_tasks (\n      task_id TEXT PRIMARY KEY,\n      title TEXT NOT NULL,\n      prompt TEXT NOT NULL,\n      enabled INTEGER NOT NULL,\n      schedule_json TEXT NOT NULL,\n      project_id TEXT NOT NULL,\n      thread_id TEXT,\n      workspace_strategy_json TEXT NOT NULL,\n      model_selection_json TEXT NOT NULL,\n      runtime_mode TEXT NOT NULL,\n      interaction_mode TEXT NOT NULL,\n      created_by TEXT NOT NULL,\n      creation_source TEXT NOT NULL,\n      created_at TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      next_run_at TEXT,\n      last_run_at TEXT,\n      last_run_status TEXT NOT NULL,\n      last_run_error TEXT,\n      run_count INTEGER NOT NULL\n    , webhook_token TEXT, webhook_secret TEXT, last_run_webhook_delivery_id TEXT, thread_mode TEXT NOT NULL DEFAULT 'new_thread')"
      ],
      [
        "trigger",
        "orchestration_v2_message_search_delete",
        "CREATE TRIGGER orchestration_v2_message_search_delete\n      AFTER DELETE ON orchestration_v2_projection_messages\n      WHEN old.streaming = 0\n      BEGIN\n        DELETE FROM orchestration_v2_message_search WHERE rowid = old.rowid;\n      END"
      ],
      [
        "trigger",
        "orchestration_v2_message_search_insert",
        "CREATE TRIGGER orchestration_v2_message_search_insert\n      AFTER INSERT ON orchestration_v2_projection_messages\n      WHEN \n  \n  new.streaming = 0\n  AND (\n    new.role = 'assistant'\n    OR (\n      new.role = 'user'\n      AND COALESCE(json_extract(new.payload_json, '$.createdBy'), 'user') = 'user'\n    )\n  )\n  AND NOT EXISTS (\n    SELECT 1 FROM orchestration_v2_projection_threads AS subagent_threads\n    WHERE subagent_threads.thread_id = new.thread_id\n      AND json_extract(subagent_threads.payload_json, '$.lineage.relationshipToParent') = 'subagent'\n  )\n\n  AND \n  CASE\n    WHEN substr(json_extract(new.payload_json, '$.text'), 1, 11) = 'Ultrathink:' COLLATE NOCASE\n      THEN ltrim(substr(json_extract(new.payload_json, '$.text'), 12), '\t\n\u000b\f\r \u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff')\n    ELSE json_extract(new.payload_json, '$.text')\n  END COLLATE BINARY <> '[User attached one or more files without additional text. Respond using the conversation context and the attached files.]'\n\n\n      BEGIN\n        INSERT INTO orchestration_v2_message_search (rowid, text)\n        SELECT new.rowid, replace(replace(json_extract(new.payload_json, '$.text'), '\u2019', ''''), '\u2018', '''')\n        WHERE json_extract(new.payload_json, '$.text') IS NOT NULL;\n      END"
      ],
      [
        "trigger",
        "orchestration_v2_message_search_update",
        "CREATE TRIGGER orchestration_v2_message_search_update\n      AFTER UPDATE OF payload_json, streaming, role ON orchestration_v2_projection_messages\n      WHEN (old.streaming = 0 OR new.streaming = 0)\n        AND (\n          old.streaming IS NOT new.streaming\n          OR old.role IS NOT new.role\n          OR json_extract(old.payload_json, '$.text') IS NOT json_extract(new.payload_json, '$.text')\n          OR json_extract(old.payload_json, '$.createdBy')\n            IS NOT json_extract(new.payload_json, '$.createdBy')\n        )\n      BEGIN\n        DELETE FROM orchestration_v2_message_search WHERE rowid = old.rowid AND old.streaming = 0;\n        INSERT INTO orchestration_v2_message_search (rowid, text)\n        SELECT new.rowid, replace(replace(json_extract(new.payload_json, '$.text'), '\u2019', ''''), '\u2018', '''')\n        WHERE \n  \n  new.streaming = 0\n  AND (\n    new.role = 'assistant'\n    OR (\n      new.role = 'user'\n      AND COALESCE(json_extract(new.payload_json, '$.createdBy'), 'user') = 'user'\n    )\n  )\n  AND NOT EXISTS (\n    SELECT 1 FROM orchestration_v2_projection_threads AS subagent_threads\n    WHERE subagent_threads.thread_id = new.thread_id\n      AND json_extract(subagent_threads.payload_json, '$.lineage.relationshipToParent') = 'subagent'\n  )\n\n  AND \n  CASE\n    WHEN substr(json_extract(new.payload_json, '$.text'), 1, 11) = 'Ultrathink:' COLLATE NOCASE\n      THEN ltrim(substr(json_extract(new.payload_json, '$.text'), 12), '\t\n\u000b\f\r \u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff')\n    ELSE json_extract(new.payload_json, '$.text')\n  END COLLATE BINARY <> '[User attached one or more files without additional text. Respond using the conversation context and the attached files.]'\n\n\n          AND json_extract(new.payload_json, '$.text') IS NOT NULL;\n      END"
      ]
    ]
  },
  "after": {
    "ledger": [
      [
        1,
        "OrchestrationEvents"
      ],
      [
        2,
        "OrchestrationCommandReceipts"
      ],
      [
        3,
        "CheckpointDiffBlobs"
      ],
      [
        4,
        "ProviderSessionRuntime"
      ],
      [
        5,
        "Projections"
      ],
      [
        6,
        "ProjectionThreadSessionRuntimeModeColumns"
      ],
      [
        7,
        "ProjectionThreadMessageAttachments"
      ],
      [
        8,
        "ProjectionThreadActivitySequence"
      ],
      [
        9,
        "ProviderSessionRuntimeMode"
      ],
      [
        10,
        "ProjectionThreadsRuntimeMode"
      ],
      [
        11,
        "OrchestrationThreadCreatedRuntimeMode"
      ],
      [
        12,
        "ProjectionThreadsInteractionMode"
      ],
      [
        13,
        "ProjectionThreadProposedPlans"
      ],
      [
        14,
        "ProjectionThreadProposedPlanImplementation"
      ],
      [
        15,
        "ProjectionTurnsSourceProposedPlan"
      ],
      [
        16,
        "CanonicalizeModelSelections"
      ],
      [
        17,
        "ProjectionThreadsArchivedAt"
      ],
      [
        18,
        "ProjectionThreadsArchivedAtIndex"
      ],
      [
        19,
        "ProjectionSnapshotLookupIndexes"
      ],
      [
        20,
        "AuthAccessManagement"
      ],
      [
        21,
        "AuthSessionClientMetadata"
      ],
      [
        22,
        "AuthSessionLastConnectedAt"
      ],
      [
        23,
        "ProjectionThreadShellSummary"
      ],
      [
        24,
        "BackfillProjectionThreadShellSummary"
      ],
      [
        25,
        "CleanupInvalidProjectionPendingApprovals"
      ],
      [
        26,
        "CanonicalizeModelSelectionOptions"
      ],
      [
        27,
        "ProviderSessionRuntimeInstanceId"
      ],
      [
        28,
        "ProjectionThreadSessionInstanceId"
      ],
      [
        29,
        "ProjectionThreadDetailOrderingIndexes"
      ],
      [
        30,
        "ProjectionThreadShellArchiveIndexes"
      ],
      [
        31,
        "AuthAuthorizationScopes"
      ],
      [
        32,
        "AuthPairingProofKeyThumbprint"
      ],
      [
        33,
        "ProjectionThreadsSettled"
      ],
      [
        34,
        "ProjectionThreadsSnoozed"
      ],
      [
        35,
        "ProjectionThreadTitleRegeneration"
      ],
      [
        36,
        "ProjectionThreadsPinned"
      ],
      [
        37,
        "ProjectionTurnsKeysetIndex"
      ],
      [
        38,
        "ProjectionThreadsPinOrderKey"
      ],
      [
        39,
        "ProjectionProjectsDefaultThreadEnvMode"
      ],
      [
        40,
        "ProjectionProjectFaviconPath"
      ],
      [
        41,
        "AuthSessionClientConnection"
      ],
      [
        42,
        "ProjectionThreadLinkedPullRequest"
      ],
      [
        43,
        "ProjectionThreadsUnsettledAt"
      ],
      [
        44,
        "ClearAutomaticProjectModelDefaults"
      ],
      [
        45,
        "ProjectionProjectsAutoPull"
      ],
      [
        46,
        "RepairAutomaticSettlementTimestamps"
      ],
      [
        47,
        "ProjectionProjectIcon"
      ],
      [
        48,
        "ProjectionThreadBranchPullRequest"
      ],
      [
        49,
        "ProjectionThreadsActiveOrderKey"
      ],
      [
        50,
        "ProjectionThreadPullRequests"
      ],
      [
        51,
        "ProjectionThreadMessageContext"
      ],
      [
        52,
        "ProjectionThreadTitleState"
      ],
      [
        53,
        "PullRequestFilesViewed"
      ],
      [
        54,
        "ProjectionThreadsAutoSettleDisabledAt"
      ],
      [
        55,
        "OrchestrationV2"
      ],
      [
        56,
        "RemoveRedundantProjectionIndexes"
      ],
      [
        57,
        "ScheduledTaskWebhooks"
      ],
      [
        58,
        "WebhookRelayDeliveries"
      ],
      [
        59,
        "McpAppModelContext"
      ],
      [
        60,
        "ThreadSnapshotWindowIndexes"
      ],
      [
        61,
        "PullRequestReviewGuides"
      ],
      [
        62,
        "ThreadFailureLookupIndex"
      ],
      [
        63,
        "DropUnusedV1Projections"
      ],
      [
        64,
        "CanonicalizeThreadPullRequestLinks"
      ],
      [
        65,
        "CodexUsageNativeTurnIndex"
      ],
      [
        66,
        "RepairClientSettlementTimestamps"
      ],
      [
        67,
        "WebhookDedupe"
      ],
      [
        68,
        "ShellStopRequestIndex"
      ],
      [
        69,
        "ThreadMessageSearch"
      ],
      [
        70,
        "PeerLinks"
      ],
      [
        71,
        "PeerLinkFence"
      ],
      [
        72,
        "WaitingLinkRequestIndex"
      ],
      [
        73,
        "ActiveTurnItemIndexes"
      ],
      [
        74,
        "ExcludeAttachmentPlaceholdersFromSearch"
      ],
      [
        75,
        "SubagentDeliveryState"
      ],
      [
        76,
        "ProjectionProjectsPinArchive"
      ],
      [
        77,
        "RepairBooleanSettledOverride"
      ],
      [
        78,
        "DropOrchestrationEventCorrelationIndex"
      ],
      [
        79,
        "DelegatedRecoveryIndexes"
      ],
      [
        80,
        "ScheduledTaskThreadMode"
      ]
    ],
    "schema": [
      [
        "index",
        "idx_auth_pairing_links_active",
        "CREATE INDEX idx_auth_pairing_links_active\n    ON auth_pairing_links(revoked_at, consumed_at, expires_at)\n  "
      ],
      [
        "index",
        "idx_auth_sessions_active",
        "CREATE INDEX idx_auth_sessions_active\n    ON auth_sessions(revoked_at, expires_at, issued_at)\n  "
      ],
      [
        "index",
        "idx_orch_command_receipts_aggregate",
        "CREATE INDEX idx_orch_command_receipts_aggregate\n    ON orchestration_command_receipts(aggregate_kind, aggregate_id)\n  "
      ],
      [
        "index",
        "idx_orch_command_receipts_sequence",
        "CREATE INDEX idx_orch_command_receipts_sequence\n    ON orchestration_command_receipts(result_sequence)\n  "
      ],
      [
        "index",
        "idx_orch_events_command_id",
        "CREATE INDEX idx_orch_events_command_id\n    ON orchestration_events(command_id)\n  "
      ],
      [
        "index",
        "idx_orch_events_stream_sequence",
        "CREATE INDEX idx_orch_events_stream_sequence\n    ON orchestration_events(aggregate_kind, stream_id, sequence)\n  "
      ],
      [
        "index",
        "idx_orch_events_stream_version",
        "CREATE UNIQUE INDEX idx_orch_events_stream_version\n    ON orchestration_events(aggregate_kind, stream_id, stream_version)\n  "
      ],
      [
        "index",
        "idx_orchestration_events_agent_stream_sequence",
        "CREATE INDEX idx_orchestration_events_agent_stream_sequence\n    ON orchestration_events(stream_id, sequence)\n    WHERE application_event_version = 2 AND aggregate_kind = 'thread'\n  "
      ],
      [
        "index",
        "idx_orchestration_events_application_high_water",
        "CREATE INDEX idx_orchestration_events_application_high_water\n    ON orchestration_events(sequence)\n    WHERE aggregate_kind = 'project'\n      OR (application_event_version = 2 AND aggregate_kind = 'thread')\n  "
      ],
      [
        "index",
        "idx_orchestration_events_application_sequence",
        "CREATE INDEX idx_orchestration_events_application_sequence\n    ON orchestration_events(application_event_version, sequence)\n  "
      ],
      [
        "index",
        "idx_projection_projects_updated_at",
        "CREATE INDEX idx_projection_projects_updated_at\n    ON projection_projects(updated_at)\n  "
      ],
      [
        "index",
        "idx_projection_projects_workspace_root_deleted_at",
        "CREATE INDEX idx_projection_projects_workspace_root_deleted_at\n    ON projection_projects(workspace_root, deleted_at)\n  "
      ],
      [
        "index",
        "idx_projection_thread_messages_thread_created_id",
        "CREATE INDEX idx_projection_thread_messages_thread_created_id\n    ON projection_thread_messages(thread_id, created_at, message_id)\n  "
      ],
      [
        "index",
        "idx_projection_thread_pull_requests_pr",
        "CREATE INDEX idx_projection_thread_pull_requests_pr\n    ON projection_thread_pull_requests(host, repository, number)\n  "
      ],
      [
        "index",
        "idx_projection_thread_sessions_instance",
        "CREATE INDEX idx_projection_thread_sessions_instance\n    ON projection_thread_sessions(provider_instance_id)\n  "
      ],
      [
        "index",
        "idx_projection_thread_sessions_provider_session",
        "CREATE INDEX idx_projection_thread_sessions_provider_session\n    ON projection_thread_sessions(provider_session_id)\n  "
      ],
      [
        "index",
        "idx_projection_threads_project_archived_at",
        "CREATE INDEX idx_projection_threads_project_archived_at\n    ON projection_threads(project_id, archived_at)\n  "
      ],
      [
        "index",
        "idx_projection_threads_project_deleted_created",
        "CREATE INDEX idx_projection_threads_project_deleted_created\n    ON projection_threads(project_id, deleted_at, created_at)\n  "
      ],
      [
        "index",
        "idx_projection_threads_shell_active",
        "CREATE INDEX idx_projection_threads_shell_active\n    ON projection_threads(deleted_at, archived_at, project_id, created_at, thread_id)\n  "
      ],
      [
        "index",
        "idx_projection_threads_shell_archived",
        "CREATE INDEX idx_projection_threads_shell_archived\n    ON projection_threads(deleted_at, archived_at, project_id, thread_id)\n  "
      ],
      [
        "index",
        "idx_provider_session_runtime_instance",
        "CREATE INDEX idx_provider_session_runtime_instance\n    ON provider_session_runtime(provider_instance_id)\n  "
      ],
      [
        "index",
        "idx_provider_session_runtime_provider",
        "CREATE INDEX idx_provider_session_runtime_provider\n    ON provider_session_runtime(provider_name)\n  "
      ],
      [
        "index",
        "idx_provider_session_runtime_status",
        "CREATE INDEX idx_provider_session_runtime_status\n    ON provider_session_runtime(status)\n  "
      ],
      [
        "index",
        "idx_scheduled_task_webhook_deliveries_task",
        "CREATE INDEX idx_scheduled_task_webhook_deliveries_task\n    ON scheduled_task_webhook_deliveries(task_id, received_at)\n  "
      ],
      [
        "index",
        "idx_scheduled_task_webhook_relay_deliveries_seen",
        "CREATE INDEX idx_scheduled_task_webhook_relay_deliveries_seen\n    ON scheduled_task_webhook_relay_deliveries(seen_at)\n  "
      ],
      [
        "index",
        "idx_scheduled_tasks_due",
        "CREATE INDEX idx_scheduled_tasks_due\n    ON scheduled_tasks(enabled, next_run_at)\n    WHERE enabled = 1 AND next_run_at IS NOT NULL\n  "
      ],
      [
        "index",
        "idx_scheduled_tasks_project",
        "CREATE INDEX idx_scheduled_tasks_project\n    ON scheduled_tasks(project_id, updated_at)\n  "
      ],
      [
        "index",
        "idx_webhook_pending_due",
        "CREATE INDEX idx_webhook_pending_due ON scheduled_task_webhook_pending(state, due_at)"
      ],
      [
        "index",
        "idx_webhook_pending_key",
        "CREATE UNIQUE INDEX idx_webhook_pending_key\n    ON scheduled_task_webhook_pending(task_id, coalesce_key) WHERE state = 'pending'"
      ],
      [
        "index",
        "idx_webhook_replay_delivery",
        "CREATE INDEX idx_webhook_replay_delivery ON scheduled_task_webhook_replay_keys(delivery_id)"
      ],
      [
        "index",
        "idx_webhook_replay_expiry",
        "CREATE INDEX idx_webhook_replay_expiry ON scheduled_task_webhook_replay_keys(expires_at)"
      ],
      [
        "index",
        "orchestration_events_v2_created_threads_idx",
        "CREATE INDEX orchestration_events_v2_created_threads_idx\n    ON orchestration_events(stream_id)\n    WHERE application_event_version = 2\n      AND aggregate_kind = 'thread'\n      AND event_type = 'thread.created'\n  "
      ],
      [
        "index",
        "orchestration_v2_command_receipts_thread_sequence_idx",
        "CREATE INDEX orchestration_v2_command_receipts_thread_sequence_idx ON orchestration_v2_command_receipts(thread_id, result_sequence)"
      ],
      [
        "index",
        "orchestration_v2_effect_outbox_claim_idx",
        "CREATE INDEX orchestration_v2_effect_outbox_claim_idx\n    ON orchestration_v2_effect_outbox(status, available_at, lease_expires_at, created_at)\n  "
      ],
      [
        "index",
        "orchestration_v2_effect_outbox_command_idx",
        "CREATE INDEX orchestration_v2_effect_outbox_command_idx\n    ON orchestration_v2_effect_outbox(command_id, effect_id)\n  "
      ],
      [
        "index",
        "orchestration_v2_effect_outbox_thread_status_idx",
        "CREATE INDEX orchestration_v2_effect_outbox_thread_status_idx\n    ON orchestration_v2_effect_outbox(thread_id, status, effect_type)\n  "
      ],
      [
        "index",
        "orchestration_v2_events_command_idx",
        "CREATE INDEX orchestration_v2_events_command_idx ON orchestration_v2_events(command_id, sequence)"
      ],
      [
        "index",
        "orchestration_v2_events_instance_sequence_idx",
        "CREATE INDEX orchestration_v2_events_instance_sequence_idx ON orchestration_v2_events(provider_instance_id, sequence)"
      ],
      [
        "index",
        "orchestration_v2_events_node_sequence_idx",
        "CREATE INDEX orchestration_v2_events_node_sequence_idx ON orchestration_v2_events(node_id, sequence)"
      ],
      [
        "index",
        "orchestration_v2_events_raw_event_idx",
        "CREATE INDEX orchestration_v2_events_raw_event_idx ON orchestration_v2_events(raw_event_id)"
      ],
      [
        "index",
        "orchestration_v2_events_run_sequence_idx",
        "CREATE INDEX orchestration_v2_events_run_sequence_idx ON orchestration_v2_events(run_id, sequence)"
      ],
      [
        "index",
        "orchestration_v2_events_thread_sequence_idx",
        "CREATE INDEX orchestration_v2_events_thread_sequence_idx ON orchestration_v2_events(thread_id, sequence)"
      ],
      [
        "index",
        "orchestration_v2_events_thread_type_sequence_idx",
        "CREATE INDEX orchestration_v2_events_thread_type_sequence_idx ON orchestration_v2_events(thread_id, event_type, sequence)"
      ],
      [
        "index",
        "orchestration_v2_legacy_imports_pending_transcript_idx",
        "CREATE INDEX orchestration_v2_legacy_imports_pending_transcript_idx\n    ON orchestration_v2_legacy_imports(transcript_imported_at, shell_imported_at, thread_id)\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_checkpoint_scopes_parent_idx",
        "CREATE INDEX orchestration_v2_projection_checkpoint_scopes_parent_idx ON orchestration_v2_projection_checkpoint_scopes(parent_scope_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_checkpoint_scopes_thread_idx",
        "CREATE INDEX orchestration_v2_projection_checkpoint_scopes_thread_idx ON orchestration_v2_projection_checkpoint_scopes(thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_checkpoints_parent_idx",
        "CREATE INDEX orchestration_v2_projection_checkpoints_parent_idx ON orchestration_v2_projection_checkpoints(parent_checkpoint_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_checkpoints_scope_ordinal_idx",
        "CREATE UNIQUE INDEX orchestration_v2_projection_checkpoints_scope_ordinal_idx ON orchestration_v2_projection_checkpoints(scope_id, ordinal_within_scope)"
      ],
      [
        "index",
        "orchestration_v2_projection_checkpoints_thread_idx",
        "CREATE INDEX orchestration_v2_projection_checkpoints_thread_idx ON orchestration_v2_projection_checkpoints(thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_context_handoffs_target_run_idx",
        "CREATE INDEX orchestration_v2_projection_context_handoffs_target_run_idx ON orchestration_v2_projection_context_handoffs(target_run_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_context_handoffs_thread_idx",
        "CREATE INDEX orchestration_v2_projection_context_handoffs_thread_idx ON orchestration_v2_projection_context_handoffs(thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_context_transfers_source_thread_idx",
        "CREATE INDEX orchestration_v2_projection_context_transfers_source_thread_idx ON orchestration_v2_projection_context_transfers(source_thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_context_transfers_target_run_idx",
        "CREATE INDEX orchestration_v2_projection_context_transfers_target_run_idx ON orchestration_v2_projection_context_transfers(target_run_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_context_transfers_target_thread_idx",
        "CREATE INDEX orchestration_v2_projection_context_transfers_target_thread_idx ON orchestration_v2_projection_context_transfers(target_thread_id, status)"
      ],
      [
        "index",
        "orchestration_v2_projection_messages_latest_user_idx",
        "CREATE INDEX orchestration_v2_projection_messages_latest_user_idx\n    ON orchestration_v2_projection_messages(thread_id, updated_at DESC, message_id DESC)\n    WHERE role = 'user'\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_messages_node_idx",
        "CREATE INDEX orchestration_v2_projection_messages_node_idx ON orchestration_v2_projection_messages(node_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_messages_run_idx",
        "CREATE INDEX orchestration_v2_projection_messages_run_idx ON orchestration_v2_projection_messages(run_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_messages_thread_created_idx",
        "CREATE INDEX orchestration_v2_projection_messages_thread_created_idx ON orchestration_v2_projection_messages(thread_id, created_at, message_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_nodes_live_idx",
        "CREATE INDEX orchestration_v2_projection_nodes_live_idx\n    ON orchestration_v2_projection_nodes(thread_id)\n    WHERE status IN ('pending', 'starting', 'running', 'waiting')\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_nodes_parent_idx",
        "CREATE INDEX orchestration_v2_projection_nodes_parent_idx ON orchestration_v2_projection_nodes(parent_node_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_nodes_provider_turn_idx",
        "CREATE INDEX orchestration_v2_projection_nodes_provider_turn_idx ON orchestration_v2_projection_nodes(provider_turn_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_nodes_thread_run_idx",
        "CREATE INDEX orchestration_v2_projection_nodes_thread_run_idx ON orchestration_v2_projection_nodes(thread_id, run_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_plans_run_idx",
        "CREATE INDEX orchestration_v2_projection_plans_run_idx ON orchestration_v2_projection_plans(run_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_plans_thread_idx",
        "CREATE INDEX orchestration_v2_projection_plans_thread_idx ON orchestration_v2_projection_plans(thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_session_bindings_thread_idx",
        "CREATE INDEX orchestration_v2_projection_provider_session_bindings_thread_idx\n    ON orchestration_v2_projection_provider_session_bindings(thread_id)\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_provider_sessions_instance_status_idx",
        "CREATE INDEX orchestration_v2_projection_provider_sessions_instance_status_idx ON orchestration_v2_projection_provider_sessions(provider_instance_id, status)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_sessions_provider_status_idx",
        "CREATE INDEX orchestration_v2_projection_provider_sessions_provider_status_idx ON orchestration_v2_projection_provider_sessions(provider, status)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_sessions_thread_idx",
        "CREATE INDEX orchestration_v2_projection_provider_sessions_thread_idx ON orchestration_v2_projection_provider_sessions(thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_threads_instance_status_idx",
        "CREATE INDEX orchestration_v2_projection_provider_threads_instance_status_idx ON orchestration_v2_projection_provider_threads(provider_instance_id, status)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_threads_owner_idx",
        "CREATE INDEX orchestration_v2_projection_provider_threads_owner_idx ON orchestration_v2_projection_provider_threads(owner_node_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_threads_session_idx",
        "CREATE INDEX orchestration_v2_projection_provider_threads_session_idx ON orchestration_v2_projection_provider_threads(provider_session_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_threads_thread_idx",
        "CREATE INDEX orchestration_v2_projection_provider_threads_thread_idx ON orchestration_v2_projection_provider_threads(thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_turns_thread_idx",
        "CREATE INDEX orchestration_v2_projection_provider_turns_thread_idx ON orchestration_v2_projection_provider_turns(thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_provider_turns_thread_ordinal_idx",
        "CREATE UNIQUE INDEX orchestration_v2_projection_provider_turns_thread_ordinal_idx ON orchestration_v2_projection_provider_turns(provider_thread_id, ordinal)"
      ],
      [
        "index",
        "orchestration_v2_projection_requests_recovery_idx",
        "CREATE INDEX orchestration_v2_projection_requests_recovery_idx\n    ON orchestration_v2_projection_runtime_requests(thread_id)\n    WHERE status = 'pending'\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_run_attempts_run_ordinal_idx",
        "CREATE UNIQUE INDEX orchestration_v2_projection_run_attempts_run_ordinal_idx ON orchestration_v2_projection_run_attempts(run_id, attempt_ordinal)"
      ],
      [
        "index",
        "orchestration_v2_projection_run_attempts_thread_idx",
        "CREATE INDEX orchestration_v2_projection_run_attempts_thread_idx ON orchestration_v2_projection_run_attempts(thread_id, run_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_runs_delegated_delivery_idx",
        "CREATE INDEX orchestration_v2_projection_runs_delegated_delivery_idx\n    ON orchestration_v2_projection_runs(thread_id)\n    WHERE CASE WHEN json_valid(payload_json)\n      THEN json_type(payload_json, '$.delegatedCompletion.delivery') = 'object'\n      ELSE 0 END\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_runs_provider_thread_idx",
        "CREATE INDEX orchestration_v2_projection_runs_provider_thread_idx ON orchestration_v2_projection_runs(provider_thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_runs_recovery_idx",
        "CREATE INDEX orchestration_v2_projection_runs_recovery_idx\n    ON orchestration_v2_projection_runs(status, thread_id)\n    WHERE status IN ('queued', 'preparing', 'starting', 'running', 'waiting')\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_runs_thread_ordinal_idx",
        "CREATE UNIQUE INDEX orchestration_v2_projection_runs_thread_ordinal_idx ON orchestration_v2_projection_runs(thread_id, ordinal)"
      ],
      [
        "index",
        "orchestration_v2_projection_runs_thread_status_idx",
        "CREATE INDEX orchestration_v2_projection_runs_thread_status_idx ON orchestration_v2_projection_runs(thread_id, status)"
      ],
      [
        "index",
        "orchestration_v2_projection_runtime_requests_provider_turn_idx",
        "CREATE INDEX orchestration_v2_projection_runtime_requests_provider_turn_idx ON orchestration_v2_projection_runtime_requests(provider_turn_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_runtime_requests_thread_status_idx",
        "CREATE INDEX orchestration_v2_projection_runtime_requests_thread_status_idx ON orchestration_v2_projection_runtime_requests(thread_id, status)"
      ],
      [
        "index",
        "orchestration_v2_projection_subagents_child_thread_idx",
        "CREATE INDEX orchestration_v2_projection_subagents_child_thread_idx ON orchestration_v2_projection_subagents(child_thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_subagents_parent_node_idx",
        "CREATE INDEX orchestration_v2_projection_subagents_parent_node_idx ON orchestration_v2_projection_subagents(parent_node_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_subagents_provider_thread_idx",
        "CREATE INDEX orchestration_v2_projection_subagents_provider_thread_idx ON orchestration_v2_projection_subagents(provider_thread_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_subagents_settled_idx",
        "CREATE INDEX orchestration_v2_projection_subagents_settled_idx\n    ON orchestration_v2_projection_subagents(thread_id, status, completion_delivery_state, run_id)\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_subagents_thread_idx",
        "CREATE INDEX orchestration_v2_projection_subagents_thread_idx ON orchestration_v2_projection_subagents(thread_id, started_at, subagent_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_threads_project_updated_idx",
        "CREATE INDEX orchestration_v2_projection_threads_project_updated_idx ON orchestration_v2_projection_threads(project_id, updated_at)"
      ],
      [
        "index",
        "orchestration_v2_projection_threads_subagent_result_idx",
        "CREATE INDEX orchestration_v2_projection_threads_subagent_result_idx\n    ON orchestration_v2_projection_threads(\n      thread_id, json_extract(payload_json, '$.lineage.parentThreadId')\n    )\n    WHERE CASE WHEN json_valid(payload_json) THEN\n      json_extract(payload_json, '$.lineage.relationshipToParent') = 'subagent'\n      AND json_extract(payload_json, '$.lineage.parentThreadId') IS NOT NULL\n      AND json_extract(payload_json, '$.forkedFrom.type') = 'node'\n      ELSE 0 END\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_active_ordinal_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_active_ordinal_idx\n    ON orchestration_v2_projection_turn_items(thread_id, ordinal, turn_item_id)\n    WHERE status IN ('pending', 'running', 'waiting')\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_active_run_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_active_run_idx\n    ON orchestration_v2_projection_turn_items(thread_id, run_id)\n    WHERE status IN ('pending', 'running', 'waiting')\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_failed_error_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_failed_error_idx\n    ON orchestration_v2_projection_turn_items(\n      thread_id, run_id, node_id, updated_at DESC, ordinal DESC, turn_item_id DESC\n    )\n    WHERE type = 'error' AND status = 'failed'\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_node_ordinal_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_node_ordinal_idx ON orchestration_v2_projection_turn_items(node_id, ordinal)"
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_provider_turn_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_provider_turn_idx ON orchestration_v2_projection_turn_items(provider_turn_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_recovery_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_recovery_idx\n    ON orchestration_v2_projection_turn_items(thread_id)\n    WHERE type IN ('command_execution', 'dynamic_tool', 'subagent')\n      AND status IN ('pending', 'running', 'waiting')\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_run_ordinal_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_run_ordinal_idx ON orchestration_v2_projection_turn_items(run_id, ordinal)"
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_shell_pending_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_shell_pending_idx\n    ON orchestration_v2_projection_turn_items(thread_id, run_id)\n    WHERE type IN ('command_execution', 'dynamic_tool', 'subagent')\n      AND status NOT IN ('completed', 'interrupted', 'failed', 'cancelled')\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_stop_request_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_stop_request_idx\n    ON orchestration_v2_projection_turn_items(thread_id, run_id)\n    WHERE type = 'run_interrupt_request'\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_thread_ordinal_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_thread_ordinal_idx ON orchestration_v2_projection_turn_items(thread_id, ordinal, turn_item_id)"
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_thread_run_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_thread_run_idx\n    ON orchestration_v2_projection_turn_items(thread_id, run_id)\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_user_message_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_user_message_idx\n    ON orchestration_v2_projection_turn_items(thread_id, ordinal, turn_item_id)\n    WHERE type = 'user_message'\n  "
      ],
      [
        "index",
        "orchestration_v2_projection_turn_items_waiting_link_idx",
        "CREATE INDEX orchestration_v2_projection_turn_items_waiting_link_idx\n    ON orchestration_v2_projection_turn_items(thread_id, updated_at DESC, turn_item_id DESC)\n    WHERE type = 'link_request' AND status = 'waiting'\n  "
      ],
      [
        "index",
        "orchestration_v2_provider_turns_codex_native_id_idx",
        "CREATE INDEX orchestration_v2_provider_turns_codex_native_id_idx\n    ON orchestration_v2_projection_provider_turns (\n      json_extract(payload_json, '$.nativeTurnRef.nativeId')\n    )\n    WHERE json_extract(payload_json, '$.nativeTurnRef.driver') = 'codex'\n  "
      ],
      [
        "table",
        "auth_pairing_links",
        "CREATE TABLE auth_pairing_links (\n      id TEXT PRIMARY KEY,\n      credential TEXT NOT NULL UNIQUE,\n      method TEXT NOT NULL,\n      scopes TEXT NOT NULL,\n      subject TEXT NOT NULL,\n      label TEXT,\n      created_at TEXT NOT NULL,\n      expires_at TEXT NOT NULL,\n      consumed_at TEXT,\n      revoked_at TEXT\n    , proof_key_thumbprint TEXT)"
      ],
      [
        "table",
        "auth_sessions",
        "CREATE TABLE auth_sessions (\n      session_id TEXT PRIMARY KEY,\n      subject TEXT NOT NULL,\n      scopes TEXT NOT NULL,\n      method TEXT NOT NULL,\n      client_label TEXT,\n      client_ip_address TEXT,\n      client_user_agent TEXT,\n      client_device_type TEXT NOT NULL DEFAULT 'unknown',\n      client_os TEXT,\n      client_browser TEXT,\n      issued_at TEXT NOT NULL,\n      expires_at TEXT NOT NULL,\n      last_connected_at TEXT,\n      revoked_at TEXT\n    , client_surface TEXT, client_app_version TEXT)"
      ],
      [
        "table",
        "effect_sql_migrations",
        "CREATE TABLE \"effect_sql_migrations\" (\n  migration_id integer PRIMARY KEY NOT NULL,\n  created_at datetime NOT NULL DEFAULT current_timestamp,\n  name VARCHAR(255) NOT NULL\n)"
      ],
      [
        "table",
        "mcp_app_model_context",
        "CREATE TABLE mcp_app_model_context (\n      thread_id TEXT NOT NULL,\n      item_id TEXT NOT NULL,\n      server TEXT NOT NULL,\n      tool TEXT NOT NULL,\n      text TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      PRIMARY KEY (thread_id, item_id)\n    )"
      ],
      [
        "table",
        "orchestration_command_receipts",
        "CREATE TABLE orchestration_command_receipts (\n      command_id TEXT PRIMARY KEY,\n      aggregate_kind TEXT NOT NULL,\n      aggregate_id TEXT NOT NULL,\n      accepted_at TEXT NOT NULL,\n      result_sequence INTEGER NOT NULL,\n      status TEXT NOT NULL,\n      error TEXT\n    , command_type TEXT NOT NULL DEFAULT 'legacy')"
      ],
      [
        "table",
        "orchestration_events",
        "CREATE TABLE orchestration_events (\n      sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n      event_id TEXT NOT NULL UNIQUE,\n      aggregate_kind TEXT NOT NULL,\n      stream_id TEXT NOT NULL,\n      stream_version INTEGER NOT NULL,\n      event_type TEXT NOT NULL,\n      occurred_at TEXT NOT NULL,\n      command_id TEXT,\n      causation_event_id TEXT,\n      correlation_id TEXT,\n      actor_kind TEXT NOT NULL,\n      payload_json TEXT NOT NULL,\n      metadata_json TEXT NOT NULL\n    , application_event_version INTEGER NOT NULL DEFAULT 1)"
      ],
      [
        "table",
        "orchestration_v2_command_receipts",
        "CREATE TABLE orchestration_v2_command_receipts (\n      command_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      command_type TEXT NOT NULL,\n      accepted_at TEXT NOT NULL,\n      result_sequence INTEGER NOT NULL,\n      status TEXT NOT NULL,\n      error TEXT\n    )"
      ],
      [
        "table",
        "orchestration_v2_effect_outbox",
        "CREATE TABLE \"orchestration_v2_effect_outbox\" (\n      effect_id TEXT PRIMARY KEY,\n      command_id TEXT NOT NULL,\n      thread_id TEXT NOT NULL,\n      effect_type TEXT NOT NULL,\n      payload_json TEXT NOT NULL,\n      status TEXT NOT NULL CHECK (\n        status IN ('pending', 'running', 'succeeded', 'failed', 'cancelled')\n      ),\n      attempt_count INTEGER NOT NULL DEFAULT 0,\n      available_at TEXT NOT NULL,\n      lease_owner TEXT,\n      lease_expires_at TEXT,\n      created_at TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      completed_at TEXT,\n      last_error TEXT\n    )"
      ],
      [
        "table",
        "orchestration_v2_events",
        "CREATE TABLE orchestration_v2_events (\n      sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n      event_id TEXT NOT NULL UNIQUE,\n      command_id TEXT,\n      thread_id TEXT NOT NULL,\n      run_id TEXT,\n      node_id TEXT,\n      provider TEXT,\n      raw_event_id TEXT,\n      event_type TEXT NOT NULL,\n      occurred_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    , driver TEXT, provider_instance_id TEXT)"
      ],
      [
        "table",
        "orchestration_v2_legacy_imports",
        "CREATE TABLE orchestration_v2_legacy_imports (\n      thread_id TEXT PRIMARY KEY,\n      source_updated_at TEXT NOT NULL,\n      shell_imported_at TEXT NOT NULL,\n      transcript_imported_at TEXT,\n      imported_message_count INTEGER NOT NULL DEFAULT 0,\n      last_error TEXT\n    )"
      ],
      [
        "table",
        "orchestration_v2_message_search",
        "CREATE VIRTUAL TABLE orchestration_v2_message_search USING fts5(\n      text,\n      content = '',\n      contentless_delete = 1,\n      tokenize = 'trigram remove_diacritics 1'\n    )"
      ],
      [
        "table",
        "orchestration_v2_message_search_config",
        "CREATE TABLE 'orchestration_v2_message_search_config'(k PRIMARY KEY, v) WITHOUT ROWID"
      ],
      [
        "table",
        "orchestration_v2_message_search_data",
        "CREATE TABLE 'orchestration_v2_message_search_data'(id INTEGER PRIMARY KEY, block BLOB)"
      ],
      [
        "table",
        "orchestration_v2_message_search_docsize",
        "CREATE TABLE 'orchestration_v2_message_search_docsize'(id INTEGER PRIMARY KEY, sz BLOB, origin INTEGER)"
      ],
      [
        "table",
        "orchestration_v2_message_search_idx",
        "CREATE TABLE 'orchestration_v2_message_search_idx'(segid, term, pgno, PRIMARY KEY(segid, term)) WITHOUT ROWID"
      ],
      [
        "table",
        "orchestration_v2_projection_checkpoint_scopes",
        "CREATE TABLE orchestration_v2_projection_checkpoint_scopes (\n      scope_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      run_id TEXT,\n      node_id TEXT NOT NULL,\n      parent_scope_id TEXT,\n      provider_thread_id TEXT,\n      kind TEXT NOT NULL,\n      ordinal_within_parent INTEGER NOT NULL,\n      advances_app_run_count INTEGER NOT NULL,\n      created_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_checkpoints",
        "CREATE TABLE orchestration_v2_projection_checkpoints (\n      checkpoint_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      scope_id TEXT NOT NULL,\n      run_id TEXT,\n      node_id TEXT NOT NULL,\n      parent_checkpoint_id TEXT,\n      ordinal_within_scope INTEGER NOT NULL,\n      app_run_ordinal INTEGER,\n      status TEXT NOT NULL,\n      captured_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_context_handoffs",
        "CREATE TABLE orchestration_v2_projection_context_handoffs (\n      context_handoff_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      target_run_id TEXT NOT NULL,\n      to_provider_thread_id TEXT NOT NULL,\n      strategy TEXT NOT NULL,\n      status TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_context_transfers",
        "CREATE TABLE orchestration_v2_projection_context_transfers (\n      context_transfer_id TEXT PRIMARY KEY,\n      source_thread_id TEXT NOT NULL,\n      target_thread_id TEXT NOT NULL,\n      target_run_id TEXT,\n      type TEXT NOT NULL,\n      status TEXT NOT NULL,\n      source_provider TEXT,\n      target_provider TEXT,\n      updated_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    , source_provider_instance_id TEXT, target_provider_instance_id TEXT)"
      ],
      [
        "table",
        "orchestration_v2_projection_messages",
        "CREATE TABLE orchestration_v2_projection_messages (\n      message_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      run_id TEXT,\n      node_id TEXT,\n      role TEXT NOT NULL,\n      streaming INTEGER NOT NULL,\n      created_at TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_metadata",
        "CREATE TABLE orchestration_v2_projection_metadata (\n      projection_name TEXT PRIMARY KEY,\n      schema_version INTEGER NOT NULL,\n      last_sequence INTEGER NOT NULL,\n      updated_at TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_nodes",
        "CREATE TABLE orchestration_v2_projection_nodes (\n      node_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      run_id TEXT,\n      parent_node_id TEXT,\n      root_node_id TEXT NOT NULL,\n      kind TEXT NOT NULL,\n      status TEXT NOT NULL,\n      provider_thread_id TEXT,\n      provider_turn_id TEXT,\n      runtime_request_id TEXT,\n      checkpoint_scope_id TEXT,\n      started_at TEXT,\n      completed_at TEXT,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_plans",
        "CREATE TABLE orchestration_v2_projection_plans (\n      plan_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      run_id TEXT,\n      node_id TEXT NOT NULL,\n      kind TEXT NOT NULL,\n      status TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_provider_session_bindings",
        "CREATE TABLE orchestration_v2_projection_provider_session_bindings (\n      provider_session_id TEXT NOT NULL,\n      thread_id TEXT NOT NULL,\n      PRIMARY KEY (provider_session_id, thread_id)\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_provider_sessions",
        "CREATE TABLE orchestration_v2_projection_provider_sessions (\n      provider_session_id TEXT PRIMARY KEY,\n      thread_id TEXT,\n      provider TEXT NOT NULL,\n      status TEXT NOT NULL,\n      model TEXT,\n      updated_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    , driver TEXT, provider_instance_id TEXT)"
      ],
      [
        "table",
        "orchestration_v2_projection_provider_threads",
        "CREATE TABLE orchestration_v2_projection_provider_threads (\n      provider_thread_id TEXT PRIMARY KEY,\n      thread_id TEXT,\n      owner_node_id TEXT,\n      provider TEXT NOT NULL,\n      provider_session_id TEXT,\n      status TEXT NOT NULL,\n      first_run_ordinal INTEGER,\n      last_run_ordinal INTEGER,\n      updated_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    , driver TEXT, provider_instance_id TEXT)"
      ],
      [
        "table",
        "orchestration_v2_projection_provider_turns",
        "CREATE TABLE orchestration_v2_projection_provider_turns (\n      provider_turn_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      provider_thread_id TEXT NOT NULL,\n      node_id TEXT NOT NULL,\n      run_attempt_id TEXT,\n      ordinal INTEGER NOT NULL,\n      status TEXT NOT NULL,\n      started_at TEXT,\n      completed_at TEXT,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_run_attempts",
        "CREATE TABLE orchestration_v2_projection_run_attempts (\n      attempt_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      run_id TEXT NOT NULL,\n      attempt_ordinal INTEGER NOT NULL,\n      root_node_id TEXT NOT NULL,\n      provider TEXT NOT NULL,\n      provider_thread_id TEXT NOT NULL,\n      provider_turn_id TEXT,\n      status TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    , provider_instance_id TEXT)"
      ],
      [
        "table",
        "orchestration_v2_projection_runs",
        "CREATE TABLE orchestration_v2_projection_runs (\n      run_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      ordinal INTEGER NOT NULL,\n      provider TEXT NOT NULL,\n      provider_thread_id TEXT,\n      status TEXT NOT NULL,\n      requested_at TEXT NOT NULL,\n      completed_at TEXT,\n      payload_json TEXT NOT NULL\n    , provider_instance_id TEXT)"
      ],
      [
        "table",
        "orchestration_v2_projection_runtime_requests",
        "CREATE TABLE orchestration_v2_projection_runtime_requests (\n      runtime_request_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      node_id TEXT NOT NULL,\n      provider_turn_id TEXT,\n      kind TEXT NOT NULL,\n      status TEXT NOT NULL,\n      created_at TEXT NOT NULL,\n      resolved_at TEXT,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_projection_subagents",
        "CREATE TABLE orchestration_v2_projection_subagents (\n      subagent_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      run_id TEXT,\n      parent_node_id TEXT NOT NULL,\n      provider TEXT NOT NULL,\n      provider_thread_id TEXT,\n      child_thread_id TEXT,\n      origin TEXT NOT NULL,\n      status TEXT NOT NULL,\n      started_at TEXT,\n      completed_at TEXT,\n      updated_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    , driver TEXT, provider_instance_id TEXT, completion_delivery_state TEXT)"
      ],
      [
        "table",
        "orchestration_v2_projection_threads",
        "CREATE TABLE orchestration_v2_projection_threads (\n      thread_id TEXT PRIMARY KEY,\n      project_id TEXT NOT NULL,\n      title TEXT NOT NULL,\n      default_provider TEXT NOT NULL,\n      runtime_mode TEXT NOT NULL,\n      interaction_mode TEXT NOT NULL,\n      active_provider_thread_id TEXT,\n      created_at TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      archived_at TEXT,\n      deleted_at TEXT,\n      payload_json TEXT NOT NULL\n    , provider_instance_id TEXT)"
      ],
      [
        "table",
        "orchestration_v2_projection_turn_items",
        "CREATE TABLE orchestration_v2_projection_turn_items (\n      turn_item_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      run_id TEXT,\n      node_id TEXT,\n      provider_thread_id TEXT,\n      provider_turn_id TEXT,\n      parent_item_id TEXT,\n      ordinal INTEGER NOT NULL,\n      type TEXT NOT NULL,\n      status TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      payload_json TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_thread_launch_workflows",
        "CREATE TABLE orchestration_v2_thread_launch_workflows (\n      command_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      project_id TEXT NOT NULL,\n      status TEXT NOT NULL,\n      title TEXT NOT NULL,\n      worktree_path TEXT,\n      branch TEXT,\n      setup_committed INTEGER NOT NULL DEFAULT 0,\n      thread_committed INTEGER NOT NULL DEFAULT 0,\n      message_committed INTEGER NOT NULL DEFAULT 0,\n      last_error TEXT,\n      created_at TEXT NOT NULL,\n      updated_at TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "orchestration_v2_turn_item_positions",
        "CREATE TABLE orchestration_v2_turn_item_positions (\n      thread_id TEXT NOT NULL,\n      turn_item_id TEXT NOT NULL,\n      ordinal INTEGER NOT NULL,\n      PRIMARY KEY (thread_id, turn_item_id),\n      UNIQUE (thread_id, ordinal)\n    )"
      ],
      [
        "table",
        "peer_environment_links",
        "CREATE TABLE peer_environment_links (\n      environment_id TEXT PRIMARY KEY,\n      secret_name TEXT NOT NULL,\n      label TEXT NOT NULL,\n      urls_json TEXT NOT NULL,\n      access TEXT NOT NULL,\n      linked_at TEXT NOT NULL,\n      expires_at TEXT NOT NULL,\n      last_reached_at TEXT,\n      last_error TEXT\n    , fenced INTEGER NOT NULL DEFAULT 0)"
      ],
      [
        "table",
        "projection_projects",
        "CREATE TABLE projection_projects (\n      project_id TEXT PRIMARY KEY,\n      title TEXT NOT NULL,\n      workspace_root TEXT NOT NULL,\n      scripts_json TEXT NOT NULL,\n      created_at TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      deleted_at TEXT\n    , default_model_selection_json TEXT, default_thread_env_mode TEXT, favicon_path TEXT, auto_pull INTEGER NOT NULL DEFAULT 0, project_icon_json TEXT, pinned_at TEXT, archived_at TEXT)"
      ],
      [
        "table",
        "projection_thread_messages",
        "CREATE TABLE projection_thread_messages (\n      message_id TEXT PRIMARY KEY,\n      thread_id TEXT NOT NULL,\n      turn_id TEXT,\n      role TEXT NOT NULL,\n      text TEXT NOT NULL,\n      is_streaming INTEGER NOT NULL,\n      created_at TEXT NOT NULL,\n      updated_at TEXT NOT NULL\n    , attachments_json TEXT, context_json TEXT)"
      ],
      [
        "table",
        "projection_thread_pull_requests",
        "CREATE TABLE projection_thread_pull_requests (\n      thread_id TEXT NOT NULL,\n      host TEXT NOT NULL,\n      repository TEXT NOT NULL,\n      number INTEGER NOT NULL,\n      url TEXT NOT NULL,\n      source TEXT NOT NULL,\n      linked_at TEXT NOT NULL,\n      snapshot_json TEXT,\n      stack_json TEXT,\n      PRIMARY KEY (thread_id, host, repository, number)\n    )"
      ],
      [
        "table",
        "projection_thread_sessions",
        "CREATE TABLE projection_thread_sessions (\n      thread_id TEXT PRIMARY KEY,\n      status TEXT NOT NULL,\n      provider_name TEXT,\n      provider_session_id TEXT,\n      provider_thread_id TEXT,\n      active_turn_id TEXT,\n      last_error TEXT,\n      updated_at TEXT NOT NULL\n    , runtime_mode TEXT NOT NULL DEFAULT 'full-access', provider_instance_id TEXT)"
      ],
      [
        "table",
        "projection_threads",
        "CREATE TABLE projection_threads (\n      thread_id TEXT PRIMARY KEY,\n      project_id TEXT NOT NULL,\n      title TEXT NOT NULL,\n      branch TEXT,\n      worktree_path TEXT,\n      latest_turn_id TEXT,\n      created_at TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      deleted_at TEXT\n    , runtime_mode TEXT NOT NULL DEFAULT 'full-access', interaction_mode TEXT NOT NULL DEFAULT 'default', model_selection_json TEXT, archived_at TEXT, latest_user_message_at TEXT, pending_approval_count INTEGER NOT NULL DEFAULT 0, pending_user_input_count INTEGER NOT NULL DEFAULT 0, has_actionable_proposed_plan INTEGER NOT NULL DEFAULT 0, settled_override TEXT, settled_at TEXT, snoozed_until TEXT, snoozed_at TEXT, title_regeneration_request_id TEXT, title_regeneration_started_at TEXT, pinned_at TEXT, pin_order_key TEXT, linked_pull_request_json TEXT, unsettled_at TEXT, branch_pull_request_json TEXT, active_order_key TEXT, title_state_json TEXT, auto_settle_disabled_at TEXT)"
      ],
      [
        "table",
        "provider_session_runtime",
        "CREATE TABLE provider_session_runtime (\n      thread_id TEXT PRIMARY KEY,\n      provider_name TEXT NOT NULL,\n      adapter_key TEXT NOT NULL,\n      runtime_mode TEXT NOT NULL DEFAULT 'full-access',\n      status TEXT NOT NULL,\n      last_seen_at TEXT NOT NULL,\n      resume_cursor_json TEXT,\n      runtime_payload_json TEXT\n    , provider_instance_id TEXT)"
      ],
      [
        "table",
        "pull_request_files_viewed",
        "CREATE TABLE pull_request_files_viewed (\n      provider TEXT NOT NULL,\n      host TEXT NOT NULL,\n      repository TEXT NOT NULL,\n      number INTEGER NOT NULL,\n      viewer TEXT NOT NULL,\n      path TEXT NOT NULL,\n      revision TEXT,\n      viewed_at TEXT NOT NULL,\n      PRIMARY KEY (provider, host, repository, number, viewer, path)\n    ) WITHOUT ROWID\n  "
      ],
      [
        "table",
        "pull_request_review_guides",
        "CREATE TABLE pull_request_review_guides (\n      host TEXT NOT NULL,\n      repository TEXT NOT NULL,\n      number INTEGER NOT NULL,\n      guide_json TEXT NOT NULL,\n      PRIMARY KEY (host, repository, number)\n    ) WITHOUT ROWID\n  "
      ],
      [
        "table",
        "scheduled_task_webhook_deliveries",
        "CREATE TABLE scheduled_task_webhook_deliveries (\n      delivery_id TEXT PRIMARY KEY,\n      task_id TEXT NOT NULL,\n      received_at TEXT NOT NULL,\n      method TEXT NOT NULL,\n      query TEXT NOT NULL,\n      headers_json TEXT NOT NULL,\n      body TEXT NOT NULL,\n      body_bytes INTEGER NOT NULL,\n      body_truncated INTEGER NOT NULL,\n      outcome TEXT NOT NULL,\n      signature_verified INTEGER NOT NULL,\n      missing_fields_json TEXT NOT NULL,\n      rendered_prompt TEXT,\n      error TEXT\n    )"
      ],
      [
        "table",
        "scheduled_task_webhook_pending",
        "CREATE TABLE scheduled_task_webhook_pending (\n    delivery_id TEXT PRIMARY KEY,\n    task_id TEXT NOT NULL REFERENCES scheduled_tasks(task_id) ON DELETE CASCADE,\n    coalesce_key TEXT NOT NULL,\n    due_at INTEGER NOT NULL,\n    state TEXT NOT NULL DEFAULT 'pending',\n    task_json TEXT NOT NULL,\n    request_json TEXT NOT NULL,\n    delivery_ids_json TEXT NOT NULL\n  )"
      ],
      [
        "table",
        "scheduled_task_webhook_relay_deliveries",
        "CREATE TABLE scheduled_task_webhook_relay_deliveries (\n      relay_delivery_id TEXT PRIMARY KEY,\n      task_id TEXT NOT NULL,\n      seen_at TEXT NOT NULL\n    )"
      ],
      [
        "table",
        "scheduled_task_webhook_replay_keys",
        "CREATE TABLE scheduled_task_webhook_replay_keys (\n    task_id TEXT NOT NULL REFERENCES scheduled_tasks(task_id) ON DELETE CASCADE,\n    replay_key TEXT NOT NULL,\n    delivery_id TEXT NOT NULL,\n    expires_at INTEGER NOT NULL,\n    PRIMARY KEY (task_id, replay_key)\n  )"
      ],
      [
        "table",
        "scheduled_tasks",
        "CREATE TABLE scheduled_tasks (\n      task_id TEXT PRIMARY KEY,\n      title TEXT NOT NULL,\n      prompt TEXT NOT NULL,\n      enabled INTEGER NOT NULL,\n      schedule_json TEXT NOT NULL,\n      project_id TEXT NOT NULL,\n      thread_id TEXT,\n      workspace_strategy_json TEXT NOT NULL,\n      model_selection_json TEXT NOT NULL,\n      runtime_mode TEXT NOT NULL,\n      interaction_mode TEXT NOT NULL,\n      created_by TEXT NOT NULL,\n      creation_source TEXT NOT NULL,\n      created_at TEXT NOT NULL,\n      updated_at TEXT NOT NULL,\n      next_run_at TEXT,\n      last_run_at TEXT,\n      last_run_status TEXT NOT NULL,\n      last_run_error TEXT,\n      run_count INTEGER NOT NULL\n    , webhook_token TEXT, webhook_secret TEXT, last_run_webhook_delivery_id TEXT, thread_mode TEXT NOT NULL DEFAULT 'new_thread')"
      ],
      [
        "trigger",
        "orchestration_v2_message_search_delete",
        "CREATE TRIGGER orchestration_v2_message_search_delete\n      AFTER DELETE ON orchestration_v2_projection_messages\n      WHEN old.streaming = 0\n      BEGIN\n        DELETE FROM orchestration_v2_message_search WHERE rowid = old.rowid;\n      END"
      ],
      [
        "trigger",
        "orchestration_v2_message_search_insert",
        "CREATE TRIGGER orchestration_v2_message_search_insert\n      AFTER INSERT ON orchestration_v2_projection_messages\n      WHEN \n  \n  new.streaming = 0\n  AND (\n    new.role = 'assistant'\n    OR (\n      new.role = 'user'\n      AND COALESCE(json_extract(new.payload_json, '$.createdBy'), 'user') = 'user'\n    )\n  )\n  AND NOT EXISTS (\n    SELECT 1 FROM orchestration_v2_projection_threads AS subagent_threads\n    WHERE subagent_threads.thread_id = new.thread_id\n      AND json_extract(subagent_threads.payload_json, '$.lineage.relationshipToParent') = 'subagent'\n  )\n\n  AND \n  CASE\n    WHEN substr(json_extract(new.payload_json, '$.text'), 1, 11) = 'Ultrathink:' COLLATE NOCASE\n      THEN ltrim(substr(json_extract(new.payload_json, '$.text'), 12), '\t\n\u000b\f\r \u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff')\n    ELSE json_extract(new.payload_json, '$.text')\n  END COLLATE BINARY <> '[User attached one or more files without additional text. Respond using the conversation context and the attached files.]'\n\n\n      BEGIN\n        INSERT INTO orchestration_v2_message_search (rowid, text)\n        SELECT new.rowid, replace(replace(json_extract(new.payload_json, '$.text'), '\u2019', ''''), '\u2018', '''')\n        WHERE json_extract(new.payload_json, '$.text') IS NOT NULL;\n      END"
      ],
      [
        "trigger",
        "orchestration_v2_message_search_update",
        "CREATE TRIGGER orchestration_v2_message_search_update\n      AFTER UPDATE OF payload_json, streaming, role ON orchestration_v2_projection_messages\n      WHEN (old.streaming = 0 OR new.streaming = 0)\n        AND (\n          old.streaming IS NOT new.streaming\n          OR old.role IS NOT new.role\n          OR json_extract(old.payload_json, '$.text') IS NOT json_extract(new.payload_json, '$.text')\n          OR json_extract(old.payload_json, '$.createdBy')\n            IS NOT json_extract(new.payload_json, '$.createdBy')\n        )\n      BEGIN\n        DELETE FROM orchestration_v2_message_search WHERE rowid = old.rowid AND old.streaming = 0;\n        INSERT INTO orchestration_v2_message_search (rowid, text)\n        SELECT new.rowid, replace(replace(json_extract(new.payload_json, '$.text'), '\u2019', ''''), '\u2018', '''')\n        WHERE \n  \n  new.streaming = 0\n  AND (\n    new.role = 'assistant'\n    OR (\n      new.role = 'user'\n      AND COALESCE(json_extract(new.payload_json, '$.createdBy'), 'user') = 'user'\n    )\n  )\n  AND NOT EXISTS (\n    SELECT 1 FROM orchestration_v2_projection_threads AS subagent_threads\n    WHERE subagent_threads.thread_id = new.thread_id\n      AND json_extract(subagent_threads.payload_json, '$.lineage.relationshipToParent') = 'subagent'\n  )\n\n  AND \n  CASE\n    WHEN substr(json_extract(new.payload_json, '$.text'), 1, 11) = 'Ultrathink:' COLLATE NOCASE\n      THEN ltrim(substr(json_extract(new.payload_json, '$.text'), 12), '\t\n\u000b\f\r \u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff')\n    ELSE json_extract(new.payload_json, '$.text')\n  END COLLATE BINARY <> '[User attached one or more files without additional text. Respond using the conversation context and the attached files.]'\n\n\n          AND json_extract(new.payload_json, '$.text') IS NOT NULL;\n      END"
      ]
    ]
  }
}