[ {"kind": "index","name": "cotton_workspaces_owner_user_id_key","tbl_name": "cotton_workspaces","sql": "CREATE UNIQUE INDEX cotton_workspaces_owner_user_id_key ON cotton_workspaces (owner_user_id)" }, {"kind": "index","name": "idx_cotton_account_usage_samples_account","tbl_name": "cotton_account_usage_samples","sql": "CREATE INDEX idx_cotton_account_usage_samples_account ON cotton_account_usage_samples (workspace_id, account_id, sampled_at DESC)" }, {"kind": "index","name": "idx_cotton_account_usage_samples_author","tbl_name": "cotton_account_usage_samples","sql": "CREATE INDEX idx_cotton_account_usage_samples_author ON cotton_account_usage_samples (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_admissions_author","tbl_name": "cotton_admissions","sql": "CREATE INDEX idx_cotton_admissions_author ON cotton_admissions (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_admissions_person","tbl_name": "cotton_admissions","sql": "CREATE INDEX idx_cotton_admissions_person ON cotton_admissions (workspace_id, person_key)" }, {"kind": "index","name": "idx_cotton_agent_accounts_author","tbl_name": "cotton_agent_accounts","sql": "CREATE INDEX idx_cotton_agent_accounts_author ON cotton_agent_accounts (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_agent_accounts_workspace","tbl_name": "cotton_agent_accounts","sql": "CREATE INDEX idx_cotton_agent_accounts_workspace ON cotton_agent_accounts (workspace_id, seen_at DESC)" }, {"kind": "index","name": "idx_cotton_ai_access_author","tbl_name": "cotton_ai_access","sql": "CREATE INDEX idx_cotton_ai_access_author ON cotton_ai_access (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_ai_budgets_author","tbl_name": "cotton_ai_budgets","sql": "CREATE INDEX idx_cotton_ai_budgets_author ON cotton_ai_budgets (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_ai_budgets_workspace","tbl_name": "cotton_ai_budgets","sql": "CREATE INDEX idx_cotton_ai_budgets_workspace ON cotton_ai_budgets (workspace_id)" }, {"kind": "index","name": "idx_cotton_ai_calls_author","tbl_name": "cotton_ai_calls","sql": "CREATE INDEX idx_cotton_ai_calls_author ON cotton_ai_calls (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_ai_calls_created_at","tbl_name": "cotton_ai_calls","sql": "CREATE INDEX idx_cotton_ai_calls_created_at ON cotton_ai_calls (workspace_id, created_at)" }, {"kind": "index","name": "idx_cotton_ai_calls_workspace","tbl_name": "cotton_ai_calls","sql": "CREATE INDEX idx_cotton_ai_calls_workspace ON cotton_ai_calls (workspace_id)" }, {"kind": "index","name": "idx_cotton_ai_jobs_author","tbl_name": "cotton_ai_jobs","sql": "CREATE INDEX idx_cotton_ai_jobs_author ON cotton_ai_jobs(substr(_hlc,20),_hlc)" }, {"kind": "index","name": "idx_cotton_ai_jobs_subject","tbl_name": "cotton_ai_jobs","sql": "CREATE INDEX idx_cotton_ai_jobs_subject ON cotton_ai_jobs(workspace_id,subject_table,subject_id,state)" }, {"kind": "index","name": "idx_cotton_ai_jobs_waiting","tbl_name": "cotton_ai_jobs","sql": "CREATE INDEX idx_cotton_ai_jobs_waiting ON cotton_ai_jobs(workspace_id,state,level,created_at,id)" }, {"kind": "index","name": "idx_cotton_alarms_author","tbl_name": "cotton_alarms","sql": "CREATE INDEX idx_cotton_alarms_author ON cotton_alarms (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_alarms_workspace","tbl_name": "cotton_alarms","sql": "CREATE INDEX idx_cotton_alarms_workspace ON cotton_alarms (workspace_id)" }, {"kind": "index","name": "idx_cotton_arrivals_author","tbl_name": "cotton_arrivals","sql": "CREATE INDEX idx_cotton_arrivals_author ON cotton_arrivals(substr(_hlc,20),_hlc)" }, {"kind": "index","name": "idx_cotton_arrivals_pending","tbl_name": "cotton_arrivals","sql": "CREATE INDEX idx_cotton_arrivals_pending ON cotton_arrivals(workspace_id,decided_at,seen_by,created_at)" }, {"kind": "index","name": "idx_cotton_arrivals_record","tbl_name": "cotton_arrivals","sql": "CREATE UNIQUE INDEX idx_cotton_arrivals_record ON cotton_arrivals(workspace_id,record_table,record_id)" }, {"kind": "index","name": "idx_cotton_assistant_runs_author","tbl_name": "cotton_assistant_runs","sql": "CREATE INDEX idx_cotton_assistant_runs_author ON cotton_assistant_runs (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_assistant_runs_note","tbl_name": "cotton_assistant_runs","sql": "CREATE INDEX idx_cotton_assistant_runs_note ON cotton_assistant_runs (result_note_id)" }, {"kind": "index","name": "idx_cotton_assistant_runs_source","tbl_name": "cotton_assistant_runs","sql": "CREATE INDEX idx_cotton_assistant_runs_source ON cotton_assistant_runs (source_kind, source_id)" }, {"kind": "index","name": "idx_cotton_assistant_runs_state","tbl_name": "cotton_assistant_runs","sql": "CREATE INDEX idx_cotton_assistant_runs_state ON cotton_assistant_runs (workspace_id, state, queued_at)" }, {"kind": "index","name": "idx_cotton_audiences_audience","tbl_name": "cotton_audiences","sql": "CREATE INDEX idx_cotton_audiences_audience ON cotton_audiences (audience)" }, {"kind": "index","name": "idx_cotton_audiences_author","tbl_name": "cotton_audiences","sql": "CREATE INDEX idx_cotton_audiences_author ON cotton_audiences (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_authors_author","tbl_name": "cotton_authors","sql": "CREATE INDEX idx_cotton_authors_author ON cotton_authors (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_authors_minted","tbl_name": "cotton_authors","sql": "CREATE INDEX idx_cotton_authors_minted ON cotton_authors (workspace_id, minted_at)" }, {"kind": "index","name": "idx_cotton_automation_runs_author","tbl_name": "cotton_automation_runs","sql": "CREATE INDEX idx_cotton_automation_runs_author ON cotton_automation_runs (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_automation_runs_automation","tbl_name": "cotton_automation_runs","sql": "CREATE INDEX idx_cotton_automation_runs_automation ON cotton_automation_runs (workspace_id, automation, started_at)" }, {"kind": "index","name": "idx_cotton_blocked_senders_address","tbl_name": "cotton_blocked_senders","sql": "CREATE INDEX idx_cotton_blocked_senders_address ON cotton_blocked_senders (workspace_id, address)" }, {"kind": "index","name": "idx_cotton_blocked_senders_author","tbl_name": "cotton_blocked_senders","sql": "CREATE INDEX idx_cotton_blocked_senders_author ON cotton_blocked_senders (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_board_definitions_author","tbl_name": "cotton_board_definitions","sql": "CREATE INDEX idx_cotton_board_definitions_author ON cotton_board_definitions (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_call_log_author","tbl_name": "cotton_call_log","sql": "CREATE INDEX idx_cotton_call_log_author ON cotton_call_log (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_call_log_contact","tbl_name": "cotton_call_log","sql": "CREATE INDEX idx_cotton_call_log_contact ON cotton_call_log (contact_id)" }, {"kind": "index","name": "idx_cotton_call_log_person","tbl_name": "cotton_call_log","sql": "CREATE INDEX idx_cotton_call_log_person ON cotton_call_log (person_id)" }, {"kind": "index","name": "idx_cotton_call_log_started","tbl_name": "cotton_call_log","sql": "CREATE INDEX idx_cotton_call_log_started ON cotton_call_log (workspace_id, started_at DESC)" }, {"kind": "index","name": "idx_cotton_changes_author","tbl_name": "cotton_changes","sql": "CREATE INDEX idx_cotton_changes_author ON cotton_changes (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_changes_record","tbl_name": "cotton_changes","sql": "CREATE INDEX idx_cotton_changes_record ON cotton_changes (table_id, record_id, created_at)" }, {"kind": "index","name": "idx_cotton_code_credentials_author","tbl_name": "cotton_code_credentials","sql": "CREATE INDEX idx_cotton_code_credentials_author ON cotton_code_credentials (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_code_credentials_workspace","tbl_name": "cotton_code_credentials","sql": "CREATE INDEX idx_cotton_code_credentials_workspace ON cotton_code_credentials (workspace_id, created_at DESC)" }, {"kind": "index","name": "idx_cotton_collections_author","tbl_name": "cotton_collections","sql": "CREATE INDEX idx_cotton_collections_author ON cotton_collections (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_collections_workspace","tbl_name": "cotton_collections","sql": "CREATE INDEX idx_cotton_collections_workspace ON cotton_collections (workspace_id)" }, {"kind": "index","name": "idx_cotton_comments_author","tbl_name": "cotton_comments","sql": "CREATE INDEX idx_cotton_comments_author ON cotton_comments (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_comments_open","tbl_name": "cotton_comments","sql": "CREATE INDEX idx_cotton_comments_open ON cotton_comments (workspace_id, created_at DESC) WHERE resolved_at IS NULL" }, {"kind": "index","name": "idx_cotton_comments_parent","tbl_name": "cotton_comments","sql": "CREATE INDEX idx_cotton_comments_parent ON cotton_comments (parent_id) WHERE parent_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_comments_record","tbl_name": "cotton_comments","sql": "CREATE INDEX idx_cotton_comments_record ON cotton_comments (record_kind, record_id, created_at)" }, {"kind": "index","name": "idx_cotton_connections_author","tbl_name": "cotton_connections","sql": "CREATE INDEX idx_cotton_connections_author ON cotton_connections (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_database_departures_author","tbl_name": "cotton_database_departures","sql": "CREATE INDEX idx_cotton_database_departures_author ON cotton_database_departures (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_database_departures_database","tbl_name": "cotton_database_departures","sql": "CREATE INDEX idx_cotton_database_departures_database ON cotton_database_departures (workspace_id, database_id)" }, {"kind": "index","name": "idx_cotton_databases_author","tbl_name": "cotton_databases","sql": "CREATE INDEX idx_cotton_databases_author ON cotton_databases (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_decisions_author","tbl_name": "cotton_decisions","sql": "CREATE INDEX idx_cotton_decisions_author ON cotton_decisions (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_dev_jobs_author","tbl_name": "cotton_dev_jobs","sql": "CREATE INDEX idx_cotton_dev_jobs_author ON cotton_dev_jobs (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_dev_jobs_queue","tbl_name": "cotton_dev_jobs","sql": "CREATE INDEX idx_cotton_dev_jobs_queue ON cotton_dev_jobs (workspace_id, device_id, state, created_at)" }, {"kind": "index","name": "idx_cotton_device_keep_author","tbl_name": "cotton_device_keep","sql": "CREATE INDEX idx_cotton_device_keep_author ON cotton_device_keep (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_device_relay_keys_author","tbl_name": "cotton_device_relay_keys","sql": "CREATE INDEX idx_cotton_device_relay_keys_author ON cotton_device_relay_keys (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_device_relay_keys_device","tbl_name": "cotton_device_relay_keys","sql": "CREATE INDEX idx_cotton_device_relay_keys_device ON cotton_device_relay_keys (device_id, epoch, id)" }, {"kind": "index","name": "idx_cotton_device_samples_author","tbl_name": "cotton_device_samples","sql": "CREATE INDEX idx_cotton_device_samples_author ON cotton_device_samples (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_device_samples_device","tbl_name": "cotton_device_samples","sql": "CREATE INDEX idx_cotton_device_samples_device ON cotton_device_samples (workspace_id, device_id, sampled_at DESC)" }, {"kind": "index","name": "idx_cotton_device_statements_author","tbl_name": "cotton_device_statements","sql": "CREATE INDEX idx_cotton_device_statements_author ON cotton_device_statements (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_device_statements_device","tbl_name": "cotton_device_statements","sql": "CREATE INDEX idx_cotton_device_statements_device ON cotton_device_statements (workspace_id, device_key)" }, {"kind": "index","name": "idx_cotton_device_statements_person","tbl_name": "cotton_device_statements","sql": "CREATE INDEX idx_cotton_device_statements_person ON cotton_device_statements (workspace_id, person_key)" }, {"kind": "index","name": "idx_cotton_devices_author","tbl_name": "cotton_devices","sql": "CREATE INDEX idx_cotton_devices_author ON cotton_devices (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_devices_device","tbl_name": "cotton_devices","sql": "CREATE INDEX idx_cotton_devices_device ON cotton_devices (device_id)" }, {"kind": "index","name": "idx_cotton_devices_workspace","tbl_name": "cotton_devices","sql": "CREATE INDEX idx_cotton_devices_workspace ON cotton_devices (workspace_id, revoked_at)" }, {"kind": "index","name": "idx_cotton_dictations_author","tbl_name": "cotton_dictations","sql": "CREATE INDEX idx_cotton_dictations_author ON cotton_dictations (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_dictations_workspace_spoken","tbl_name": "cotton_dictations","sql": "CREATE INDEX idx_cotton_dictations_workspace_spoken ON cotton_dictations (workspace_id, spoken_at DESC)" }, {"kind": "index","name": "idx_cotton_document_pages_author","tbl_name": "cotton_document_pages","sql": "CREATE INDEX idx_cotton_document_pages_author ON cotton_document_pages (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_document_pages_workspace","tbl_name": "cotton_document_pages","sql": "CREATE INDEX idx_cotton_document_pages_workspace ON cotton_document_pages (workspace_id)" }, {"kind": "index","name": "idx_cotton_documents_author","tbl_name": "cotton_documents","sql": "CREATE INDEX idx_cotton_documents_author ON cotton_documents (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_documents_origin","tbl_name": "cotton_documents","sql": "CREATE INDEX idx_cotton_documents_origin ON cotton_documents (origin_handle) WHERE origin_handle IS NOT NULL" }, {"kind": "index","name": "idx_cotton_documents_pipeline","tbl_name": "cotton_documents","sql": "CREATE INDEX idx_cotton_documents_pipeline ON cotton_documents (status, status_changed_at) WHERE status IN ('processing', 'summarizing')" }, {"kind": "index","name": "idx_cotton_documents_type","tbl_name": "cotton_documents","sql": "CREATE INDEX idx_cotton_documents_type ON cotton_documents (workspace_id, doc_type)" }, {"kind": "index","name": "idx_cotton_documents_workspace_date","tbl_name": "cotton_documents","sql": "CREATE INDEX idx_cotton_documents_workspace_date ON cotton_documents (workspace_id, document_date DESC, created_at DESC)" }, {"kind": "index","name": "idx_cotton_email_participants_author","tbl_name": "cotton_email_participants","sql": "CREATE INDEX idx_cotton_email_participants_author ON cotton_email_participants (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_email_participants_email","tbl_name": "cotton_email_participants","sql": "CREATE INDEX idx_cotton_email_participants_email ON cotton_email_participants (workspace_id, email)" }, {"kind": "index","name": "idx_cotton_email_participants_thread","tbl_name": "cotton_email_participants","sql": "CREATE INDEX idx_cotton_email_participants_thread ON cotton_email_participants (thread_id)" }, {"kind": "index","name": "idx_cotton_email_senders_author","tbl_name": "cotton_email_senders","sql": "CREATE INDEX idx_cotton_email_senders_author ON cotton_email_senders (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_email_threads_author","tbl_name": "cotton_email_threads","sql": "CREATE INDEX idx_cotton_email_threads_author ON cotton_email_threads (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_email_threads_merchant","tbl_name": "cotton_email_threads","sql": "CREATE INDEX idx_cotton_email_threads_merchant ON cotton_email_threads (workspace_id, id, merchant, trashed_at) WHERE merchant IS NOT NULL AND trashed_at IS NULL" }, {"kind": "index","name": "idx_cotton_email_threads_record_kind","tbl_name": "cotton_email_threads","sql": "CREATE INDEX idx_cotton_email_threads_record_kind ON cotton_email_threads (workspace_id, record_kind, last_at DESC) WHERE record_kind IS NOT NULL" }, {"kind": "index","name": "idx_cotton_email_threads_sender","tbl_name": "cotton_email_threads","sql": "CREATE INDEX idx_cotton_email_threads_sender ON cotton_email_threads (workspace_id, sender_address) WHERE sender_address IS NOT NULL" }, {"kind": "index","name": "idx_cotton_email_threads_sender_kind","tbl_name": "cotton_email_threads","sql": "CREATE INDEX idx_cotton_email_threads_sender_kind ON cotton_email_threads (workspace_id, sender_kind, last_at DESC)" }, {"kind": "index","name": "idx_cotton_email_threads_workspace_recent","tbl_name": "cotton_email_threads","sql": "CREATE INDEX idx_cotton_email_threads_workspace_recent ON cotton_email_threads (workspace_id, last_at DESC)" }, {"kind": "index","name": "idx_cotton_emails_account","tbl_name": "cotton_emails","sql": "CREATE INDEX idx_cotton_emails_account ON cotton_emails (workspace_id, account) WHERE account IS NOT NULL" }, {"kind": "index","name": "idx_cotton_emails_account_live","tbl_name": "cotton_emails","sql": "CREATE INDEX idx_cotton_emails_account_live ON cotton_emails (workspace_id, lower(coalesce(account, gmail_account)), trashed_at)" }, {"kind": "index","name": "idx_cotton_emails_author","tbl_name": "cotton_emails","sql": "CREATE INDEX idx_cotton_emails_author ON cotton_emails (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_emails_binned","tbl_name": "cotton_emails","sql": "CREATE INDEX idx_cotton_emails_binned ON cotton_emails (workspace_id,trashed_at) WHERE trashed_at IS NOT NULL" }, {"kind": "index","name": "idx_cotton_emails_from","tbl_name": "cotton_emails","sql": "CREATE INDEX idx_cotton_emails_from ON cotton_emails (workspace_id, from_email)" }, {"kind": "index","name": "idx_cotton_emails_gmail_id","tbl_name": "cotton_emails","sql": "CREATE INDEX idx_cotton_emails_gmail_id ON cotton_emails (workspace_id, gmail_id)" }, {"kind": "index","name": "idx_cotton_emails_pending","tbl_name": "cotton_emails","sql": "CREATE INDEX idx_cotton_emails_pending ON cotton_emails (workspace_id, sync_state)\n WHERE sync_state = 'pending'" }, {"kind": "index","name": "idx_cotton_emails_thread_live","tbl_name": "cotton_emails","sql": "CREATE INDEX idx_cotton_emails_thread_live ON cotton_emails (thread_id, trashed_at, in_inbox, starred, unread)" }, {"kind": "index","name": "idx_cotton_emails_thread_sent","tbl_name": "cotton_emails","sql": "CREATE INDEX idx_cotton_emails_thread_sent ON cotton_emails (thread_id, sent_at DESC)" }, {"kind": "index","name": "idx_cotton_emails_workspace","tbl_name": "cotton_emails","sql": "CREATE INDEX idx_cotton_emails_workspace ON cotton_emails (workspace_id)" }, {"kind": "index","name": "idx_cotton_event_attendees_author","tbl_name": "cotton_event_attendees","sql": "CREATE INDEX idx_cotton_event_attendees_author ON cotton_event_attendees (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_event_attendees_event","tbl_name": "cotton_event_attendees","sql": "CREATE INDEX idx_cotton_event_attendees_event ON cotton_event_attendees (event_id)" }, {"kind": "index","name": "idx_cotton_events_author","tbl_name": "cotton_events","sql": "CREATE INDEX idx_cotton_events_author ON cotton_events (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_events_collection","tbl_name": "cotton_events","sql": "CREATE INDEX idx_cotton_events_collection ON cotton_events (collection_id)" }, {"kind": "index","name": "idx_cotton_events_ical_uid","tbl_name": "cotton_events","sql": "CREATE INDEX idx_cotton_events_ical_uid ON cotton_events (ical_uid, original_starts_at) WHERE ical_uid IS NOT NULL" }, {"kind": "index","name": "idx_cotton_events_invites","tbl_name": "cotton_events","sql": "CREATE INDEX idx_cotton_events_invites ON cotton_events (collection_id, starts_at) WHERE my_response = 'needs_action' AND organizer_is_self = 0 AND trashed_at IS NULL" }, {"kind": "index","name": "idx_cotton_events_range","tbl_name": "cotton_events","sql": "CREATE INDEX idx_cotton_events_range ON cotton_events (collection_id, starts_at)" }, {"kind": "index","name": "idx_cotton_events_series","tbl_name": "cotton_events","sql": "CREATE INDEX idx_cotton_events_series ON cotton_events (series_id) WHERE series_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_events_trashed","tbl_name": "cotton_events","sql": "CREATE INDEX idx_cotton_events_trashed ON cotton_events (trashed_at) WHERE trashed_at IS NOT NULL" }, {"kind": "index","name": "idx_cotton_feedback_author","tbl_name": "cotton_feedback","sql": "CREATE INDEX idx_cotton_feedback_author ON cotton_feedback (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_feedback_capture","tbl_name": "cotton_feedback","sql": "CREATE INDEX idx_cotton_feedback_capture ON cotton_feedback (workspace_id, app, created_at) WHERE app IS NOT NULL" }, {"kind": "index","name": "idx_cotton_feedback_open","tbl_name": "cotton_feedback","sql": "CREATE INDEX idx_cotton_feedback_open ON cotton_feedback (workspace_id, created_at DESC) WHERE resolved_at IS NULL" }, {"kind": "index","name": "idx_cotton_feedback_parent","tbl_name": "cotton_feedback","sql": "CREATE INDEX idx_cotton_feedback_parent ON cotton_feedback (parent_id) WHERE parent_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_feedback_person","tbl_name": "cotton_feedback","sql": "CREATE INDEX idx_cotton_feedback_person ON cotton_feedback (person_id, created_at) WHERE person_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_feedback_same_as","tbl_name": "cotton_feedback","sql": "CREATE INDEX idx_cotton_feedback_same_as ON cotton_feedback (same_as) WHERE same_as IS NOT NULL" }, {"kind": "index","name": "idx_cotton_filing_proposals_author","tbl_name": "cotton_filing_proposals","sql": "CREATE INDEX idx_cotton_filing_proposals_author ON cotton_filing_proposals(substr(_hlc,20),_hlc)" }, {"kind": "index","name": "idx_cotton_filing_proposals_open","tbl_name": "cotton_filing_proposals","sql": "CREATE INDEX idx_cotton_filing_proposals_open ON cotton_filing_proposals(workspace_id,status,created_at)" }, {"kind": "index","name": "idx_cotton_goals_author","tbl_name": "cotton_goals","sql": "CREATE INDEX idx_cotton_goals_author ON cotton_goals (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_goals_workspace_status","tbl_name": "cotton_goals","sql": "CREATE INDEX idx_cotton_goals_workspace_status ON cotton_goals (workspace_id, status, sort_order)" }, {"kind": "index","name": "idx_cotton_google_accounts_author","tbl_name": "cotton_google_accounts","sql": "CREATE INDEX idx_cotton_google_accounts_author ON cotton_google_accounts (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_google_accounts_workspace","tbl_name": "cotton_google_accounts","sql": "CREATE INDEX idx_cotton_google_accounts_workspace ON cotton_google_accounts (workspace_id)" }, {"kind": "index","name": "idx_cotton_grant_rotations_author","tbl_name": "cotton_grant_rotations","sql": "CREATE INDEX idx_cotton_grant_rotations_author ON cotton_grant_rotations (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_grant_rotations_grant","tbl_name": "cotton_grant_rotations","sql": "CREATE INDEX idx_cotton_grant_rotations_grant ON cotton_grant_rotations (workspace_id, grant_id, generation)" }, {"kind": "index","name": "idx_cotton_group_members_author","tbl_name": "cotton_group_members","sql": "CREATE INDEX idx_cotton_group_members_author ON cotton_group_members (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_group_members_record","tbl_name": "cotton_group_members","sql": "CREATE INDEX idx_cotton_group_members_record ON cotton_group_members (workspace_id, record_id)" }, {"kind": "index","name": "idx_cotton_groups_author","tbl_name": "cotton_groups","sql": "CREATE INDEX idx_cotton_groups_author ON cotton_groups (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_home_arrangement_author","tbl_name": "cotton_home_arrangement","sql": "CREATE INDEX idx_cotton_home_arrangement_author ON cotton_home_arrangement (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_imports_author","tbl_name": "cotton_imports","sql": "CREATE INDEX idx_cotton_imports_author ON cotton_imports (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_inbox_items_author","tbl_name": "cotton_inbox_items","sql": "CREATE INDEX idx_cotton_inbox_items_author ON cotton_inbox_items (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_inbox_items_said","tbl_name": "cotton_inbox_items","sql": "CREATE INDEX idx_cotton_inbox_items_said ON cotton_inbox_items (said_table, said_record_id) WHERE said_table IS NOT NULL" }, {"kind": "index","name": "idx_cotton_inbox_items_workspace","tbl_name": "cotton_inbox_items","sql": "CREATE INDEX idx_cotton_inbox_items_workspace ON cotton_inbox_items (workspace_id, route_status)" }, {"kind": "index","name": "idx_cotton_invites_author","tbl_name": "cotton_invites","sql": "CREATE INDEX idx_cotton_invites_author ON cotton_invites (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_joined_places_author","tbl_name": "cotton_joined_places","sql": "CREATE INDEX idx_cotton_joined_places_author ON cotton_joined_places (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_links_author","tbl_name": "cotton_links","sql": "CREATE INDEX idx_cotton_links_author ON cotton_links (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_links_from","tbl_name": "cotton_links","sql": "CREATE INDEX idx_cotton_links_from ON cotton_links (from_kind, from_id)" }, {"kind": "index","name": "idx_cotton_links_to","tbl_name": "cotton_links","sql": "CREATE INDEX idx_cotton_links_to ON cotton_links (to_kind, to_id)" }, {"kind": "index","name": "idx_cotton_links_workspace","tbl_name": "cotton_links","sql": "CREATE INDEX idx_cotton_links_workspace ON cotton_links (workspace_id)" }, {"kind": "index","name": "idx_cotton_locations_author","tbl_name": "cotton_locations","sql": "CREATE INDEX idx_cotton_locations_author ON cotton_locations (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_locations_workspace","tbl_name": "cotton_locations","sql": "CREATE INDEX idx_cotton_locations_workspace ON cotton_locations (workspace_id)" }, {"kind": "index","name": "idx_cotton_machine_runners_author","tbl_name": "cotton_machine_runners","sql": "CREATE INDEX idx_cotton_machine_runners_author ON cotton_machine_runners (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_machine_runners_device","tbl_name": "cotton_machine_runners","sql": "CREATE INDEX idx_cotton_machine_runners_device ON cotton_machine_runners (workspace_id, device_id)" }, {"kind": "index","name": "idx_cotton_mcp_audit_author","tbl_name": "cotton_mcp_audit","sql": "CREATE INDEX idx_cotton_mcp_audit_author ON cotton_mcp_audit (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_mcp_audit_token","tbl_name": "cotton_mcp_audit","sql": "CREATE INDEX idx_cotton_mcp_audit_token ON cotton_mcp_audit (token_id, created_at DESC)" }, {"kind": "index","name": "idx_cotton_mcp_audit_workspace","tbl_name": "cotton_mcp_audit","sql": "CREATE INDEX idx_cotton_mcp_audit_workspace ON cotton_mcp_audit (workspace_id, created_at DESC)" }, {"kind": "index","name": "idx_cotton_mcp_tokens_author","tbl_name": "cotton_mcp_tokens","sql": "CREATE INDEX idx_cotton_mcp_tokens_author ON cotton_mcp_tokens (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_mcp_tokens_owner","tbl_name": "cotton_mcp_tokens","sql": "CREATE INDEX idx_cotton_mcp_tokens_owner ON cotton_mcp_tokens (owner_user_id, created_at DESC)" }, {"kind": "index","name": "idx_cotton_media_album_items_author","tbl_name": "cotton_media_album_items","sql": "CREATE INDEX idx_cotton_media_album_items_author ON cotton_media_album_items (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_media_album_items_origin","tbl_name": "cotton_media_album_items","sql": "CREATE INDEX idx_cotton_media_album_items_origin ON cotton_media_album_items (origin_handle) WHERE origin_handle IS NOT NULL" }, {"kind": "index","name": "idx_cotton_media_album_items_record","tbl_name": "cotton_media_album_items","sql": "CREATE INDEX idx_cotton_media_album_items_record ON cotton_media_album_items (workspace_id, record_id)" }, {"kind": "index","name": "idx_cotton_media_albums_author","tbl_name": "cotton_media_albums","sql": "CREATE INDEX idx_cotton_media_albums_author ON cotton_media_albums (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_media_albums_open","tbl_name": "cotton_media_albums","sql": "CREATE INDEX idx_cotton_media_albums_open ON cotton_media_albums (workspace_id, starts_at DESC) WHERE state = 'open'" }, {"kind": "index","name": "idx_cotton_media_albums_origin","tbl_name": "cotton_media_albums","sql": "CREATE INDEX idx_cotton_media_albums_origin ON cotton_media_albums (origin_handle) WHERE origin_handle IS NOT NULL" }, {"kind": "index","name": "idx_cotton_media_albums_time","tbl_name": "cotton_media_albums","sql": "CREATE INDEX idx_cotton_media_albums_time ON cotton_media_albums (workspace_id, starts_at DESC)" }, {"kind": "index","name": "idx_cotton_media_backups_author","tbl_name": "cotton_media_backups","sql": "CREATE INDEX idx_cotton_media_backups_author ON cotton_media_backups (substr(_hlc,20),_hlc)" }, {"kind": "index","name": "idx_cotton_media_duplicates_author","tbl_name": "cotton_media_duplicates","sql": "CREATE INDEX idx_cotton_media_duplicates_author ON cotton_media_duplicates (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_media_duplicates_copy","tbl_name": "cotton_media_duplicates","sql": "CREATE INDEX idx_cotton_media_duplicates_copy ON cotton_media_duplicates (workspace_id, copy_id)" }, {"kind": "index","name": "idx_cotton_media_duplicates_open","tbl_name": "cotton_media_duplicates","sql": "CREATE INDEX idx_cotton_media_duplicates_open ON cotton_media_duplicates (workspace_id, keep_id) WHERE state = 'open'" }, {"kind": "index","name": "idx_cotton_media_erasures_author","tbl_name": "cotton_media_erasures","sql": "CREATE INDEX idx_cotton_media_erasures_author ON cotton_media_erasures (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_media_erasures_key","tbl_name": "cotton_media_erasures","sql": "CREATE INDEX idx_cotton_media_erasures_key ON cotton_media_erasures (key)" }, {"kind": "index","name": "idx_cotton_media_faces_author","tbl_name": "cotton_media_faces","sql": "CREATE INDEX idx_cotton_media_faces_author ON cotton_media_faces (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_media_faces_cluster","tbl_name": "cotton_media_faces","sql": "CREATE INDEX idx_cotton_media_faces_cluster ON cotton_media_faces (workspace_id, cluster_id) WHERE cluster_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_media_faces_person","tbl_name": "cotton_media_faces","sql": "CREATE INDEX idx_cotton_media_faces_person ON cotton_media_faces (workspace_id, person_id) WHERE person_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_media_faces_record","tbl_name": "cotton_media_faces","sql": "CREATE INDEX idx_cotton_media_faces_record ON cotton_media_faces (workspace_id, record_id)" }, {"kind": "index","name": "idx_cotton_media_faces_suggested","tbl_name": "cotton_media_faces","sql": "CREATE INDEX idx_cotton_media_faces_suggested ON cotton_media_faces (workspace_id, suggested_person_id) WHERE suggested_person_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_media_holdings_author","tbl_name": "cotton_media_holdings","sql": "CREATE INDEX idx_cotton_media_holdings_author ON cotton_media_holdings (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_media_holdings_device","tbl_name": "cotton_media_holdings","sql": "CREATE INDEX idx_cotton_media_holdings_device ON cotton_media_holdings (device_id, tier)" }, {"kind": "index","name": "idx_cotton_media_holdings_live","tbl_name": "cotton_media_holdings","sql": "CREATE INDEX idx_cotton_media_holdings_live ON cotton_media_holdings (workspace_id, tier, object_key, device_id, bytes, created_at, dropped_at) WHERE dropped_at IS NULL" }, {"kind": "index","name": "idx_cotton_media_holdings_object","tbl_name": "cotton_media_holdings","sql": "CREATE INDEX idx_cotton_media_holdings_object ON cotton_media_holdings (workspace_id, object_key, dropped_at)" }, {"kind": "index","name": "idx_cotton_media_sightings_author","tbl_name": "cotton_media_sightings","sql": "CREATE INDEX idx_cotton_media_sightings_author ON cotton_media_sightings (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_media_sightings_record","tbl_name": "cotton_media_sightings","sql": "CREATE INDEX idx_cotton_media_sightings_record ON cotton_media_sightings (workspace_id, record_id)" }, {"kind": "index","name": "idx_cotton_media_sightings_source","tbl_name": "cotton_media_sightings","sql": "CREATE INDEX idx_cotton_media_sightings_source ON cotton_media_sightings (workspace_id, source, source_id)" }, {"kind": "index","name": "idx_cotton_media_sightings_thread","tbl_name": "cotton_media_sightings","sql": "CREATE INDEX idx_cotton_media_sightings_thread ON cotton_media_sightings (workspace_id, thread_id) WHERE thread_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_meeting_utterances_author","tbl_name": "cotton_meeting_utterances","sql": "CREATE INDEX idx_cotton_meeting_utterances_author ON cotton_meeting_utterances (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_meeting_utterances_meeting","tbl_name": "cotton_meeting_utterances","sql": "CREATE INDEX idx_cotton_meeting_utterances_meeting ON cotton_meeting_utterances (meeting_id, seq)" }, {"kind": "index","name": "idx_cotton_meetings_author","tbl_name": "cotton_meetings","sql": "CREATE INDEX idx_cotton_meetings_author ON cotton_meetings (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_meetings_event","tbl_name": "cotton_meetings","sql": "CREATE INDEX idx_cotton_meetings_event ON cotton_meetings (event_id) WHERE event_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_meetings_pipeline","tbl_name": "cotton_meetings","sql": "CREATE INDEX idx_cotton_meetings_pipeline ON cotton_meetings (status, status_changed_at) WHERE status IN ('transcribing', 'summarizing')" }, {"kind": "index","name": "idx_cotton_meetings_workspace_started","tbl_name": "cotton_meetings","sql": "CREATE INDEX idx_cotton_meetings_workspace_started ON cotton_meetings (workspace_id, started_at DESC)" }, {"kind": "index","name": "idx_cotton_member_person_claims_admission","tbl_name": "cotton_member_person_claims","sql": "CREATE INDEX idx_cotton_member_person_claims_admission ON cotton_member_person_claims (workspace_id, admission_id, claimed_at, _hlc)" }, {"kind": "index","name": "idx_cotton_memories_author","tbl_name": "cotton_memories","sql": "CREATE INDEX idx_cotton_memories_author ON cotton_memories (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_memories_glance","tbl_name": "cotton_memories","sql": "CREATE INDEX idx_cotton_memories_glance ON cotton_memories (workspace_id,status,visibility,origin_kind,reviewed_at,created_at,id,title)" }, {"kind": "index","name": "idx_cotton_memories_slug","tbl_name": "cotton_memories","sql": "CREATE UNIQUE INDEX idx_cotton_memories_slug ON cotton_memories (workspace_id, slug)" }, {"kind": "index","name": "idx_cotton_memories_source_external","tbl_name": "cotton_memories","sql": "CREATE UNIQUE INDEX idx_cotton_memories_source_external ON cotton_memories (workspace_id, source_external_id) WHERE source_external_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_memories_superseded_by","tbl_name": "cotton_memories","sql": "CREATE INDEX idx_cotton_memories_superseded_by ON cotton_memories (superseded_by) WHERE superseded_by IS NOT NULL" }, {"kind": "index","name": "idx_cotton_memories_unreviewed","tbl_name": "cotton_memories","sql": "CREATE INDEX idx_cotton_memories_unreviewed ON cotton_memories (workspace_id, updated_at DESC) WHERE (status = 'active') AND (reviewed_at IS NULL)" }, {"kind": "index","name": "idx_cotton_memory_projects_author","tbl_name": "cotton_memory_projects","sql": "CREATE INDEX idx_cotton_memory_projects_author ON cotton_memory_projects (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_memory_projects_origin","tbl_name": "cotton_memory_projects","sql": "CREATE INDEX idx_cotton_memory_projects_origin ON cotton_memory_projects (origin_handle) WHERE origin_handle IS NOT NULL" }, {"kind": "index","name": "idx_cotton_money_accounts_author","tbl_name": "cotton_money_accounts","sql": "CREATE INDEX idx_cotton_money_accounts_author ON cotton_money_accounts (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_money_accounts_person","tbl_name": "cotton_money_accounts","sql": "CREATE INDEX idx_cotton_money_accounts_person ON cotton_money_accounts (counterparty_person_id) WHERE counterparty_person_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_money_accounts_workspace","tbl_name": "cotton_money_accounts","sql": "CREATE INDEX idx_cotton_money_accounts_workspace ON cotton_money_accounts (workspace_id)" }, {"kind": "index","name": "idx_cotton_money_evidence_author","tbl_name": "cotton_money_evidence","sql": "CREATE INDEX idx_cotton_money_evidence_author ON cotton_money_evidence (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_money_evidence_ref","tbl_name": "cotton_money_evidence","sql": "CREATE INDEX idx_cotton_money_evidence_ref ON cotton_money_evidence (kind, ref_id)" }, {"kind": "index","name": "idx_cotton_money_evidence_transaction","tbl_name": "cotton_money_evidence","sql": "CREATE INDEX idx_cotton_money_evidence_transaction ON cotton_money_evidence (transaction_id)" }, {"kind": "index","name": "idx_cotton_money_evidence_workspace","tbl_name": "cotton_money_evidence","sql": "CREATE INDEX idx_cotton_money_evidence_workspace ON cotton_money_evidence (workspace_id)" }, {"kind": "index","name": "idx_cotton_money_statement_lines_author","tbl_name": "cotton_money_statement_lines","sql": "CREATE INDEX idx_cotton_money_statement_lines_author ON cotton_money_statement_lines (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_money_statement_lines_fingerprint","tbl_name": "cotton_money_statement_lines","sql": "CREATE INDEX idx_cotton_money_statement_lines_fingerprint ON cotton_money_statement_lines (fingerprint)" }, {"kind": "index","name": "idx_cotton_money_statement_lines_statement","tbl_name": "cotton_money_statement_lines","sql": "CREATE INDEX idx_cotton_money_statement_lines_statement ON cotton_money_statement_lines (statement_id, line_no)" }, {"kind": "index","name": "idx_cotton_money_statement_lines_workspace","tbl_name": "cotton_money_statement_lines","sql": "CREATE INDEX idx_cotton_money_statement_lines_workspace ON cotton_money_statement_lines (workspace_id)" }, {"kind": "index","name": "idx_cotton_money_statements_account","tbl_name": "cotton_money_statements","sql": "CREATE INDEX idx_cotton_money_statements_account ON cotton_money_statements (account_id, period_start) WHERE account_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_money_statements_author","tbl_name": "cotton_money_statements","sql": "CREATE INDEX idx_cotton_money_statements_author ON cotton_money_statements (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_money_statements_pending","tbl_name": "cotton_money_statements","sql": "CREATE INDEX idx_cotton_money_statements_pending ON cotton_money_statements (created_at) WHERE read_status = 'pending'" }, {"kind": "index","name": "idx_cotton_money_statements_workspace","tbl_name": "cotton_money_statements","sql": "CREATE INDEX idx_cotton_money_statements_workspace ON cotton_money_statements (workspace_id, period_start DESC)" }, {"kind": "index","name": "idx_cotton_money_transactions_account","tbl_name": "cotton_money_transactions","sql": "CREATE INDEX idx_cotton_money_transactions_account ON cotton_money_transactions (account_id) WHERE account_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_money_transactions_author","tbl_name": "cotton_money_transactions","sql": "CREATE INDEX idx_cotton_money_transactions_author ON cotton_money_transactions (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_money_transactions_balance","tbl_name": "cotton_money_transactions","sql": "CREATE INDEX idx_cotton_money_transactions_balance ON cotton_money_transactions (workspace_id,account_id,currency,occurred_on,CASE WHEN direction='in' THEN amount_minor ELSE -amount_minor END,direction,amount_minor,status,amount_known,moves_money,trashed_at) WHERE status='actual' AND amount_known=1 AND moves_money=1 AND trashed_at IS NULL" }, {"kind": "index","name": "idx_cotton_money_transactions_due","tbl_name": "cotton_money_transactions","sql": "CREATE INDEX idx_cotton_money_transactions_due ON cotton_money_transactions (due_date) WHERE due_date IS NOT NULL" }, {"kind": "index","name": "idx_cotton_money_transactions_expected","tbl_name": "cotton_money_transactions","sql": "CREATE INDEX idx_cotton_money_transactions_expected ON cotton_money_transactions (workspace_id,occurred_on,id,due_date,currency,direction,amount_minor,trashed_at) WHERE status='expected'" }, {"kind": "index","name": "idx_cotton_money_transactions_glance","tbl_name": "cotton_money_transactions","sql": "CREATE INDEX idx_cotton_money_transactions_glance ON cotton_money_transactions (workspace_id,trashed_at,between_us,status,direction,currency,amount_minor)" }, {"kind": "index","name": "idx_cotton_money_transactions_person","tbl_name": "cotton_money_transactions","sql": "CREATE INDEX idx_cotton_money_transactions_person ON cotton_money_transactions (counterparty_person_id) WHERE counterparty_person_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_money_transactions_settles","tbl_name": "cotton_money_transactions","sql": "CREATE INDEX idx_cotton_money_transactions_settles ON cotton_money_transactions (settles_transaction_id) WHERE settles_transaction_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_money_transactions_workspace","tbl_name": "cotton_money_transactions","sql": "CREATE INDEX idx_cotton_money_transactions_workspace ON cotton_money_transactions (workspace_id)" }, {"kind": "index","name": "idx_cotton_money_transactions_workspace_date","tbl_name": "cotton_money_transactions","sql": "CREATE INDEX idx_cotton_money_transactions_workspace_date ON cotton_money_transactions (workspace_id, occurred_on DESC)" }, {"kind": "index","name": "idx_cotton_moods_at","tbl_name": "cotton_moods","sql": "CREATE INDEX idx_cotton_moods_at ON cotton_moods (workspace_id, at DESC)" }, {"kind": "index","name": "idx_cotton_moods_author","tbl_name": "cotton_moods","sql": "CREATE INDEX idx_cotton_moods_author ON cotton_moods (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_moods_local_day","tbl_name": "cotton_moods","sql": "CREATE INDEX idx_cotton_moods_local_day ON cotton_moods (workspace_id, local_day)" }, {"kind": "index","name": "idx_cotton_msg_contact_handles_author","tbl_name": "cotton_msg_contact_handles","sql": "CREATE INDEX idx_cotton_msg_contact_handles_author ON cotton_msg_contact_handles (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_msg_contact_handles_contact","tbl_name": "cotton_msg_contact_handles","sql": "CREATE INDEX idx_cotton_msg_contact_handles_contact ON cotton_msg_contact_handles (contact_id)" }, {"kind": "index","name": "idx_cotton_msg_contact_handles_workspace","tbl_name": "cotton_msg_contact_handles","sql": "CREATE INDEX idx_cotton_msg_contact_handles_workspace ON cotton_msg_contact_handles (workspace_id)" }, {"kind": "index","name": "idx_cotton_msg_contacts_auth_user","tbl_name": "cotton_msg_contacts","sql": "CREATE INDEX idx_cotton_msg_contacts_auth_user ON cotton_msg_contacts (auth_user_id) WHERE auth_user_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_msg_contacts_author","tbl_name": "cotton_msg_contacts","sql": "CREATE INDEX idx_cotton_msg_contacts_author ON cotton_msg_contacts (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_msg_contacts_workspace","tbl_name": "cotton_msg_contacts","sql": "CREATE INDEX idx_cotton_msg_contacts_workspace ON cotton_msg_contacts (workspace_id)" }, {"kind": "index","name": "idx_cotton_msg_messages_author","tbl_name": "cotton_msg_messages","sql": "CREATE INDEX idx_cotton_msg_messages_author ON cotton_msg_messages (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_msg_messages_channel_external","tbl_name": "cotton_msg_messages","sql": "CREATE INDEX idx_cotton_msg_messages_channel_external ON cotton_msg_messages (workspace_id, channel, external_id) WHERE external_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_msg_messages_outbox","tbl_name": "cotton_msg_messages","sql": "CREATE INDEX idx_cotton_msg_messages_outbox ON cotton_msg_messages (channel, created_at, id) WHERE send_state IN ('queued', 'sending')" }, {"kind": "index","name": "idx_cotton_msg_messages_sender_participant","tbl_name": "cotton_msg_messages","sql": "CREATE INDEX idx_cotton_msg_messages_sender_participant ON cotton_msg_messages (sender_participant_id)" }, {"kind": "index","name": "idx_cotton_msg_messages_source_account","tbl_name": "cotton_msg_messages","sql": "CREATE INDEX idx_cotton_msg_messages_source_account ON cotton_msg_messages (workspace_id, channel, json_extract(meta, '$.source.account')) WHERE deleted_at IS NULL AND hidden_at IS NULL AND json_extract(meta, '$.source.account') IS NOT NULL" }, {"kind": "index","name": "idx_cotton_msg_messages_starred","tbl_name": "cotton_msg_messages","sql": "CREATE INDEX idx_cotton_msg_messages_starred ON cotton_msg_messages (workspace_id, starred_at) WHERE starred_at IS NOT NULL" }, {"kind": "index","name": "idx_cotton_msg_messages_thread_channel","tbl_name": "cotton_msg_messages","sql": "CREATE INDEX idx_cotton_msg_messages_thread_channel ON cotton_msg_messages (thread_id, channel)" }, {"kind": "index","name": "idx_cotton_msg_messages_thread_created","tbl_name": "cotton_msg_messages","sql": "CREATE INDEX idx_cotton_msg_messages_thread_created ON cotton_msg_messages (thread_id, created_at)" }, {"kind": "index","name": "idx_cotton_msg_messages_thread_sent","tbl_name": "cotton_msg_messages","sql": "CREATE INDEX idx_cotton_msg_messages_thread_sent ON cotton_msg_messages (thread_id, sent_at DESC)" }, {"kind": "index","name": "idx_cotton_msg_messages_thread_seq","tbl_name": "cotton_msg_messages","sql": "CREATE INDEX idx_cotton_msg_messages_thread_seq ON cotton_msg_messages (thread_id, seq)" }, {"kind": "index","name": "idx_cotton_msg_messages_unread","tbl_name": "cotton_msg_messages","sql": "CREATE INDEX idx_cotton_msg_messages_unread ON cotton_msg_messages (workspace_id, thread_id) WHERE read_at IS NULL" }, {"kind": "index","name": "idx_cotton_msg_messages_unread_cursor","tbl_name": "cotton_msg_messages","sql": "CREATE INDEX idx_cotton_msg_messages_unread_cursor ON cotton_msg_messages (thread_id, seq, sent_at) WHERE direction = 'in' AND origin = 'live' AND hidden_at IS NULL AND trashed_at IS NULL" }, {"kind": "index","name": "idx_cotton_msg_messages_unresolved_reply","tbl_name": "cotton_msg_messages","sql": "CREATE INDEX idx_cotton_msg_messages_unresolved_reply ON cotton_msg_messages (thread_id, reply_to_external_id) WHERE (reply_to_external_id IS NOT NULL) AND (reply_to_id IS NULL)" }, {"kind": "index","name": "idx_cotton_msg_owner_settings_author","tbl_name": "cotton_msg_owner_settings","sql": "CREATE INDEX idx_cotton_msg_owner_settings_author ON cotton_msg_owner_settings (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_msg_reactions_author","tbl_name": "cotton_msg_reactions","sql": "CREATE INDEX idx_cotton_msg_reactions_author ON cotton_msg_reactions (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_msg_reactions_message","tbl_name": "cotton_msg_reactions","sql": "CREATE INDEX idx_cotton_msg_reactions_message ON cotton_msg_reactions (message_id)" }, {"kind": "index","name": "idx_cotton_msg_reactions_workspace","tbl_name": "cotton_msg_reactions","sql": "CREATE INDEX idx_cotton_msg_reactions_workspace ON cotton_msg_reactions (workspace_id)" }, {"kind": "index","name": "idx_cotton_msg_receipts_author","tbl_name": "cotton_msg_receipts","sql": "CREATE INDEX idx_cotton_msg_receipts_author ON cotton_msg_receipts (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_msg_receipts_thread","tbl_name": "cotton_msg_receipts","sql": "CREATE INDEX idx_cotton_msg_receipts_thread ON cotton_msg_receipts (thread_id)" }, {"kind": "index","name": "idx_cotton_msg_receipts_workspace","tbl_name": "cotton_msg_receipts","sql": "CREATE INDEX idx_cotton_msg_receipts_workspace ON cotton_msg_receipts (workspace_id)" }, {"kind": "index","name": "idx_cotton_msg_thread_filings_author","tbl_name": "cotton_msg_thread_filings","sql": "CREATE INDEX idx_cotton_msg_thread_filings_author ON cotton_msg_thread_filings (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_msg_thread_filings_state","tbl_name": "cotton_msg_thread_filings","sql": "CREATE INDEX idx_cotton_msg_thread_filings_state ON cotton_msg_thread_filings (workspace_id, state)" }, {"kind": "index","name": "idx_cotton_msg_thread_marks_author","tbl_name": "cotton_msg_thread_marks","sql": "CREATE INDEX idx_cotton_msg_thread_marks_author ON cotton_msg_thread_marks (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_msg_thread_participants_author","tbl_name": "cotton_msg_thread_participants","sql": "CREATE INDEX idx_cotton_msg_thread_participants_author ON cotton_msg_thread_participants (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_msg_thread_participants_contact","tbl_name": "cotton_msg_thread_participants","sql": "CREATE INDEX idx_cotton_msg_thread_participants_contact ON cotton_msg_thread_participants (contact_id)" }, {"kind": "index","name": "idx_cotton_msg_thread_participants_thread_contact","tbl_name": "cotton_msg_thread_participants","sql": "CREATE INDEX idx_cotton_msg_thread_participants_thread_contact ON cotton_msg_thread_participants (thread_id, contact_id)" }, {"kind": "index","name": "idx_cotton_msg_thread_participants_thread_label","tbl_name": "cotton_msg_thread_participants","sql": "CREATE INDEX idx_cotton_msg_thread_participants_thread_label ON cotton_msg_thread_participants (thread_id, display_name)" }, {"kind": "index","name": "idx_cotton_msg_thread_participants_workspace","tbl_name": "cotton_msg_thread_participants","sql": "CREATE INDEX idx_cotton_msg_thread_participants_workspace ON cotton_msg_thread_participants (workspace_id)" }, {"kind": "index","name": "idx_cotton_msg_threads_author","tbl_name": "cotton_msg_threads","sql": "CREATE INDEX idx_cotton_msg_threads_author ON cotton_msg_threads (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_msg_threads_contact","tbl_name": "cotton_msg_threads","sql": "CREATE INDEX idx_cotton_msg_threads_contact ON cotton_msg_threads (contact_id)" }, {"kind": "index","name": "idx_cotton_msg_threads_pinned","tbl_name": "cotton_msg_threads","sql": "CREATE INDEX idx_cotton_msg_threads_pinned ON cotton_msg_threads (workspace_id, pinned_at) WHERE pinned_at IS NOT NULL" }, {"kind": "index","name": "idx_cotton_msg_threads_workspace_recent","tbl_name": "cotton_msg_threads","sql": "CREATE INDEX idx_cotton_msg_threads_workspace_recent ON cotton_msg_threads (workspace_id, last_message_at DESC)" }, {"kind": "index","name": "idx_cotton_news_editions_author","tbl_name": "cotton_news_editions","sql": "CREATE INDEX idx_cotton_news_editions_author ON cotton_news_editions (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_news_editions_pipeline","tbl_name": "cotton_news_editions","sql": "CREATE INDEX idx_cotton_news_editions_pipeline ON cotton_news_editions (status, status_changed_at) WHERE status IN ('queued', 'harvesting', 'writing')" }, {"kind": "index","name": "idx_cotton_news_editions_workspace_created","tbl_name": "cotton_news_editions","sql": "CREATE INDEX idx_cotton_news_editions_workspace_created ON cotton_news_editions (workspace_id, created_at DESC)" }, {"kind": "index","name": "idx_cotton_news_seen_author","tbl_name": "cotton_news_seen","sql": "CREATE INDEX idx_cotton_news_seen_author ON cotton_news_seen (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_news_seen_topic","tbl_name": "cotton_news_seen","sql": "CREATE INDEX idx_cotton_news_seen_topic ON cotton_news_seen (workspace_id, topic_id, first_seen_at DESC)" }, {"kind": "index","name": "idx_cotton_news_settings_author","tbl_name": "cotton_news_settings","sql": "CREATE INDEX idx_cotton_news_settings_author ON cotton_news_settings (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_news_stories_author","tbl_name": "cotton_news_stories","sql": "CREATE INDEX idx_cotton_news_stories_author ON cotton_news_stories (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_news_stories_edition_rank","tbl_name": "cotton_news_stories","sql": "CREATE INDEX idx_cotton_news_stories_edition_rank ON cotton_news_stories (edition_id, rank)" }, {"kind": "index","name": "idx_cotton_news_topics_author","tbl_name": "cotton_news_topics","sql": "CREATE INDEX idx_cotton_news_topics_author ON cotton_news_topics (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_news_topics_workspace_active","tbl_name": "cotton_news_topics","sql": "CREATE INDEX idx_cotton_news_topics_workspace_active ON cotton_news_topics (workspace_id, active, sort_order)" }, {"kind": "index","name": "idx_cotton_note_attachments_author","tbl_name": "cotton_note_attachments","sql": "CREATE INDEX idx_cotton_note_attachments_author ON cotton_note_attachments (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_note_attachments_note","tbl_name": "cotton_note_attachments","sql": "CREATE INDEX idx_cotton_note_attachments_note ON cotton_note_attachments (note_id, position)" }, {"kind": "index","name": "idx_cotton_notes_author","tbl_name": "cotton_notes","sql": "CREATE INDEX idx_cotton_notes_author ON cotton_notes (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_notes_home","tbl_name": "cotton_notes","sql": "CREATE INDEX idx_cotton_notes_home ON cotton_notes (workspace_id) WHERE kind = 'note' AND managed_by IS NULL AND archived_at IS NULL AND trashed_at IS NULL" }, {"kind": "index","name": "idx_cotton_notes_managed","tbl_name": "cotton_notes","sql": "CREATE INDEX idx_cotton_notes_managed ON cotton_notes (managed_by) WHERE managed_by IS NOT NULL" }, {"kind": "index","name": "idx_cotton_notes_origin","tbl_name": "cotton_notes","sql": "CREATE INDEX idx_cotton_notes_origin ON cotton_notes (origin_handle) WHERE origin_handle IS NOT NULL" }, {"kind": "index","name": "idx_cotton_notes_workspace","tbl_name": "cotton_notes","sql": "CREATE INDEX idx_cotton_notes_workspace ON cotton_notes (workspace_id)" }, {"kind": "index","name": "idx_cotton_notes_workspace_external","tbl_name": "cotton_notes","sql": "CREATE UNIQUE INDEX idx_cotton_notes_workspace_external ON cotton_notes (workspace_id, external_id) WHERE external_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_oauth_clients_author","tbl_name": "cotton_oauth_clients","sql": "CREATE INDEX idx_cotton_oauth_clients_author ON cotton_oauth_clients (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_oauth_grants_author","tbl_name": "cotton_oauth_grants","sql": "CREATE INDEX idx_cotton_oauth_grants_author ON cotton_oauth_grants (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_oauth_grants_workspace","tbl_name": "cotton_oauth_grants","sql": "CREATE INDEX idx_cotton_oauth_grants_workspace ON cotton_oauth_grants (workspace_id, revoked_at)" }, {"kind": "index","name": "idx_cotton_outages_author","tbl_name": "cotton_outages","sql": "CREATE INDEX idx_cotton_outages_author ON cotton_outages (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_outages_open","tbl_name": "cotton_outages","sql": "CREATE INDEX idx_cotton_outages_open ON cotton_outages (workspace_id, condition) WHERE ended_at IS NULL" }, {"kind": "index","name": "idx_cotton_outages_started","tbl_name": "cotton_outages","sql": "CREATE INDEX idx_cotton_outages_started ON cotton_outages (workspace_id, started_at DESC)" }, {"kind": "index","name": "idx_cotton_pages_author","tbl_name": "cotton_pages","sql": "CREATE INDEX idx_cotton_pages_author ON cotton_pages (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_pages_workspace","tbl_name": "cotton_pages","sql": "CREATE INDEX idx_cotton_pages_workspace ON cotton_pages (workspace_id)" }, {"kind": "index","name": "idx_cotton_people_author","tbl_name": "cotton_people","sql": "CREATE INDEX idx_cotton_people_author ON cotton_people (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_people_city_filled","tbl_name": "cotton_people","sql": "CREATE INDEX idx_cotton_people_city_filled ON cotton_people (workspace_id, city_filled_at) WHERE city_filled_at IS NOT NULL" }, {"kind": "index","name": "idx_cotton_people_workspace","tbl_name": "cotton_people","sql": "CREATE INDEX idx_cotton_people_workspace ON cotton_people (workspace_id)" }, {"kind": "index","name": "idx_cotton_person_handles_author","tbl_name": "cotton_person_handles","sql": "CREATE INDEX idx_cotton_person_handles_author ON cotton_person_handles (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_person_handles_person","tbl_name": "cotton_person_handles","sql": "CREATE INDEX idx_cotton_person_handles_person ON cotton_person_handles (person_id)" }, {"kind": "index","name": "idx_cotton_person_keys_author","tbl_name": "cotton_person_keys","sql": "CREATE INDEX idx_cotton_person_keys_author ON cotton_person_keys (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_person_languages_author","tbl_name": "cotton_person_languages","sql": "CREATE INDEX idx_cotton_person_languages_author ON cotton_person_languages (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_person_languages_person","tbl_name": "cotton_person_languages","sql": "CREATE INDEX idx_cotton_person_languages_person ON cotton_person_languages (person_id)" }, {"kind": "index","name": "idx_cotton_person_notes_author","tbl_name": "cotton_person_notes","sql": "CREATE INDEX idx_cotton_person_notes_author ON cotton_person_notes (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_person_notes_person","tbl_name": "cotton_person_notes","sql": "CREATE INDEX idx_cotton_person_notes_person ON cotton_person_notes (person_id)" }, {"kind": "index","name": "idx_cotton_person_suggestions_author","tbl_name": "cotton_person_suggestions","sql": "CREATE INDEX idx_cotton_person_suggestions_author ON cotton_person_suggestions (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_person_suggestions_candidate","tbl_name": "cotton_person_suggestions","sql": "CREATE INDEX idx_cotton_person_suggestions_candidate ON cotton_person_suggestions (workspace_id, candidate_id)" }, {"kind": "index","name": "idx_cotton_person_suggestions_open","tbl_name": "cotton_person_suggestions","sql": "CREATE INDEX idx_cotton_person_suggestions_open ON cotton_person_suggestions (workspace_id, person_id) WHERE state = 'open'" }, {"kind": "index","name": "idx_cotton_photos_author","tbl_name": "cotton_photos","sql": "CREATE INDEX idx_cotton_photos_author ON cotton_photos (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_photos_favourite","tbl_name": "cotton_photos","sql": "CREATE INDEX idx_cotton_photos_favourite ON cotton_photos (workspace_id, taken_at DESC) WHERE favourite = 1" }, {"kind": "index","name": "idx_cotton_photos_origin","tbl_name": "cotton_photos","sql": "CREATE INDEX idx_cotton_photos_origin ON cotton_photos (origin_handle) WHERE origin_handle IS NOT NULL" }, {"kind": "index","name": "idx_cotton_photos_phash","tbl_name": "cotton_photos","sql": "CREATE INDEX idx_cotton_photos_phash ON cotton_photos (workspace_id, phash) WHERE phash IS NOT NULL" }, {"kind": "index","name": "idx_cotton_photos_place","tbl_name": "cotton_photos","sql": "CREATE INDEX idx_cotton_photos_place ON cotton_photos (workspace_id, place_city)" }, {"kind": "index","name": "idx_cotton_photos_review","tbl_name": "cotton_photos","sql": "CREATE INDEX idx_cotton_photos_review ON cotton_photos (workspace_id, review_at) WHERE review_note IS NOT NULL" }, {"kind": "index","name": "idx_cotton_photos_taken","tbl_name": "cotton_photos","sql": "CREATE INDEX idx_cotton_photos_taken ON cotton_photos (workspace_id, taken_at DESC)" }, {"kind": "index","name": "idx_cotton_photos_undescribed","tbl_name": "cotton_photos","sql": "CREATE INDEX idx_cotton_photos_undescribed ON cotton_photos (workspace_id, taken_at DESC) WHERE summary IS NULL" }, {"kind": "index","name": "idx_cotton_photos_utility","tbl_name": "cotton_photos","sql": "CREATE INDEX idx_cotton_photos_utility ON cotton_photos (workspace_id, taken_at DESC) WHERE is_utility = 1" }, {"kind": "index","name": "idx_cotton_placement_proposals_author","tbl_name": "cotton_placement_proposals","sql": "CREATE INDEX idx_cotton_placement_proposals_author ON cotton_placement_proposals (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_posts_author","tbl_name": "cotton_posts","sql": "CREATE INDEX idx_cotton_posts_author ON cotton_posts (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_posts_posted","tbl_name": "cotton_posts","sql": "CREATE INDEX idx_cotton_posts_posted ON cotton_posts (workspace_id, saved, posted_at)" }, {"kind": "index","name": "idx_cotton_project_links_arranged","tbl_name": "cotton_project_links","sql": "CREATE INDEX idx_cotton_project_links_arranged ON cotton_project_links (workspace_id, project_id, record_kind, pinned DESC, \"position\")" }, {"kind": "index","name": "idx_cotton_project_links_author","tbl_name": "cotton_project_links","sql": "CREATE INDEX idx_cotton_project_links_author ON cotton_project_links (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_project_links_origin","tbl_name": "cotton_project_links","sql": "CREATE INDEX idx_cotton_project_links_origin ON cotton_project_links (origin_handle) WHERE origin_handle IS NOT NULL" }, {"kind": "index","name": "idx_cotton_project_links_record","tbl_name": "cotton_project_links","sql": "CREATE INDEX idx_cotton_project_links_record ON cotton_project_links (record_kind, record_id)" }, {"kind": "index","name": "idx_cotton_project_links_workspace","tbl_name": "cotton_project_links","sql": "CREATE INDEX idx_cotton_project_links_workspace ON cotton_project_links (workspace_id)" }, {"kind": "index","name": "idx_cotton_prompts_author","tbl_name": "cotton_prompts","sql": "CREATE INDEX idx_cotton_prompts_author ON cotton_prompts (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_prompts_session","tbl_name": "cotton_prompts","sql": "CREATE INDEX idx_cotton_prompts_session ON cotton_prompts (workspace_id, session_id, seq)" }, {"kind": "index","name": "idx_cotton_prompts_workspace","tbl_name": "cotton_prompts","sql": "CREATE INDEX idx_cotton_prompts_workspace ON cotton_prompts (workspace_id)" }, {"kind": "index","name": "idx_cotton_push_acks_author","tbl_name": "cotton_push_acks","sql": "CREATE INDEX idx_cotton_push_acks_author ON cotton_push_acks (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_push_acks_push","tbl_name": "cotton_push_acks","sql": "CREATE INDEX idx_cotton_push_acks_push ON cotton_push_acks (push_id)" }, {"kind": "index","name": "idx_cotton_records_author","tbl_name": "cotton_records","sql": "CREATE INDEX idx_cotton_records_author ON cotton_records (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_records_table","tbl_name": "cotton_records","sql": "CREATE INDEX idx_cotton_records_table ON cotton_records (table_id, project_id, updated_at)" }, {"kind": "index","name": "idx_cotton_repo_bundles_author","tbl_name": "cotton_repo_bundles","sql": "CREATE INDEX idx_cotton_repo_bundles_author ON cotton_repo_bundles (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_repo_bundles_repo","tbl_name": "cotton_repo_bundles","sql": "CREATE INDEX idx_cotton_repo_bundles_repo ON cotton_repo_bundles (workspace_id, repo_id, created_at)" }, {"kind": "index","name": "idx_cotton_repo_clones_author","tbl_name": "cotton_repo_clones","sql": "CREATE INDEX idx_cotton_repo_clones_author ON cotton_repo_clones (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_repo_clones_repo","tbl_name": "cotton_repo_clones","sql": "CREATE INDEX idx_cotton_repo_clones_repo ON cotton_repo_clones (workspace_id, repo_id, state)" }, {"kind": "index","name": "idx_cotton_repo_comments_author","tbl_name": "cotton_repo_comments","sql": "CREATE INDEX idx_cotton_repo_comments_author ON cotton_repo_comments (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_repo_comments_target","tbl_name": "cotton_repo_comments","sql": "CREATE INDEX idx_cotton_repo_comments_target ON cotton_repo_comments (workspace_id, repo_id, target_kind, target_number, remote_created_at)" }, {"kind": "index","name": "idx_cotton_repo_commits_author","tbl_name": "cotton_repo_commits","sql": "CREATE INDEX idx_cotton_repo_commits_author ON cotton_repo_commits (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_repo_commits_repo","tbl_name": "cotton_repo_commits","sql": "CREATE INDEX idx_cotton_repo_commits_repo ON cotton_repo_commits (workspace_id, repo_id, authored_at DESC)" }, {"kind": "index","name": "idx_cotton_repo_issues_author","tbl_name": "cotton_repo_issues","sql": "CREATE INDEX idx_cotton_repo_issues_author ON cotton_repo_issues (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_repo_issues_repo","tbl_name": "cotton_repo_issues","sql": "CREATE INDEX idx_cotton_repo_issues_repo ON cotton_repo_issues (workspace_id, repo_id, state, remote_updated_at DESC)" }, {"kind": "index","name": "idx_cotton_repo_jobs_author","tbl_name": "cotton_repo_jobs","sql": "CREATE INDEX idx_cotton_repo_jobs_author ON cotton_repo_jobs (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_repo_jobs_queue","tbl_name": "cotton_repo_jobs","sql": "CREATE INDEX idx_cotton_repo_jobs_queue ON cotton_repo_jobs (workspace_id, status, created_at)" }, {"kind": "index","name": "idx_cotton_repo_jobs_run","tbl_name": "cotton_repo_jobs","sql": "CREATE INDEX idx_cotton_repo_jobs_run ON cotton_repo_jobs (workspace_id, run_id, index_in_run)" }, {"kind": "index","name": "idx_cotton_repo_jobs_run_id","tbl_name": "cotton_repo_jobs","sql": "CREATE INDEX idx_cotton_repo_jobs_run_id ON cotton_repo_jobs (run_id)" }, {"kind": "index","name": "idx_cotton_repo_labels_author","tbl_name": "cotton_repo_labels","sql": "CREATE INDEX idx_cotton_repo_labels_author ON cotton_repo_labels (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_repo_labels_repo","tbl_name": "cotton_repo_labels","sql": "CREATE INDEX idx_cotton_repo_labels_repo ON cotton_repo_labels (workspace_id, repo_id, name)" }, {"kind": "index","name": "idx_cotton_repo_merge_queue_author","tbl_name": "cotton_repo_merge_queue","sql": "CREATE INDEX idx_cotton_repo_merge_queue_author ON cotton_repo_merge_queue (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_repo_merge_queue_repo","tbl_name": "cotton_repo_merge_queue","sql": "CREATE INDEX idx_cotton_repo_merge_queue_repo ON cotton_repo_merge_queue (workspace_id, repo_id, state, enqueued_at)" }, {"kind": "index","name": "idx_cotton_repo_pulls_author","tbl_name": "cotton_repo_pulls","sql": "CREATE INDEX idx_cotton_repo_pulls_author ON cotton_repo_pulls (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_repo_pulls_repo","tbl_name": "cotton_repo_pulls","sql": "CREATE INDEX idx_cotton_repo_pulls_repo ON cotton_repo_pulls (workspace_id, repo_id, state, remote_updated_at DESC)" }, {"kind": "index","name": "idx_cotton_repo_releases_author","tbl_name": "cotton_repo_releases","sql": "CREATE INDEX idx_cotton_repo_releases_author ON cotton_repo_releases (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_repo_releases_repo","tbl_name": "cotton_repo_releases","sql": "CREATE INDEX idx_cotton_repo_releases_repo ON cotton_repo_releases (workspace_id, repo_id, published_at DESC)" }, {"kind": "index","name": "idx_cotton_repo_rules_author","tbl_name": "cotton_repo_rules","sql": "CREATE INDEX idx_cotton_repo_rules_author ON cotton_repo_rules (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_repo_rules_repo","tbl_name": "cotton_repo_rules","sql": "CREATE INDEX idx_cotton_repo_rules_repo ON cotton_repo_rules (workspace_id, repo_id, branch)" }, {"kind": "index","name": "idx_cotton_repo_runners_author","tbl_name": "cotton_repo_runners","sql": "CREATE INDEX idx_cotton_repo_runners_author ON cotton_repo_runners (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_repo_runners_workspace","tbl_name": "cotton_repo_runners","sql": "CREATE INDEX idx_cotton_repo_runners_workspace ON cotton_repo_runners (workspace_id, last_seen_at DESC)" }, {"kind": "index","name": "idx_cotton_repo_runs_author","tbl_name": "cotton_repo_runs","sql": "CREATE INDEX idx_cotton_repo_runs_author ON cotton_repo_runs (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_repo_runs_repo","tbl_name": "cotton_repo_runs","sql": "CREATE INDEX idx_cotton_repo_runs_repo ON cotton_repo_runs (workspace_id, repo_id, index_in_repo DESC)" }, {"kind": "index","name": "idx_cotton_repo_runs_sha","tbl_name": "cotton_repo_runs","sql": "CREATE INDEX idx_cotton_repo_runs_sha ON cotton_repo_runs (workspace_id, repo_id, sha)" }, {"kind": "index","name": "idx_cotton_repo_vars_author","tbl_name": "cotton_repo_vars","sql": "CREATE INDEX idx_cotton_repo_vars_author ON cotton_repo_vars (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_repo_vars_repo","tbl_name": "cotton_repo_vars","sql": "CREATE INDEX idx_cotton_repo_vars_repo ON cotton_repo_vars (workspace_id, repo_id, name)" }, {"kind": "index","name": "idx_cotton_repos_author","tbl_name": "cotton_repos","sql": "CREATE INDEX idx_cotton_repos_author ON cotton_repos (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_revocations_author","tbl_name": "cotton_revocations","sql": "CREATE INDEX idx_cotton_revocations_author ON cotton_revocations (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_revocations_of_subject","tbl_name": "cotton_revocations","sql": "CREATE INDEX idx_cotton_revocations_of_subject ON cotton_revocations (subject_table, subject_id)" }, {"kind": "index","name": "idx_cotton_revocations_subject","tbl_name": "cotton_revocations","sql": "CREATE INDEX idx_cotton_revocations_subject ON cotton_revocations (workspace_id, subject_table, subject_id)" }, {"kind": "index","name": "idx_cotton_screenplay_characters_author","tbl_name": "cotton_screenplay_characters","sql": "CREATE INDEX idx_cotton_screenplay_characters_author ON cotton_screenplay_characters (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_screenplay_characters_screenplay","tbl_name": "cotton_screenplay_characters","sql": "CREATE INDEX idx_cotton_screenplay_characters_screenplay ON cotton_screenplay_characters (screenplay_id, name)" }, {"kind": "index","name": "idx_cotton_screenplay_documents_author","tbl_name": "cotton_screenplay_documents","sql": "CREATE INDEX idx_cotton_screenplay_documents_author ON cotton_screenplay_documents (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_screenplay_draft_scenes_author","tbl_name": "cotton_screenplay_draft_scenes","sql": "CREATE INDEX idx_cotton_screenplay_draft_scenes_author ON cotton_screenplay_draft_scenes (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_screenplay_draft_scenes_order","tbl_name": "cotton_screenplay_draft_scenes","sql": "CREATE INDEX idx_cotton_screenplay_draft_scenes_order ON cotton_screenplay_draft_scenes (draft_id, \"position\")" }, {"kind": "index","name": "idx_cotton_screenplay_drafts_author","tbl_name": "cotton_screenplay_drafts","sql": "CREATE INDEX idx_cotton_screenplay_drafts_author ON cotton_screenplay_drafts (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_screenplay_drafts_screenplay","tbl_name": "cotton_screenplay_drafts","sql": "CREATE INDEX idx_cotton_screenplay_drafts_screenplay ON cotton_screenplay_drafts (screenplay_id, created_at)" }, {"kind": "index","name": "idx_cotton_screenplay_scenes_author","tbl_name": "cotton_screenplay_scenes","sql": "CREATE INDEX idx_cotton_screenplay_scenes_author ON cotton_screenplay_scenes (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_screenplay_scenes_order","tbl_name": "cotton_screenplay_scenes","sql": "CREATE INDEX idx_cotton_screenplay_scenes_order ON cotton_screenplay_scenes (screenplay_id, \"position\")" }, {"kind": "index","name": "idx_cotton_screenplays_author","tbl_name": "cotton_screenplays","sql": "CREATE INDEX idx_cotton_screenplays_author ON cotton_screenplays (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_screenplays_workspace","tbl_name": "cotton_screenplays","sql": "CREATE INDEX idx_cotton_screenplays_workspace ON cotton_screenplays (workspace_id, archived_at)" }, {"kind": "index","name": "idx_cotton_secret_placements_author","tbl_name": "cotton_secret_placements","sql": "CREATE INDEX idx_cotton_secret_placements_author ON cotton_secret_placements (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_secret_placements_device","tbl_name": "cotton_secret_placements","sql": "CREATE INDEX idx_cotton_secret_placements_device ON cotton_secret_placements (workspace_id, device_id)" }, {"kind": "index","name": "idx_cotton_secret_placements_secret","tbl_name": "cotton_secret_placements","sql": "CREATE INDEX idx_cotton_secret_placements_secret ON cotton_secret_placements (secret_id)" }, {"kind": "index","name": "idx_cotton_secrets_author","tbl_name": "cotton_secrets","sql": "CREATE INDEX idx_cotton_secrets_author ON cotton_secrets (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_secrets_live","tbl_name": "cotton_secrets","sql": "CREATE INDEX idx_cotton_secrets_live ON cotton_secrets (workspace_id, kind, updated_at DESC) WHERE trashed_at IS NULL" }, {"kind": "index","name": "idx_cotton_secrets_service","tbl_name": "cotton_secrets","sql": "CREATE INDEX idx_cotton_secrets_service ON cotton_secrets (workspace_id, service)" }, {"kind": "index","name": "idx_cotton_serving_machine_author","tbl_name": "cotton_serving_machine","sql": "CREATE INDEX idx_cotton_serving_machine_author ON cotton_serving_machine (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_serving_machine_epoch","tbl_name": "cotton_serving_machine","sql": "CREATE INDEX idx_cotton_serving_machine_epoch ON cotton_serving_machine (workspace_id, epoch)" }, {"kind": "index","name": "idx_cotton_session_messages_addressed","tbl_name": "cotton_session_messages","sql": "CREATE INDEX idx_cotton_session_messages_addressed\n ON cotton_session_messages (workspace_id, status, to_kind, to_session_id)" }, {"kind": "index","name": "idx_cotton_session_messages_author","tbl_name": "cotton_session_messages","sql": "CREATE INDEX idx_cotton_session_messages_author ON cotton_session_messages (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_session_messages_project","tbl_name": "cotton_session_messages","sql": "CREATE INDEX idx_cotton_session_messages_project\n ON cotton_session_messages (workspace_id, project_id, status)" }, {"kind": "index","name": "idx_cotton_session_tasks_author","tbl_name": "cotton_session_tasks","sql": "CREATE INDEX idx_cotton_session_tasks_author ON cotton_session_tasks (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_session_tasks_session","tbl_name": "cotton_session_tasks","sql": "CREATE INDEX idx_cotton_session_tasks_session ON cotton_session_tasks (session_id, seq)" }, {"kind": "index","name": "idx_cotton_sessions_author","tbl_name": "cotton_sessions","sql": "CREATE INDEX idx_cotton_sessions_author ON cotton_sessions (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_sessions_conversation","tbl_name": "cotton_sessions","sql": "CREATE UNIQUE INDEX idx_cotton_sessions_conversation ON cotton_sessions (project_id) WHERE kind = 'conversation'" }, {"kind": "index","name": "idx_cotton_sessions_machine","tbl_name": "cotton_sessions","sql": "CREATE INDEX idx_cotton_sessions_machine ON cotton_sessions (workspace_id, machine, last_active_at DESC)" }, {"kind": "index","name": "idx_cotton_sessions_parent","tbl_name": "cotton_sessions","sql": "CREATE INDEX idx_cotton_sessions_parent ON cotton_sessions (parent_session_id, last_active_at DESC) WHERE parent_session_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_sessions_project","tbl_name": "cotton_sessions","sql": "CREATE INDEX idx_cotton_sessions_project ON cotton_sessions (project_id, last_active_at DESC) WHERE project_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_sessions_queue","tbl_name": "cotton_sessions","sql": "CREATE INDEX idx_cotton_sessions_queue ON cotton_sessions (workspace_id, state, device_id)" }, {"kind": "index","name": "idx_cotton_sessions_recent","tbl_name": "cotton_sessions","sql": "CREATE INDEX idx_cotton_sessions_recent ON cotton_sessions (workspace_id, last_active_at DESC)" }, {"kind": "index","name": "idx_cotton_storage_rules_author","tbl_name": "cotton_storage_rules","sql": "CREATE INDEX idx_cotton_storage_rules_author ON cotton_storage_rules (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_stories_author","tbl_name": "cotton_stories","sql": "CREATE INDEX idx_cotton_stories_author ON cotton_stories (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_stories_person","tbl_name": "cotton_stories","sql": "CREATE INDEX idx_cotton_stories_person ON cotton_stories (person_id)" }, {"kind": "index","name": "idx_cotton_stories_posted","tbl_name": "cotton_stories","sql": "CREATE INDEX idx_cotton_stories_posted ON cotton_stories (workspace_id, posted_at)" }, {"kind": "index","name": "idx_cotton_table_definitions_author","tbl_name": "cotton_table_definitions","sql": "CREATE INDEX idx_cotton_table_definitions_author ON cotton_table_definitions (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_theme_definitions_author","tbl_name": "cotton_theme_definitions","sql": "CREATE INDEX idx_cotton_theme_definitions_author ON cotton_theme_definitions (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_thought_attachments_author","tbl_name": "cotton_thought_attachments","sql": "CREATE INDEX idx_cotton_thought_attachments_author ON cotton_thought_attachments (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_thought_attachments_thought","tbl_name": "cotton_thought_attachments","sql": "CREATE INDEX idx_cotton_thought_attachments_thought ON cotton_thought_attachments (thought_id, position)" }, {"kind": "index","name": "idx_cotton_todo_recurrences_author","tbl_name": "cotton_todo_recurrences","sql": "CREATE INDEX idx_cotton_todo_recurrences_author ON cotton_todo_recurrences (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_todo_recurrences_workspace","tbl_name": "cotton_todo_recurrences","sql": "CREATE INDEX idx_cotton_todo_recurrences_workspace ON cotton_todo_recurrences (workspace_id)" }, {"kind": "index","name": "idx_cotton_todos_author","tbl_name": "cotton_todos","sql": "CREATE INDEX idx_cotton_todos_author ON cotton_todos (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_todos_open","tbl_name": "cotton_todos","sql": "CREATE INDEX idx_cotton_todos_open ON cotton_todos (workspace_id) WHERE status = 'open' AND trashed_at IS NULL" }, {"kind": "index","name": "idx_cotton_todos_recurrence","tbl_name": "cotton_todos","sql": "CREATE INDEX idx_cotton_todos_recurrence ON cotton_todos (recurrence_id) WHERE recurrence_id IS NOT NULL" }, {"kind": "index","name": "idx_cotton_todos_workspace","tbl_name": "cotton_todos","sql": "CREATE INDEX idx_cotton_todos_workspace ON cotton_todos (workspace_id)" }, {"kind": "index","name": "idx_cotton_todos_workspace_due","tbl_name": "cotton_todos","sql": "CREATE INDEX idx_cotton_todos_workspace_due ON cotton_todos (workspace_id, due_at)" }, {"kind": "index","name": "idx_cotton_tool_assets_author","tbl_name": "cotton_tool_assets","sql": "CREATE INDEX idx_cotton_tool_assets_author ON cotton_tool_assets (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_tool_definitions_author","tbl_name": "cotton_tool_definitions","sql": "CREATE INDEX idx_cotton_tool_definitions_author ON cotton_tool_definitions (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_toolkits_author","tbl_name": "cotton_toolkits","sql": "CREATE INDEX idx_cotton_toolkits_author ON cotton_toolkits (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_toolkits_position","tbl_name": "cotton_toolkits","sql": "CREATE INDEX idx_cotton_toolkits_position ON cotton_toolkits (workspace_id, position)" }, {"kind": "index","name": "idx_cotton_undos_author","tbl_name": "cotton_undos","sql": "CREATE INDEX idx_cotton_undos_author ON cotton_undos (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_undos_change","tbl_name": "cotton_undos","sql": "CREATE INDEX idx_cotton_undos_change ON cotton_undos (workspace_id, change_id)" }, {"kind": "index","name": "idx_cotton_usage_author","tbl_name": "cotton_usage","sql": "CREATE INDEX idx_cotton_usage_author ON cotton_usage (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_usage_workspace_at","tbl_name": "cotton_usage","sql": "CREATE INDEX idx_cotton_usage_workspace_at ON cotton_usage (workspace_id, at)" }, {"kind": "index","name": "idx_cotton_vault_keys_author","tbl_name": "cotton_vault_keys","sql": "CREATE INDEX idx_cotton_vault_keys_author ON cotton_vault_keys (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_vault_keys_version","tbl_name": "cotton_vault_keys","sql": "CREATE INDEX idx_cotton_vault_keys_version ON cotton_vault_keys (workspace_id, vmk_version)" }, {"kind": "index","name": "idx_cotton_vault_retired_keys_author","tbl_name": "cotton_vault_retired_keys","sql": "CREATE INDEX idx_cotton_vault_retired_keys_author ON cotton_vault_retired_keys (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_vault_retired_keys_version","tbl_name": "cotton_vault_retired_keys","sql": "CREATE INDEX idx_cotton_vault_retired_keys_version ON cotton_vault_retired_keys (workspace_id, version)" }, {"kind": "index","name": "idx_cotton_vault_state_author","tbl_name": "cotton_vault_state","sql": "CREATE INDEX idx_cotton_vault_state_author ON cotton_vault_state (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_videos_author","tbl_name": "cotton_videos","sql": "CREATE INDEX idx_cotton_videos_author ON cotton_videos (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_videos_favourite","tbl_name": "cotton_videos","sql": "CREATE INDEX idx_cotton_videos_favourite ON cotton_videos (workspace_id, taken_at DESC) WHERE favourite = 1" }, {"kind": "index","name": "idx_cotton_videos_origin","tbl_name": "cotton_videos","sql": "CREATE INDEX idx_cotton_videos_origin ON cotton_videos (origin_handle) WHERE origin_handle IS NOT NULL" }, {"kind": "index","name": "idx_cotton_videos_phash","tbl_name": "cotton_videos","sql": "CREATE INDEX idx_cotton_videos_phash ON cotton_videos (workspace_id, phash) WHERE phash IS NOT NULL" }, {"kind": "index","name": "idx_cotton_videos_place","tbl_name": "cotton_videos","sql": "CREATE INDEX idx_cotton_videos_place ON cotton_videos (workspace_id, place_city)" }, {"kind": "index","name": "idx_cotton_videos_review","tbl_name": "cotton_videos","sql": "CREATE INDEX idx_cotton_videos_review ON cotton_videos (workspace_id, review_at) WHERE review_note IS NOT NULL" }, {"kind": "index","name": "idx_cotton_videos_taken","tbl_name": "cotton_videos","sql": "CREATE INDEX idx_cotton_videos_taken ON cotton_videos (workspace_id, taken_at DESC)" }, {"kind": "index","name": "idx_cotton_videos_undescribed","tbl_name": "cotton_videos","sql": "CREATE INDEX idx_cotton_videos_undescribed ON cotton_videos (workspace_id, taken_at DESC) WHERE summary IS NULL" }, {"kind": "index","name": "idx_cotton_voice_vocabulary_author","tbl_name": "cotton_voice_vocabulary","sql": "CREATE INDEX idx_cotton_voice_vocabulary_author ON cotton_voice_vocabulary (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_voice_vocabulary_workspace","tbl_name": "cotton_voice_vocabulary","sql": "CREATE INDEX idx_cotton_voice_vocabulary_workspace ON cotton_voice_vocabulary (workspace_id)" }, {"kind": "index","name": "idx_cotton_widgets_author","tbl_name": "cotton_widgets","sql": "CREATE INDEX idx_cotton_widgets_author ON cotton_widgets (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_cotton_widgets_device","tbl_name": "cotton_widgets","sql": "CREATE INDEX idx_cotton_widgets_device ON cotton_widgets (workspace_id, device_id)" }, {"kind": "index","name": "idx_cotton_workspaces_author","tbl_name": "cotton_workspaces","sql": "CREATE INDEX idx_cotton_workspaces_author ON cotton_workspaces (substr(_hlc, 20), _hlc)" }, {"kind": "index","name": "idx_media_state","tbl_name": "_media","sql": "CREATE INDEX idx_media_state ON _media (state, next_attempt_at)" }, {"kind": "index","name": "idx_outbox_order","tbl_name": "_outbox","sql": "CREATE INDEX idx_outbox_order ON _outbox (hlc, op_id)" }, {"kind": "index","name": "idx_parked_row","tbl_name": "_parked","sql": "CREATE INDEX idx_parked_row ON _parked (direction, tbl, row_id)" }, {"kind": "index","name": "idx_tombstones_author","tbl_name": "_tombstones","sql": "CREATE INDEX idx_tombstones_author ON _tombstones (substr(hlc, 20), hlc)" }, {"kind": "index","name": "idx_tombstones_held","tbl_name": "_tombstones","sql": "CREATE INDEX idx_tombstones_held ON _tombstones (held) WHERE held = 1" }, {"kind": "index","name": "idx_tombstones_hlc","tbl_name": "_tombstones","sql": "CREATE INDEX idx_tombstones_hlc ON _tombstones (hlc)" }, {"kind": "index","name": "idx_writes_author","tbl_name": "_writes","sql": "CREATE INDEX idx_writes_author ON _writes (author, hlc) WHERE held = 0" }, {"kind": "index","name": "idx_writes_held","tbl_name": "_writes","sql": "CREATE INDEX idx_writes_held ON _writes (held) WHERE held = 1" }, {"kind": "index","name": "idx_writes_hlc","tbl_name": "_writes","sql": "CREATE INDEX idx_writes_hlc ON _writes (hlc)" }, {"kind": "index","name": "idx_writes_owners","tbl_name": "_writes_owners","sql": "CREATE INDEX idx_writes_owners ON _writes_owners (tbl, owner)" }, {"kind": "index","name": "uq_cotton_ai_budgets_workspace","tbl_name": "cotton_ai_budgets","sql": "CREATE UNIQUE INDEX uq_cotton_ai_budgets_workspace ON cotton_ai_budgets (workspace_id)" }, {"kind": "index","name": "uq_cotton_audiences_record","tbl_name": "cotton_audiences","sql": "CREATE UNIQUE INDEX uq_cotton_audiences_record ON cotton_audiences (workspace_id, record_table, record_id)" }, {"kind": "index","name": "uq_cotton_device_keep_rule","tbl_name": "cotton_device_keep","sql": "CREATE UNIQUE INDEX uq_cotton_device_keep_rule ON cotton_device_keep (workspace_id, device_id, kind, target)" }, {"kind": "index","name": "uq_cotton_dictations_workspace_external","tbl_name": "cotton_dictations","sql": "CREATE UNIQUE INDEX uq_cotton_dictations_workspace_external ON cotton_dictations (workspace_id, external_id) WHERE external_id IS NOT NULL" }, {"kind": "index","name": "uq_cotton_events_gcal_id","tbl_name": "cotton_events","sql": "CREATE UNIQUE INDEX uq_cotton_events_gcal_id ON cotton_events (account, gcal_id) WHERE gcal_id IS NOT NULL" }, {"kind": "index","name": "uq_cotton_group_members_member","tbl_name": "cotton_group_members","sql": "CREATE UNIQUE INDEX uq_cotton_group_members_member ON cotton_group_members (group_id, record_id)" }, {"kind": "index","name": "uq_cotton_links_ends","tbl_name": "cotton_links","sql": "CREATE UNIQUE INDEX uq_cotton_links_ends ON cotton_links (from_kind, from_id, to_kind, to_id, coalesce(to_database, ''))" }, {"kind": "index","name": "uq_cotton_media_album_items_member","tbl_name": "cotton_media_album_items","sql": "CREATE UNIQUE INDEX uq_cotton_media_album_items_member ON cotton_media_album_items (album_id, record_id)" }, {"kind": "index","name": "uq_cotton_media_duplicates_pair","tbl_name": "cotton_media_duplicates","sql": "CREATE UNIQUE INDEX uq_cotton_media_duplicates_pair ON cotton_media_duplicates (workspace_id, keep_id, copy_id)" }, {"kind": "index","name": "uq_cotton_media_faces_natural","tbl_name": "cotton_media_faces","sql": "CREATE UNIQUE INDEX uq_cotton_media_faces_natural ON cotton_media_faces (workspace_id, record_kind, record_id, source, source_id)" }, {"kind": "index","name": "uq_cotton_media_sightings_natural","tbl_name": "cotton_media_sightings","sql": "CREATE UNIQUE INDEX uq_cotton_media_sightings_natural ON cotton_media_sightings (workspace_id, record_kind, record_id, source, ifnull(source_id, ''))" }, {"kind": "index","name": "uq_cotton_money_accounts_default","tbl_name": "cotton_money_accounts","sql": "CREATE UNIQUE INDEX uq_cotton_money_accounts_default ON cotton_money_accounts (workspace_id) WHERE is_default = 1" }, {"kind": "index","name": "uq_cotton_money_accounts_identity","tbl_name": "cotton_money_accounts","sql": "CREATE UNIQUE INDEX uq_cotton_money_accounts_identity ON cotton_money_accounts (workspace_id, institution, number_mask) WHERE (institution IS NOT NULL) AND (number_mask IS NOT NULL)" }, {"kind": "index","name": "uq_cotton_money_evidence_line","tbl_name": "cotton_money_evidence","sql": "CREATE UNIQUE INDEX uq_cotton_money_evidence_line ON cotton_money_evidence (ref_id) WHERE kind = 'statement_line'" }, {"kind": "index","name": "uq_cotton_money_evidence_ref","tbl_name": "cotton_money_evidence","sql": "CREATE UNIQUE INDEX uq_cotton_money_evidence_ref ON cotton_money_evidence (transaction_id, kind, ref_id) WHERE ref_id IS NOT NULL" }, {"kind": "index","name": "uq_cotton_money_statement_lines_fingerprint","tbl_name": "cotton_money_statement_lines","sql": "CREATE UNIQUE INDEX uq_cotton_money_statement_lines_fingerprint ON cotton_money_statement_lines (statement_id, fingerprint)" }, {"kind": "index","name": "uq_cotton_money_transactions_external_hash","tbl_name": "cotton_money_transactions","sql": "CREATE UNIQUE INDEX uq_cotton_money_transactions_external_hash ON cotton_money_transactions (workspace_id, external_hash) WHERE external_hash IS NOT NULL" }, {"kind": "index","name": "uq_cotton_msg_messages_external","tbl_name": "cotton_msg_messages","sql": "CREATE UNIQUE INDEX uq_cotton_msg_messages_external ON cotton_msg_messages (thread_id, channel, external_id) WHERE external_id IS NOT NULL" }, {"kind": "index","name": "uq_cotton_msg_owner_settings_handle","tbl_name": "cotton_msg_owner_settings","sql": "CREATE UNIQUE INDEX uq_cotton_msg_owner_settings_handle ON cotton_msg_owner_settings (handle)" }, {"kind": "index","name": "uq_cotton_msg_thread_filings_pair","tbl_name": "cotton_msg_thread_filings","sql": "CREATE UNIQUE INDEX uq_cotton_msg_thread_filings_pair ON cotton_msg_thread_filings (workspace_id, thread_id, database_id)" }, {"kind": "index","name": "uq_cotton_msg_thread_marks_copy","tbl_name": "cotton_msg_thread_marks","sql": "CREATE UNIQUE INDEX uq_cotton_msg_thread_marks_copy ON cotton_msg_thread_marks (workspace_id, database_id, thread_id)" }, {"kind": "index","name": "uq_cotton_msg_threads_dm","tbl_name": "cotton_msg_threads","sql": "CREATE UNIQUE INDEX uq_cotton_msg_threads_dm ON cotton_msg_threads (workspace_id, contact_id) WHERE kind = 'dm'" }, {"kind": "index","name": "uq_cotton_msg_threads_group_key","tbl_name": "cotton_msg_threads","sql": "CREATE UNIQUE INDEX uq_cotton_msg_threads_group_key ON cotton_msg_threads (workspace_id, external_key) WHERE external_key IS NOT NULL" }, {"kind": "index","name": "uq_cotton_notes_journal_day","tbl_name": "cotton_notes","sql": "CREATE UNIQUE INDEX uq_cotton_notes_journal_day ON cotton_notes (workspace_id, journal_date, COALESCE(project_id, '')) WHERE kind = 'journal'" }, {"kind": "index","name": "uq_cotton_notes_public_slug","tbl_name": "cotton_notes","sql": "CREATE UNIQUE INDEX uq_cotton_notes_public_slug ON cotton_notes (public_slug) WHERE public_slug IS NOT NULL" }, {"kind": "index","name": "uq_cotton_people_device_contact","tbl_name": "cotton_people","sql": "CREATE UNIQUE INDEX uq_cotton_people_device_contact ON cotton_people (workspace_id, device_contact_id) WHERE device_contact_id IS NOT NULL" }, {"kind": "index","name": "uq_cotton_person_handles_handle","tbl_name": "cotton_person_handles","sql": "CREATE UNIQUE INDEX uq_cotton_person_handles_handle ON cotton_person_handles (workspace_id, kind, normalised)" }, {"kind": "index","name": "uq_cotton_person_suggestions_contact","tbl_name": "cotton_person_suggestions","sql": "CREATE UNIQUE INDEX uq_cotton_person_suggestions_contact ON cotton_person_suggestions (workspace_id, contact_id, candidate_id) WHERE contact_id IS NOT NULL" }, {"kind": "index","name": "uq_cotton_person_suggestions_pair","tbl_name": "cotton_person_suggestions","sql": "CREATE UNIQUE INDEX uq_cotton_person_suggestions_pair ON cotton_person_suggestions (workspace_id, person_id, candidate_id)" }, {"kind": "index","name": "uq_cotton_posts_external","tbl_name": "cotton_posts","sql": "CREATE UNIQUE INDEX uq_cotton_posts_external ON cotton_posts (workspace_id, source, account, external_id)" }, {"kind": "index","name": "uq_cotton_push_acks_device_push","tbl_name": "cotton_push_acks","sql": "CREATE UNIQUE INDEX uq_cotton_push_acks_device_push ON cotton_push_acks (workspace_id, device_id, push_id)" }, {"kind": "index","name": "uq_cotton_secrets_service_name","tbl_name": "cotton_secrets","sql": "CREATE UNIQUE INDEX uq_cotton_secrets_service_name ON cotton_secrets (workspace_id, service, name) WHERE service IS NOT NULL" }, {"kind": "index","name": "uq_cotton_tool_assets_picture","tbl_name": "cotton_tool_assets","sql": "CREATE UNIQUE INDEX uq_cotton_tool_assets_picture ON cotton_tool_assets (workspace_id, tool_id, name)" }, {"kind": "index","name": "uq_cotton_voice_vocabulary_workspace_term","tbl_name": "cotton_voice_vocabulary","sql": "CREATE UNIQUE INDEX uq_cotton_voice_vocabulary_workspace_term ON cotton_voice_vocabulary (workspace_id, lower(term))" }, {"kind": "table","name": "_ai_batches","tbl_name": "_ai_batches","sql": "CREATE TABLE _ai_batches (request_key TEXT PRIMARY KEY, batch_id TEXT NOT NULL, next_poll TEXT NOT NULL, created_at TEXT NOT NULL, result TEXT, metered INTEGER NOT NULL DEFAULT 0, reservation_usd REAL NOT NULL DEFAULT 0, purpose TEXT, context TEXT, applied INTEGER NOT NULL DEFAULT 0, failure TEXT)" }, {"kind": "table","name": "_computed","tbl_name": "_computed","sql": "CREATE TABLE _computed (\n table_id TEXT NOT NULL,\n record_id TEXT NOT NULL,\n key TEXT NOT NULL,\n value,\n PRIMARY KEY (table_id, record_id, key)\n )" }, {"kind": "table","name": "_cursors","tbl_name": "_cursors","sql": "CREATE TABLE _cursors (\n author_device_id TEXT PRIMARY KEY,\n hlc_seen TEXT NOT NULL,\n updated_at TEXT NOT NULL\n )" }, {"kind": "table","name": "_fts_fill","tbl_name": "_fts_fill","sql": "CREATE TABLE _fts_fill (\n fts TEXT PRIMARY KEY,\n floor INTEGER NOT NULL,\n filled INTEGER NOT NULL DEFAULT 0,\n total INTEGER NOT NULL DEFAULT 0,\n started_at TEXT NOT NULL,\n updated_at TEXT NOT NULL\n )" }, {"kind": "table","name": "_gone","tbl_name": "_gone","sql": "CREATE TABLE _gone (\n tbl TEXT NOT NULL,\n row_id TEXT NOT NULL,\n hlc TEXT NOT NULL,\n reason TEXT,\n op_id TEXT,\n author TEXT,\n actor TEXT,\n bytes BLOB NOT NULL,\n sig BLOB,\n PRIMARY KEY (tbl, row_id)\n )" }, {"kind": "table","name": "_keep_fetch","tbl_name": "_keep_fetch","sql": "CREATE TABLE _keep_fetch (\n tbl TEXT PRIMARY KEY,\n covered TEXT NOT NULL,\n target TEXT,\n after TEXT\n )" }, {"kind": "table","name": "_media","tbl_name": "_media","sql": "CREATE TABLE _media (\n key TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n sha256 TEXT NOT NULL,\n content_type TEXT NOT NULL,\n size_bytes INTEGER NOT NULL,\n local_path TEXT,\n state TEXT NOT NULL CHECK (state IN ('pending','synced','failed','delete_pending')),\n after TEXT,\n after_row_id TEXT,\n attempts INTEGER NOT NULL DEFAULT 0,\n last_error TEXT,\n next_attempt_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n tier TEXT,\n pinned INTEGER NOT NULL DEFAULT 0,\n last_viewed_at TEXT,\n captured_here INTEGER NOT NULL DEFAULT 0,\n fetched_by_rule INTEGER NOT NULL DEFAULT 0 CHECK (fetched_by_rule IN (0,1))\n )" }, {"kind": "table","name": "_media_key_names","tbl_name": "_media_key_names","sql": "CREATE TABLE _media_key_names (\n key TEXT NOT NULL,\n tbl TEXT NOT NULL,\n row_id TEXT NOT NULL,\n PRIMARY KEY (key, tbl, row_id)\n )" }, {"kind": "table","name": "_media_unlinks","tbl_name": "_media_unlinks","sql": "CREATE TABLE _media_unlinks (\n key TEXT PRIMARY KEY,\n queued_at TEXT NOT NULL,\n done_at TEXT\n )" }, {"kind": "table","name": "_meta","tbl_name": "_meta","sql": "CREATE TABLE _meta (\n only_one INTEGER PRIMARY KEY CHECK (only_one = 1),\n workspace_id TEXT NOT NULL,\n owner_id TEXT NOT NULL,\n schema_version INTEGER NOT NULL,\n last_server_seq INTEGER NOT NULL DEFAULT 0,\n device_id TEXT NOT NULL,\n last_hlc TEXT,\n author_id TEXT,\n rotation_check_due TEXT,\n handed_over_epoch INTEGER,\n heard_serving_epoch INTEGER\n )" }, {"kind": "table","name": "_on_demand","tbl_name": "_on_demand","sql": "CREATE TABLE _on_demand (\n tbl TEXT NOT NULL,\n row_id TEXT NOT NULL,\n fetched_at TEXT NOT NULL,\n opened_at TEXT NOT NULL,\n PRIMARY KEY (tbl, row_id)\n )" }, {"kind": "table","name": "_outbox","tbl_name": "_outbox","sql": "CREATE TABLE _outbox (\n op_id TEXT PRIMARY KEY,\n kind TEXT NOT NULL CHECK (kind IN ('create', 'change', 'retract')),\n author TEXT NOT NULL,\n tbl TEXT NOT NULL,\n row_id TEXT NOT NULL,\n hlc TEXT NOT NULL,\n schema_version INTEGER NOT NULL,\n queued_at TEXT NOT NULL,\n attempts INTEGER NOT NULL DEFAULT 0,\n last_error TEXT,\n bytes BLOB NOT NULL,\n sig BLOB,\n mint_cont INTEGER,\n mint_boot TEXT\n )" }, {"kind": "table","name": "_parked","tbl_name": "_parked","sql": "CREATE TABLE _parked (\n op_id TEXT PRIMARY KEY,\n direction TEXT,\n class TEXT NOT NULL CHECK (class IN ('waiting','conflict','gone','unverified','newer-shape')),\n reason TEXT,\n first_at TEXT,\n tried_at TEXT,\n tries INTEGER NOT NULL DEFAULT 0,\n bytes BLOB,\n sig BLOB,\n tbl TEXT NOT NULL,\n row_id TEXT NOT NULL,\n handover_epoch INTEGER,\n handover_offers INTEGER NOT NULL DEFAULT 0\n )" }, {"kind": "table","name": "_tombstones","tbl_name": "_tombstones","sql": "CREATE TABLE _tombstones (\n tbl TEXT NOT NULL,\n row_id TEXT NOT NULL,\n hlc TEXT NOT NULL,\n op_id TEXT NOT NULL,\n author TEXT NOT NULL,\n actor TEXT NOT NULL,\n bytes BLOB NOT NULL,\n sig BLOB,\n held INTEGER NOT NULL DEFAULT 0,\n mint_cont INTEGER,\n mint_boot TEXT,\n PRIMARY KEY (tbl, row_id)\n )" }, {"kind": "table","name": "_writes","tbl_name": "_writes","sql": "CREATE TABLE _writes (\n tbl TEXT NOT NULL,\n row_id TEXT NOT NULL,\n hlc TEXT NOT NULL,\n author TEXT,\n op_id TEXT UNIQUE,\n kind TEXT CHECK (kind IS NULL OR kind IN ('create','change','retract')),\n actor TEXT,\n held INTEGER NOT NULL DEFAULT 0,\n mint_cont INTEGER,\n mint_boot TEXT,\n bytes BLOB,\n fields TEXT,\n sig BLOB,\n PRIMARY KEY (tbl, row_id, hlc)\n )" }, {"kind": "table","name": "_writes_owners","tbl_name": "_writes_owners","sql": "CREATE TABLE _writes_owners (\n receipt TEXT NOT NULL REFERENCES _writes(op_id) ON DELETE CASCADE,\n tbl TEXT NOT NULL,\n owner TEXT NOT NULL,\n PRIMARY KEY (receipt, tbl, owner)\n ) WITHOUT ROWID" }, {"kind": "table","name": "cotton_account_usage_samples","tbl_name": "cotton_account_usage_samples","sql": "CREATE TABLE cotton_account_usage_samples (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n account_id TEXT NOT NULL,\n sampled_at TEXT NOT NULL,\n five_hour_pct REAL,\n weekly_pct REAL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, account_id, sampled_at),\n CHECK (length(trim(account_id)) > 0),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_admissions","tbl_name": "cotton_admissions","sql": "CREATE TABLE cotton_admissions (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n person_key TEXT NOT NULL CHECK (length(person_key) > 0),\n person_name TEXT NOT NULL,\n rights TEXT NOT NULL CHECK (rights IN ('owner','member','admin')),\n invite_id TEXT UNIQUE,\n admitted_by_person TEXT NOT NULL,\n p_sig TEXT NOT NULL,\n admitted_at TEXT NOT NULL,\n suggested_person_id TEXT,\n suggested_person_sig TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_agent_accounts","tbl_name": "cotton_agent_accounts","sql": "CREATE TABLE cotton_agent_accounts (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n provider TEXT NOT NULL,\n email TEXT NOT NULL,\n label TEXT,\n five_hour_pct REAL,\n five_hour_resets_at TEXT,\n weekly_pct REAL,\n weekly_resets_at TEXT,\n seen_at TEXT,\n seen_on_device_id TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, provider, email),\n CHECK (provider IN ('anthropic', 'openai')),\n CHECK (length(trim(email)) > 0),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_ai_access","tbl_name": "cotton_ai_access","sql": "CREATE TABLE cotton_ai_access (\n workspace_id TEXT PRIMARY KEY,\n owner_user_id TEXT NOT NULL,\n trial_started_at TEXT,\n subscription_active INTEGER NOT NULL DEFAULT 0,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_ai_budgets","tbl_name": "cotton_ai_budgets","sql": "CREATE TABLE cotton_ai_budgets (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n name TEXT NOT NULL DEFAULT 'AI budget',\n hourly_cap REAL NOT NULL DEFAULT 1 CHECK (hourly_cap >= 0),\n daily_cap REAL NOT NULL DEFAULT 5 CHECK (daily_cap >= 0),\n currency TEXT NOT NULL DEFAULT 'USD',\n usd_rate REAL NOT NULL DEFAULT 1 CHECK (usd_rate > 0),\n paused_until TEXT,\n pause_reason TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT)" }, {"kind": "table","name": "cotton_ai_calls","tbl_name": "cotton_ai_calls","sql": "CREATE TABLE cotton_ai_calls (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n legacy_id INTEGER,\n created_at TEXT NOT NULL,\n function_name TEXT NOT NULL,\n provider TEXT NOT NULL,\n model TEXT,\n status TEXT NOT NULL,\n error_message TEXT,\n input_tokens INTEGER,\n output_tokens INTEGER,\n cache_read_input_tokens INTEGER,\n cache_creation_input_tokens INTEGER,\n duration_seconds REAL,\n latency_ms INTEGER NOT NULL,\n cost_usd REAL,\n key_source TEXT NOT NULL DEFAULT 'platform',\n is_preview INTEGER NOT NULL DEFAULT 0,\n metadata TEXT,\n updated_at TEXT NOT NULL,\n device_id TEXT,\n cost_amount REAL,\n currency TEXT NOT NULL DEFAULT 'USD',\n mode TEXT NOT NULL DEFAULT 'live',\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n local_day TEXT,\n at TEXT, job_id TEXT, drained_by TEXT)" }, {"kind": "table","name": "cotton_ai_jobs","tbl_name": "cotton_ai_jobs","sql": "CREATE TABLE cotton_ai_jobs (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n level INTEGER NOT NULL CHECK (level IN (2,3)),\n subject_table TEXT NOT NULL,\n subject_id TEXT NOT NULL,\n input TEXT NOT NULL CHECK (json_valid(input)),\n state TEXT NOT NULL DEFAULT 'waiting' CHECK (state IN ('waiting','taken','done','failed','refused')),\n taken_by TEXT,\n taken_at TEXT,\n done_at TEXT,\n outcome TEXT CHECK (outcome IS NULL OR json_valid(outcome)),\n attempts INTEGER NOT NULL DEFAULT 0 CHECK (attempts >= 0),\n reason TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT\n)" }, {"kind": "table","name": "cotton_alarms","tbl_name": "cotton_alarms","sql": "CREATE TABLE cotton_alarms (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n label TEXT NOT NULL DEFAULT '',\n hour INTEGER NOT NULL,\n minute INTEGER NOT NULL,\n repeat_days TEXT NOT NULL DEFAULT '[]',\n enabled INTEGER NOT NULL DEFAULT 1,\n sound INTEGER NOT NULL DEFAULT 1,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n trashed_at TEXT,\n CHECK ((hour >= 0) AND (hour <= 23)),\n CHECK ((minute >= 0) AND (minute <= 59)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_arrivals","tbl_name": "cotton_arrivals","sql": "CREATE TABLE cotton_arrivals (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n kind TEXT NOT NULL CHECK(kind IN ('mail','chat','call','photo','thought')),\n record_table TEXT NOT NULL,\n record_id TEXT NOT NULL,\n context TEXT NOT NULL CHECK(json_valid(context) AND json_type(context)='object'),\n seen_by TEXT,\n seen_at TEXT,\n burst TEXT,\n outcome TEXT CHECK(outcome IN ('acted','proposed','asked','left')),\n reason TEXT,\n retrieval TEXT CHECK(retrieval IS NULL OR (json_valid(retrieval) AND json_type(retrieval)='array')),\n changes TEXT CHECK(changes IS NULL OR (json_valid(changes) AND json_type(changes)='array')),\n ask TEXT,\n decided_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY(workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n)" }, {"kind": "table","name": "cotton_assistant_runs","tbl_name": "cotton_assistant_runs","sql": "CREATE TABLE cotton_assistant_runs (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n source_kind TEXT NOT NULL CHECK (source_kind IN ('thought','comment','session_message')),\n source_id TEXT NOT NULL,\n record_kind TEXT,\n record_id TEXT,\n session_id TEXT,\n class TEXT NOT NULL CHECK (class IN ('quick','deep')),\n state TEXT NOT NULL DEFAULT 'queued' CHECK (state IN ('queued','running','done','failed')),\n task TEXT NOT NULL CHECK (length(task) BETWEEN 1 AND 500),\n receipt TEXT NOT NULL,\n turns INTEGER NOT NULL DEFAULT 0,\n input_tokens INTEGER NOT NULL DEFAULT 0,\n output_tokens INTEGER NOT NULL DEFAULT 0,\n cost_usd REAL,\n result_note_id TEXT,\n stopped_reason TEXT CHECK (stopped_reason IS NULL OR stopped_reason IN ('answered','turn_ceiling','time_ceiling','no_key','model_refused')),\n error TEXT,\n queued_at TEXT NOT NULL,\n started_at TEXT,\n finished_at TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK ((state = 'failed') = (error IS NOT NULL)),\n CHECK ((state IN ('done','failed')) = (finished_at IS NOT NULL)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_audiences","tbl_name": "cotton_audiences","sql": "CREATE TABLE cotton_audiences (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n record_table TEXT NOT NULL CHECK (length(trim(record_table)) > 0),\n record_id TEXT NOT NULL CHECK (length(trim(record_id)) > 0),\n audience TEXT NOT NULL CHECK (length(trim(audience)) > 0),\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_authors","tbl_name": "cotton_authors","sql": "CREATE TABLE cotton_authors (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n device_id TEXT NOT NULL CHECK (length(device_id) > 0),\n device_name TEXT,\n minted_at TEXT NOT NULL,\n reason TEXT NOT NULL CHECK (reason IN ('first','take-over','redate','keys')),\n first_stamp TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_automation_runs","tbl_name": "cotton_automation_runs","sql": "CREATE TABLE cotton_automation_runs (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n automation TEXT NOT NULL,\n changes TEXT NOT NULL DEFAULT '[]',\n root_first INTEGER,\n started_at TEXT NOT NULL,\n ended_at TEXT,\n outcome TEXT,\n summary TEXT,\n record_byline TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n deleted_at TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_blocked_senders","tbl_name": "cotton_blocked_senders","sql": "CREATE TABLE cotton_blocked_senders (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n address TEXT NOT NULL,\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, address),\n CHECK (length(address) > 0),\n CHECK (address = lower(address)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_board_definitions","tbl_name": "cotton_board_definitions","sql": "CREATE TABLE cotton_board_definitions (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n definition TEXT NOT NULL,\n builtin INTEGER NOT NULL DEFAULT 0,\n builtin_revision INTEGER,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT, builtin_hash TEXT, builtin_stamp INTEGER,\n CHECK (length(id) > 0),\n CHECK (length(definition) > 0),\n CHECK (builtin IN (0, 1)),\n CHECK (builtin_revision IS NULL OR builtin_revision >= 1),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_call_log","tbl_name": "cotton_call_log","sql": "CREATE TABLE cotton_call_log (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n source TEXT NOT NULL,\n external_id TEXT NOT NULL,\n provider TEXT NOT NULL,\n direction TEXT NOT NULL,\n outcome TEXT NOT NULL,\n started_at TEXT NOT NULL,\n duration_s INTEGER NOT NULL DEFAULT 0,\n handle TEXT,\n contact_id TEXT,\n person_id TEXT,\n device TEXT,\n meta TEXT NOT NULL DEFAULT '{}',\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, source, external_id),\n CHECK (source IN ('ios_call_history', 'android_call_log')),\n CHECK (direction IN ('in', 'out')),\n CHECK (outcome IN ('answered', 'missed', 'cancelled', 'failed')),\n CHECK (length(trim(external_id)) > 0),\n CHECK (length(trim(provider)) > 0),\n CHECK (duration_s >= 0),\n CHECK (json_type(meta) = 'object'),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_changes","tbl_name": "cotton_changes","sql": "CREATE TABLE cotton_changes (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n table_id TEXT NOT NULL,\n record_id TEXT,\n verb TEXT NOT NULL,\n byline TEXT NOT NULL,\n before TEXT,\n after TEXT,\n created_at TEXT NOT NULL,\n kind TEXT,\n actor TEXT,\n write_hlc TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (length(id) > 0),\n CHECK (length(table_id) > 0),\n CHECK (length(verb) > 0),\n CHECK (before IS NULL OR json_valid(before)),\n CHECK (after IS NULL OR json_valid(after)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_code_credentials","tbl_name": "cotton_code_credentials","sql": "CREATE TABLE cotton_code_credentials (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n device_id TEXT NOT NULL CHECK (length(trim(device_id)) > 0),\n name TEXT NOT NULL CHECK (length(trim(name)) > 0),\n scope TEXT NOT NULL CHECK (scope IN ('device', 'script', 'runner')),\n created_at TEXT NOT NULL,\n expires_at TEXT,\n revoked_at TEXT,\n last_used_at TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n token_digest TEXT,\n minted_by TEXT, read_only INTEGER NOT NULL DEFAULT 0,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_collections","tbl_name": "cotton_collections","sql": "CREATE TABLE cotton_collections (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n name TEXT NOT NULL,\n is_default INTEGER NOT NULL DEFAULT 0,\n sort_key TEXT,\n created_at TEXT NOT NULL,\n archived_at TEXT,\n color TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (kind = 'calendar'),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_comments","tbl_name": "cotton_comments","sql": "CREATE TABLE \"cotton_comments\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n record_kind TEXT NOT NULL,\n record_id TEXT NOT NULL,\n parent_id TEXT,\n body TEXT NOT NULL,\n author_kind TEXT NOT NULL,\n author_user_id TEXT,\n author_label TEXT,\n anchor TEXT,\n resolved_at TEXT,\n resolved_by_kind TEXT,\n resolved_by_label TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n kind TEXT NOT NULL DEFAULT 'note', trashed_at TEXT,\n CHECK (kind IN ('question', 'note')),\n CHECK ((author_kind = 'agent') = (author_label IS NOT NULL)),\n CHECK (author_kind IN ('user', 'agent')),\n CHECK (length(trim(body)) > 0),\n CHECK (record_kind IN ('todo', 'event', 'note', 'journal', 'person', 'location', 'page', 'meeting', 'document', 'news_edition', 'memory', 'call', 'decision')),\n CHECK (resolved_by_kind IN ('user', 'agent')),\n CHECK ((resolved_at IS NULL) = (resolved_by_kind IS NULL)),\n CHECK ((author_kind = 'user') = (author_user_id IS NOT NULL)),\n FOREIGN KEY (parent_id) REFERENCES cotton_comments(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_connections","tbl_name": "cotton_connections","sql": "CREATE TABLE cotton_connections (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n kind TEXT NOT NULL CHECK (kind IN ('whatsapp','google','mail','calendar','cloudflare','git_host','mcp_server','mac_source','browser','tailscale')),\n name TEXT NOT NULL CHECK (length(trim(name)) > 0),\n reaches TEXT NOT NULL DEFAULT '',\n state TEXT NOT NULL DEFAULT 'needs_sign_in' CHECK (state IN ('reading','paused','needs_sign_in','failed')),\n last_read_at TEXT,\n last_error TEXT,\n read_requested_at TEXT,\n secret_id TEXT,\n schedule TEXT,\n config TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(config)),\n database_id TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_database_departures","tbl_name": "cotton_database_departures","sql": "CREATE TABLE cotton_database_departures (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n database_id TEXT NOT NULL CHECK (length(database_id) > 0),\n device_id TEXT CHECK (device_id IS NULL OR length(device_id) > 0),\n reason TEXT NOT NULL CHECK (reason IN ('left', 'removed', 'handed_over')),\n departed_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_databases","tbl_name": "cotton_databases","sql": "CREATE TABLE cotton_databases (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n name TEXT NOT NULL CHECK (length(trim(name)) > 0),\n sort_order REAL NOT NULL DEFAULT 0,\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_decisions","tbl_name": "cotton_decisions","sql": "CREATE TABLE cotton_decisions (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n title TEXT NOT NULL,\n why TEXT,\n pull TEXT,\n decided_by TEXT,\n trashed_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (length(trim(title)) > 0),\n CHECK (length(title) <= 280),\n CHECK (pull IS NULL OR length(trim(pull)) > 0),\n CHECK (decided_by IS NULL OR length(trim(decided_by)) > 0),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_dev_jobs","tbl_name": "cotton_dev_jobs","sql": "CREATE TABLE cotton_dev_jobs (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n device_id TEXT NOT NULL,\n command TEXT NOT NULL,\n cwd TEXT,\n timeout_seconds INTEGER NOT NULL DEFAULT 300,\n state TEXT NOT NULL DEFAULT 'queued',\n exit_code INTEGER,\n failure TEXT,\n log_path TEXT,\n log_bytes INTEGER NOT NULL DEFAULT 0,\n log_lines INTEGER NOT NULL DEFAULT 0,\n output_tail TEXT,\n created_at TEXT NOT NULL,\n claimed_at TEXT,\n finished_at TEXT,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (length(device_id) > 0),\n CHECK (length(trim(command)) > 0),\n CHECK (length(command) <= 4096),\n CHECK (cwd IS NULL OR length(trim(cwd)) > 0),\n CHECK (timeout_seconds > 0),\n CHECK (timeout_seconds <= 3600),\n CHECK (state IN ('queued', 'running', 'done', 'failed', 'expired')),\n CHECK (log_bytes >= 0),\n CHECK (log_lines >= 0),\n CHECK (output_tail IS NULL OR length(output_tail) <= 65536),\n CHECK (failure IS NULL OR length(failure) <= 2048),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_device_keep","tbl_name": "cotton_device_keep","sql": "CREATE TABLE cotton_device_keep (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n device_id TEXT NOT NULL CHECK (length(trim(device_id)) > 0),\n kind TEXT NOT NULL CHECK (kind IN ('table','group','record')),\n target TEXT NOT NULL CHECK (length(trim(target)) > 0),\n rule TEXT NOT NULL CHECK (rule IN ('all','none','always') OR (rule GLOB 'days:[1-9]*' AND substr(rule, 6) NOT GLOB '*[^0-9]*')),\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_device_relay_keys","tbl_name": "cotton_device_relay_keys","sql": "CREATE TABLE cotton_device_relay_keys (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n device_id TEXT NOT NULL CHECK (length(trim(device_id)) > 0),\n epoch INTEGER NOT NULL CHECK (epoch >= 0),\n relay_identity_key TEXT NOT NULL CHECK (length(relay_identity_key) = 43),\n set_at TEXT NOT NULL,\n set_by TEXT NOT NULL,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_device_samples","tbl_name": "cotton_device_samples","sql": "CREATE TABLE cotton_device_samples (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n device_id TEXT NOT NULL,\n sampled_at TEXT NOT NULL,\n load1 REAL,\n mem_free_pct INTEGER,\n disk_free_gb REAL,\n sessions_running INTEGER,\n build_lock_held INTEGER,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, device_id, sampled_at),\n CHECK (length(trim(device_id)) > 0),\n CHECK (build_lock_held IS NULL OR build_lock_held IN (0, 1)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_device_statements","tbl_name": "cotton_device_statements","sql": "CREATE TABLE cotton_device_statements (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n person_key TEXT NOT NULL CHECK (length(person_key) > 0),\n device_key TEXT NOT NULL CHECK (length(device_key) > 0),\n vault_public_key TEXT NOT NULL,\n device_name TEXT NOT NULL,\n p_sig TEXT NOT NULL,\n d_sig TEXT NOT NULL,\n made_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_devices","tbl_name": "cotton_devices","sql": "CREATE TABLE cotton_devices (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n device_id TEXT NOT NULL CHECK (length(device_id) > 0),\n name TEXT NOT NULL,\n platform TEXT,\n app_version TEXT,\n relay_identity_key TEXT,\n approved_at TEXT NOT NULL,\n approved_by_device TEXT NOT NULL,\n revoked_at TEXT,\n revoked_by_device TEXT,\n revoked_reason TEXT,\n recovery_key_shown_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n cpu_count INTEGER,\n mem_total_gb REAL,\n mem_free_pct INTEGER,\n load1 REAL,\n disk_free_gb REAL,\n sessions_running INTEGER,\n kept_space_bytes INTEGER DEFAULT 2000000000 CHECK (kept_space_bytes IS NULL OR kept_space_bytes >= 0),\n sessions_cap INTEGER NOT NULL DEFAULT 3 CHECK (sessions_cap >= 0),\n build_lock_held INTEGER CHECK (build_lock_held IS NULL OR build_lock_held IN (0, 1)),\n agents TEXT NOT NULL DEFAULT '{}' CHECK (json_type(agents) = 'object'),\n account_ids TEXT NOT NULL DEFAULT '{}' CHECK (json_type(account_ids) = 'object'),\n host_version TEXT,\n sampled_at TEXT,\n mem_committed_gb REAL,\n mem_budget_gb REAL,\n session_peak_gb REAL,\n session_peak_samples INTEGER,\n serving_rank INTEGER,\n repos TEXT CHECK (repos IS NULL OR json_type(repos) = 'object'),\n chip TEXT,\n os_version TEXT,\n disk_total_gb REAL,\n update_hold TEXT,\n scope TEXT NOT NULL DEFAULT 'full' CHECK (scope IN ('full','reader','runner')),\n person_key TEXT,\n push_token TEXT,\n push_bundle_id TEXT,\n push_environment TEXT CHECK (push_environment IS NULL OR push_environment IN ('sandbox','production')),\n push_registered_at TEXT,\n push_retired_at TEXT,\n push_retired_reason TEXT,\n pushed_first_at TEXT,\n push_authorization TEXT CHECK (push_authorization IS NULL OR push_authorization IN ('authorized','provisional','ephemeral','denied','not_determined')),\n schema_version INTEGER CHECK (schema_version IS NULL OR schema_version > 0),\n copy_as_of TEXT, ai_holds TEXT, ai_spend TEXT, ai_day_cap_usd REAL, reported_state TEXT, hardware_id TEXT, takes_placements INTEGER NOT NULL DEFAULT 0 CHECK (takes_placements IN (0,1)), keep_free_bytes INTEGER CHECK (keep_free_bytes IS NULL OR keep_free_bytes >= 0), keep_bytes TEXT NULL CHECK (keep_bytes IS NULL OR keep_bytes IN ('everything','rows_only')), runner_ordered_at TEXT NULL, runner_confirmed_at TEXT NULL, runner_problem TEXT NULL, camera_roll INTEGER NOT NULL DEFAULT 1 CHECK (camera_roll IN (0,1)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_dictations","tbl_name": "cotton_dictations","sql": "CREATE TABLE cotton_dictations (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n text TEXT NOT NULL,\n raw_text TEXT,\n source TEXT NOT NULL,\n host_app TEXT,\n words INTEGER NOT NULL DEFAULT 0,\n duration_ms INTEGER,\n spoken_at TEXT NOT NULL,\n external_id TEXT,\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (source IN ('take', 'typed', 'wispr')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_document_pages","tbl_name": "cotton_document_pages","sql": "CREATE TABLE cotton_document_pages (\n id TEXT PRIMARY KEY,\n document_id TEXT NOT NULL,\n workspace_id TEXT NOT NULL,\n page INTEGER NOT NULL,\n text TEXT NOT NULL,\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (document_id, page),\n CHECK (page >= 1),\n FOREIGN KEY (document_id) REFERENCES cotton_documents(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_documents","tbl_name": "cotton_documents","sql": "CREATE TABLE \"cotton_documents\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n title TEXT,\n original_name TEXT NOT NULL,\n mime TEXT NOT NULL,\n byte_size INTEGER NOT NULL,\n sha256 TEXT NOT NULL,\n storage_path TEXT NOT NULL,\n decrypted_path TEXT,\n password TEXT,\n page_count INTEGER,\n status TEXT NOT NULL DEFAULT 'processing',\n failed_stage TEXT,\n error_code TEXT,\n status_changed_at TEXT NOT NULL,\n doc_type TEXT NOT NULL DEFAULT 'other',\n document_date TEXT,\n period_start TEXT,\n period_end TEXT,\n issuer TEXT,\n summary TEXT,\n facts TEXT NOT NULL DEFAULT '{}',\n text_extracted INTEGER NOT NULL DEFAULT 0,\n source TEXT NOT NULL DEFAULT 'app',\n mcp_token_id TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '', origin_handle TEXT CHECK (origin_handle IS NULL OR length(origin_handle) > 0), secret_id TEXT,\n _born TEXT,\n trashed_at TEXT,\n UNIQUE (workspace_id, sha256),\n CHECK (byte_size >= 0),\n CHECK (doc_type IN ('bank_statement', 'card_statement', 'invoice', 'receipt', 'tax', 'id', 'insurance', 'medical', 'legal', 'ticket', 'statement_other', 'letter', 'manual', 'other')),\n CHECK ((status = 'failed') = (failed_stage IS NOT NULL)),\n CHECK (failed_stage IS NULL OR failed_stage IN ('unlock', 'extract', 'summarize', 'land')),\n CHECK ((page_count IS NULL) OR (page_count >= 0)),\n CHECK ((period_start IS NULL) OR (period_end IS NULL) OR (period_end >= period_start)),\n CHECK (length(sha256) = 64 AND NOT sha256 GLOB '*[^0-9a-f]*'),\n CHECK (source IN ('app', 'agent', 'share')),\n CHECK (status IN ('processing', 'summarizing', 'ready', 'locked', 'failed')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_email_participants","tbl_name": "cotton_email_participants","sql": "CREATE TABLE cotton_email_participants (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n thread_id TEXT NOT NULL,\n email TEXT NOT NULL,\n display_name TEXT,\n role TEXT NOT NULL DEFAULT 'cc',\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (thread_id, email),\n CHECK (length(email) > 0),\n CHECK (email = lower(email)),\n CHECK (role IN ('from', 'to', 'cc')),\n FOREIGN KEY (thread_id) REFERENCES cotton_email_threads(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_email_senders","tbl_name": "cotton_email_senders","sql": "CREATE TABLE cotton_email_senders (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n address TEXT NOT NULL,\n kind TEXT NOT NULL,\n written_to INTEGER NOT NULL DEFAULT 0,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n decided_by TEXT CHECK (decided_by IS NULL OR decided_by IN ('owner', 'assistant')),\n verdict TEXT CHECK (verdict IS NULL OR verdict IN ('person', 'service', 'junk')),\n reason TEXT,\n decided_at TEXT,\n UNIQUE (workspace_id, address),\n CHECK (length(address) > 0),\n CHECK (address = lower(address)),\n CHECK (kind IN ('person', 'service', 'junk')),\n CHECK (written_to IN (0, 1)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_email_threads","tbl_name": "cotton_email_threads","sql": "CREATE TABLE cotton_email_threads (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n external_key TEXT NOT NULL,\n subject TEXT,\n first_at TEXT,\n last_at TEXT,\n email_count INTEGER NOT NULL DEFAULT 0,\n summary TEXT,\n summary_updated_at TEXT,\n summary_by TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '', trashed_at TEXT,\n _born TEXT,\n sender_address TEXT,\n sender_kind TEXT,\n record_kind TEXT,\n amount_minor INTEGER,\n currency TEXT,\n merchant TEXT,\n record_on TEXT,\n reference TEXT,\n record_reason TEXT,\n UNIQUE (workspace_id, external_key),\n CHECK ((record_kind IS NULL) OR (record_kind IN ('receipt', 'statement', 'ticket', 'booking', 'code', 'delivery', 'notice'))),\n CHECK ((currency IS NULL) OR (length(currency) = 3 AND currency = upper(currency))),\n CHECK ((record_on IS NULL) OR (record_on GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]')),\n CHECK ((sender_address IS NULL) OR (sender_address = lower(sender_address) AND length(sender_address) > 0)),\n CHECK ((sender_kind IS NULL) OR (sender_kind IN ('person', 'service', 'junk'))),\n CHECK (length(external_key) > 0),\n CHECK (email_count >= 0),\n CHECK ((summary IS NULL) OR (length(summary) <= 4000)),\n CHECK ((summary_by IS NULL) OR (length(trim(summary_by)) > 0)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_emails","tbl_name": "cotton_emails","sql": "CREATE TABLE cotton_emails (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n thread_id TEXT NOT NULL,\n external_id TEXT NOT NULL,\n subject TEXT,\n from_email TEXT NOT NULL,\n from_name TEXT,\n recipients TEXT NOT NULL DEFAULT '[]',\n sent_at TEXT NOT NULL,\n body TEXT,\n snippet TEXT,\n attachments TEXT NOT NULL DEFAULT '[]',\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '', gmail_id TEXT, gmail_account TEXT, labels TEXT CHECK (labels IS NULL OR json_type(labels) = 'array'), unread INTEGER NOT NULL DEFAULT 0, starred INTEGER NOT NULL DEFAULT 0, in_inbox INTEGER NOT NULL DEFAULT 1, trashed_at TEXT, sync_state TEXT CHECK (sync_state IS NULL OR sync_state IN ('synced', 'pending')),\n _born TEXT,\n account TEXT,\n UNIQUE (workspace_id, external_id),\n CHECK (length(external_id) > 0),\n CHECK (length(from_email) > 0),\n CHECK (json_type(recipients) = 'array'),\n CHECK (json_type(attachments) = 'array'),\n FOREIGN KEY (thread_id) REFERENCES cotton_email_threads(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_event_attendees","tbl_name": "cotton_event_attendees","sql": "CREATE TABLE cotton_event_attendees (\n id TEXT PRIMARY KEY,\n event_id TEXT NOT NULL,\n email TEXT,\n phone TEXT,\n display_name TEXT,\n response TEXT NOT NULL DEFAULT 'needs_action',\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (response IN ('needs_action', 'accepted', 'declined', 'tentative')),\n FOREIGN KEY (event_id) REFERENCES cotton_events(id)\n )" }, {"kind": "table","name": "cotton_events","tbl_name": "cotton_events","sql": "CREATE TABLE cotton_events (\n id TEXT PRIMARY KEY,\n collection_id TEXT NOT NULL,\n title TEXT NOT NULL,\n notes TEXT,\n starts_at TEXT NOT NULL,\n ends_at TEXT,\n all_day INTEGER NOT NULL DEFAULT 0,\n rrule TEXT,\n location TEXT,\n source_inbox_id TEXT,\n gcal_id TEXT,\n gcal_etag TEXT,\n sync_state TEXT,\n organizer_is_self INTEGER NOT NULL DEFAULT 1,\n my_response TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '', series_id TEXT, original_starts_at TEXT, exdates TEXT CHECK (exdates IS NULL OR json_type(exdates) = 'array'), trashed_at TEXT,\n erase_requested_at TEXT,\n _born TEXT,\n ical_uid TEXT,\n account TEXT,\n on_google INTEGER NOT NULL DEFAULT 0, event_place TEXT, country TEXT, timezone TEXT,\n CHECK (on_google IN (0, 1)),\n CHECK (my_response IN ('needs_action', 'accepted', 'declined', 'tentative')),\n CHECK (sync_state IN ('synced', 'pending', 'conflict')),\n FOREIGN KEY (collection_id) REFERENCES cotton_collections(id)\n )" }, {"kind": "table","name": "cotton_feedback","tbl_name": "cotton_feedback","sql": "CREATE TABLE \"cotton_feedback\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n image_sha256 TEXT,\n image_ext TEXT,\n x REAL,\n y REAL,\n body TEXT NOT NULL,\n author_kind TEXT NOT NULL,\n author_user_id TEXT,\n author_label TEXT,\n person_id TEXT,\n same_as TEXT,\n share_id TEXT,\n app TEXT,\n context TEXT,\n status TEXT NOT NULL DEFAULT 'open',\n resolved_at TEXT,\n resolved_by_kind TEXT,\n resolved_by_label TEXT,\n resolution_note TEXT,\n parent_id TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK ((image_sha256 IS NULL) OR (app IS NOT NULL)),\n CHECK ((image_sha256 IS NULL) = (image_ext IS NULL)),\n CHECK ((x IS NULL) = (y IS NULL)),\n CHECK ((x IS NULL) OR (app IS NULL) OR (image_sha256 IS NOT NULL)),\n CHECK (length(trim(body)) > 0),\n CHECK (author_kind IN ('user', 'agent', 'guest')),\n CHECK ((author_kind = 'user') = (author_user_id IS NOT NULL)),\n CHECK ((author_kind = 'user') OR (author_label IS NOT NULL)),\n CHECK (same_as IS NULL OR same_as <> id),\n CHECK ((same_as IS NULL) OR (parent_id IS NULL)),\n CHECK (context IS NULL OR json_type(context) = 'object'),\n CHECK (status IN ('open', 'agreed', 'declined', 'shipped', 'resolved', 'dismissed')),\n CHECK (resolved_by_kind IN ('user', 'agent')),\n FOREIGN KEY (parent_id) REFERENCES cotton_feedback(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_filing_proposals","tbl_name": "cotton_filing_proposals","sql": "CREATE TABLE cotton_filing_proposals (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n owner TEXT NOT NULL,\n session TEXT NOT NULL,\n source TEXT NOT NULL,\n destination TEXT NOT NULL,\n kind TEXT NOT NULL CHECK(kind IN ('move','capture')),\n candidates TEXT NOT NULL CHECK(json_valid(candidates) AND json_type(candidates)='array'),\n arrivals TEXT NOT NULL CHECK(json_valid(arrivals) AND json_type(arrivals)='array'),\n revisions TEXT NOT NULL CHECK(json_valid(revisions) AND json_type(revisions)='object'),\n payload TEXT NOT NULL CHECK(json_valid(payload) AND json_type(payload)='object'),\n reason TEXT NOT NULL,\n status TEXT NOT NULL DEFAULT 'open' CHECK(status IN ('open','approved','declined','stale')),\n decided_at TEXT,\n answer TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY(workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n)" }, {"kind": "table","name": "cotton_goals","tbl_name": "cotton_goals","sql": "CREATE TABLE cotton_goals (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n title TEXT NOT NULL,\n why TEXT,\n target_date TEXT,\n status TEXT NOT NULL DEFAULT 'active',\n achieved_at TEXT,\n sort_order REAL NOT NULL DEFAULT 0,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n trashed_at TEXT,\n CHECK ((status = 'achieved') = (achieved_at IS NOT NULL)),\n CHECK (status IN ('active', 'paused', 'achieved', 'dropped')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_google_accounts","tbl_name": "cotton_google_accounts","sql": "CREATE TABLE cotton_google_accounts (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n google_email TEXT NOT NULL,\n refresh_token_enc TEXT,\n sync_token TEXT,\n channel_id TEXT,\n channel_resource_id TEXT,\n channel_expires_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, google_email),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_grant_rotations","tbl_name": "cotton_grant_rotations","sql": "CREATE TABLE cotton_grant_rotations (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n grant_id TEXT NOT NULL,\n generation INTEGER NOT NULL,\n digest TEXT NOT NULL,\n rotated_at TEXT NOT NULL,\n actor TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_group_members","tbl_name": "cotton_group_members","sql": "CREATE TABLE cotton_group_members (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n group_id TEXT NOT NULL,\n record_id TEXT NOT NULL,\n place REAL NOT NULL,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (group_id) REFERENCES cotton_groups(id)\n )" }, {"kind": "table","name": "cotton_groups","tbl_name": "cotton_groups","sql": "CREATE TABLE cotton_groups (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n table_id TEXT NOT NULL CHECK (length(trim(table_id)) > 0),\n name TEXT NOT NULL,\n filter TEXT,\n position REAL,\n picture TEXT,\n record_byline TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n deleted_at TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_home_arrangement","tbl_name": "cotton_home_arrangement","sql": "CREATE TABLE cotton_home_arrangement (\n workspace_id TEXT PRIMARY KEY,\n project_slugs TEXT NOT NULL DEFAULT '[]',\n tools TEXT NOT NULL DEFAULT '[]',\n view_ids TEXT NOT NULL DEFAULT '[]',\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (json_type(project_slugs) = 'array'),\n CHECK (json_type(tools) = 'array'),\n CHECK (json_type(view_ids) = 'array'),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_imports","tbl_name": "cotton_imports","sql": "CREATE TABLE cotton_imports (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n source TEXT NOT NULL CHECK (source IN ('contacts','chat_export','recording','passwords','messages','call_history','whatsapp_backup','photos','instagram_export')),\n title TEXT NOT NULL CHECK (length(trim(title)) > 0),\n added INTEGER NOT NULL DEFAULT 0,\n skipped INTEGER NOT NULL DEFAULT 0,\n device_id TEXT,\n finished_at TEXT NOT NULL,\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_inbox_items","tbl_name": "cotton_inbox_items","sql": "CREATE TABLE \"cotton_inbox_items\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n raw_text TEXT,\n audio_url TEXT,\n captured_at TEXT NOT NULL,\n route_status TEXT NOT NULL DEFAULT 'pending',\n routed_kind TEXT,\n routed_id TEXT,\n route_confidence TEXT,\n correction_of TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n transcript TEXT,\n route_reason TEXT,\n route_proposal TEXT,\n routed_records TEXT,\n route_plan TEXT,\n route_plan_user_edited INTEGER,\n -- v20: the chat sweep's two marks on a capture.\n swept_at TEXT,\n sweep_note TEXT,\n -- v75: where the thought was said (Spec 7): the tool's table when it\n -- was said inside one, and the record when it was said on a record's\n -- page. Both NULL for a thought said on the database's own page.\n -- capture.create refuses a record without its table; no constraint here, a\n -- synced row arrives column by column (tests/no_cross_column_checks.rs).\n said_table TEXT,\n said_record_id TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT, trashed_at TEXT,\n CHECK ((raw_text IS NOT NULL) OR (audio_url IS NOT NULL)),\n CHECK (route_status IN ('pending', 'routed', 'corrected', 'dismissed')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_invites","tbl_name": "cotton_invites","sql": "CREATE TABLE cotton_invites (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n secret_hash TEXT NOT NULL CHECK (length(secret_hash) > 0),\n rights TEXT NOT NULL CHECK (rights IN ('member','admin')),\n expires_at TEXT NOT NULL,\n made_by_person TEXT NOT NULL,\n p_sig TEXT NOT NULL,\n made_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT, recipient TEXT NULL, hands_over INTEGER NOT NULL DEFAULT 0 CHECK (hands_over IN (0,1)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_joined_places","tbl_name": "cotton_joined_places","sql": "CREATE TABLE cotton_joined_places (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n database_id TEXT NOT NULL,\n name TEXT,\n origin TEXT NOT NULL,\n server_device_id TEXT NOT NULL,\n joined_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, database_id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_links","tbl_name": "cotton_links","sql": "CREATE TABLE \"cotton_links\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n from_kind TEXT NOT NULL,\n from_id TEXT NOT NULL,\n to_kind TEXT NOT NULL,\n to_id TEXT NOT NULL,\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n to_database TEXT CHECK (to_database IS NULL OR length(to_database) > 0),\n CHECK (from_kind IN ('todo', 'event', 'note', 'person', 'person_note', 'thought', 'location', 'page', 'transaction', 'meeting', 'document', 'photo', 'video', 'news_edition', 'secret', 'repository', 'pull', 'issue', 'decision', 'email_thread')),\n CHECK (to_kind IN ('todo', 'event', 'note', 'person', 'person_note', 'thought', 'location', 'page', 'transaction', 'meeting', 'document', 'photo', 'video', 'news_edition', 'secret', 'repository', 'pull', 'issue', 'decision', 'email_thread')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_locations","tbl_name": "cotton_locations","sql": "CREATE TABLE cotton_locations (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n name TEXT NOT NULL,\n address TEXT,\n lat REAL,\n lng REAL,\n note TEXT,\n source_inbox_id TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n archived_at TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT, trashed_at TEXT, place TEXT, place_id TEXT, country TEXT, timezone TEXT, near TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_machine_runners","tbl_name": "cotton_machine_runners","sql": "CREATE TABLE cotton_machine_runners (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n device_id TEXT NOT NULL CHECK (length(trim(device_id)) > 0),\n enabled INTEGER NOT NULL DEFAULT 1 CHECK (enabled IN (0, 1)),\n labels_json TEXT NOT NULL DEFAULT '[\"cotton-checks-mac:host\"]',\n capacity INTEGER NOT NULL DEFAULT 1 CHECK (capacity BETWEEN 1 AND 4),\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT, ai_levels TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(ai_levels) AND json(ai_levels) IN ('[]', '[1]', '[2]', '[3]', '[1,2]', '[1,3]', '[2,1]', '[2,3]', '[3,1]', '[3,2]', '[1,2,3]', '[1,3,2]', '[2,1,3]', '[2,3,1]', '[3,1,2]', '[3,2,1]')),\n UNIQUE (workspace_id, device_id),\n CHECK (json_type(labels_json) = 'array'),\n CHECK (json_array_length(labels_json) BETWEEN 1 AND 3),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_mcp_audit","tbl_name": "cotton_mcp_audit","sql": "CREATE TABLE cotton_mcp_audit (\n id TEXT PRIMARY KEY,\n token_id TEXT NOT NULL,\n workspace_id TEXT NOT NULL,\n tool TEXT NOT NULL,\n args_summary TEXT,\n ok INTEGER NOT NULL DEFAULT 1,\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_mcp_tokens","tbl_name": "cotton_mcp_tokens","sql": "CREATE TABLE cotton_mcp_tokens (\n id TEXT PRIMARY KEY,\n owner_user_id TEXT NOT NULL,\n workspace_id TEXT NOT NULL,\n name TEXT NOT NULL,\n token_hash TEXT NOT NULL,\n scopes TEXT NOT NULL,\n expires_at TEXT,\n revoked_at TEXT,\n created_at TEXT NOT NULL,\n last_used_at TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n minted_by_device TEXT CHECK (minted_by_device IS NULL OR length(minted_by_device) > 0),\n UNIQUE (token_hash),\n CHECK (length(trim(name)) > 0),\n CHECK (length(token_hash) = 64 AND NOT token_hash GLOB '*[^0-9a-f]*'),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_media_album_items","tbl_name": "cotton_media_album_items","sql": "CREATE TABLE cotton_media_album_items (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n album_id TEXT NOT NULL,\n record_kind TEXT NOT NULL,\n record_id TEXT NOT NULL,\n added_by TEXT NOT NULL,\n sort_at TEXT NOT NULL,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '', origin_handle TEXT CHECK (origin_handle IS NULL OR length(origin_handle) > 0),\n _born TEXT,\n CHECK (record_kind IN ('photo', 'video')),\n CHECK (substr(record_id, 1, length(record_kind) + 1) = record_kind || ':'),\n CHECK (added_by IN ('derived', 'user')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (album_id) REFERENCES cotton_media_albums(id)\n )" }, {"kind": "table","name": "cotton_media_albums","tbl_name": "cotton_media_albums","sql": "CREATE TABLE cotton_media_albums (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n state TEXT NOT NULL DEFAULT 'open',\n decided_at TEXT,\n title TEXT NOT NULL,\n title_by TEXT NOT NULL DEFAULT 'derived',\n starts_at TEXT NOT NULL,\n ends_at TEXT NOT NULL,\n home_label TEXT,\n cover_id TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '', origin_handle TEXT CHECK (origin_handle IS NULL OR length(origin_handle) > 0),\n _born TEXT, trashed_at TEXT,\n CHECK (kind IN ('trip', 'event')),\n CHECK (state IN ('open', 'kept', 'dismissed')),\n CHECK ((state = 'open') = (decided_at IS NULL)),\n CHECK (title_by IN ('derived', 'user')),\n CHECK (starts_at <= ends_at),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_media_backups","tbl_name": "cotton_media_backups","sql": "CREATE TABLE cotton_media_backups (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n object_key TEXT NOT NULL,\n serving_epoch INTEGER NOT NULL,\n verified_at TEXT NOT NULL,\n missing_at TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE(workspace_id, serving_epoch, object_key),\n FOREIGN KEY(workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n)" }, {"kind": "table","name": "cotton_media_duplicates","tbl_name": "cotton_media_duplicates","sql": "CREATE TABLE cotton_media_duplicates (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n record_kind TEXT NOT NULL,\n keep_id TEXT NOT NULL,\n copy_id TEXT NOT NULL,\n distance INTEGER NOT NULL,\n method TEXT NOT NULL,\n state TEXT NOT NULL DEFAULT 'open',\n decided_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (record_kind IN ('photo', 'video')),\n CHECK (keep_id <> copy_id),\n CHECK (substr(keep_id, 1, length(record_kind) + 1) = record_kind || ':'),\n CHECK (substr(copy_id, 1, length(record_kind) + 1) = record_kind || ':'),\n CHECK (distance >= 0 AND distance <= 64),\n CHECK (method IN ('phash', 'featureprint')),\n CHECK (state IN ('open', 'confirmed', 'dismissed')),\n CHECK ((state = 'open') = (decided_at IS NULL)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_media_erasures","tbl_name": "cotton_media_erasures","sql": "CREATE TABLE cotton_media_erasures (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n key TEXT NOT NULL,\n record_table TEXT NOT NULL,\n record_id TEXT NOT NULL,\n erased_at TEXT NOT NULL,\n actor TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_media_faces","tbl_name": "cotton_media_faces","sql": "CREATE TABLE cotton_media_faces (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n record_kind TEXT NOT NULL,\n record_id TEXT NOT NULL,\n source TEXT NOT NULL,\n source_id TEXT NOT NULL,\n x REAL NOT NULL,\n y REAL NOT NULL,\n w REAL NOT NULL,\n h REAL NOT NULL,\n quality REAL,\n cluster_id TEXT,\n person_id TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '', suggested_person_id TEXT, suggested_distance REAL CHECK (suggested_distance IS NULL OR (suggested_distance >= 0 AND suggested_distance <= 2)), suggestion_dismissed_at TEXT,\n _born TEXT, embedding TEXT CHECK (embedding IS NULL OR length(embedding) > 0), embedding_model TEXT CHECK (embedding_model IS NULL OR length(embedding_model) > 0), person_by TEXT CHECK (person_by IS NULL OR person_by = 'match'),\n CHECK (record_kind IN ('photo', 'video')),\n CHECK (substr(record_id, 1, length(record_kind) + 1) = record_kind || ':'),\n CHECK (source IN ('apple', 'cotton')),\n CHECK (x >= 0 AND x <= 1 AND y >= 0 AND y <= 1),\n CHECK (w > 0 AND w <= 1 AND h > 0 AND h <= 1),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_media_holdings","tbl_name": "cotton_media_holdings","sql": "CREATE TABLE cotton_media_holdings (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n object_key TEXT NOT NULL,\n device_id TEXT NOT NULL,\n tier TEXT NOT NULL CHECK (tier IN ('thumb','display','original')),\n bytes INTEGER NOT NULL,\n verified_at TEXT,\n dropped_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, object_key, device_id, tier),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_media_sightings","tbl_name": "cotton_media_sightings","sql": "CREATE TABLE \"cotton_media_sightings\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n record_kind TEXT NOT NULL,\n record_id TEXT NOT NULL,\n source TEXT NOT NULL,\n source_id TEXT,\n thread_id TEXT,\n key TEXT NOT NULL,\n seen_at TEXT NOT NULL,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (record_kind IN ('photo', 'video')),\n CHECK (substr(record_id, 1, length(record_kind) + 1) = record_kind || ':'),\n CHECK (source IN ('message', 'share', 'library', 'apple_library', 'email')),\n CHECK ((source = 'message') = (thread_id IS NOT NULL)),\n CHECK (source NOT IN ('message', 'apple_library', 'email') OR source_id IS NOT NULL),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_meeting_utterances","tbl_name": "cotton_meeting_utterances","sql": "CREATE TABLE cotton_meeting_utterances (\n id TEXT PRIMARY KEY,\n meeting_id TEXT NOT NULL,\n seq INTEGER NOT NULL,\n speaker_label TEXT NOT NULL,\n t0_ms INTEGER NOT NULL,\n t1_ms INTEGER NOT NULL,\n text TEXT NOT NULL,\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (meeting_id, seq),\n CHECK (seq >= 0),\n CHECK (t1_ms >= t0_ms),\n CHECK (t0_ms >= 0),\n CHECK (t1_ms >= 0),\n FOREIGN KEY (meeting_id) REFERENCES cotton_meetings(id)\n )" }, {"kind": "table","name": "cotton_meetings","tbl_name": "cotton_meetings","sql": "CREATE TABLE cotton_meetings (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n title TEXT,\n status TEXT NOT NULL DEFAULT 'uploading',\n source TEXT NOT NULL,\n started_at TEXT NOT NULL,\n ended_at TEXT,\n duration_seconds INTEGER,\n language TEXT,\n event_id TEXT,\n speakers TEXT NOT NULL DEFAULT '[]',\n summary_md TEXT,\n decisions TEXT NOT NULL DEFAULT '[]',\n vendor TEXT,\n vendor_job_id TEXT,\n poll_attempts INTEGER NOT NULL DEFAULT 0,\n status_changed_at TEXT NOT NULL,\n audio_deleted_at TEXT,\n failed_stage TEXT,\n error_code TEXT,\n segments TEXT NOT NULL DEFAULT '[]',\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n trashed_at TEXT,\n event_database TEXT CHECK (event_database IS NULL OR length(event_database) > 0),\n CHECK ((duration_seconds IS NULL) OR (duration_seconds >= 0)),\n CHECK ((status = 'failed') = (failed_stage IS NOT NULL)),\n CHECK (failed_stage IS NULL OR failed_stage IN ('submit', 'transcribe', 'summarize')),\n CHECK (poll_attempts >= 0),\n CHECK (source IN ('recorded', 'imported')),\n CHECK (status IN ('recording', 'uploading', 'queued', 'transcribing', 'summarizing', 'ready', 'failed')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_member_person_claims","tbl_name": "cotton_member_person_claims","sql": "CREATE TABLE cotton_member_person_claims (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n admission_id TEXT NOT NULL CHECK (length(admission_id) > 0),\n person_key TEXT NOT NULL CHECK (length(person_key) > 0),\n person_id TEXT NOT NULL CHECK (length(person_id) > 0),\n p_sig TEXT NOT NULL,\n claimed_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_memories","tbl_name": "cotton_memories","sql": "CREATE TABLE \"cotton_memories\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n slug TEXT NOT NULL,\n title TEXT NOT NULL,\n body TEXT NOT NULL DEFAULT '',\n status TEXT NOT NULL DEFAULT 'active',\n machine TEXT,\n visibility TEXT NOT NULL DEFAULT 'private',\n origin_kind TEXT NOT NULL,\n origin_label TEXT,\n reviewed_at TEXT,\n source_external_id TEXT,\n archived_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n source TEXT,\n superseded_by TEXT CHECK (superseded_by IS NULL OR status = 'archived'),\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK ((status = 'archived') = (archived_at IS NOT NULL)),\n CHECK (length(body) <= 4000),\n CHECK ((machine IS NULL) OR (length(trim(machine)) > 0)),\n CHECK (origin_kind IN ('user', 'agent')),\n CHECK ((origin_kind = 'agent') = (origin_label IS NOT NULL)),\n CHECK (length(slug) BETWEEN 1 AND 64 AND slug GLOB '[a-z0-9]*' AND NOT slug GLOB '*[^a-z0-9-]*'),\n CHECK (status IN ('active', 'archived')),\n CHECK ((length(trim(title)) > 0) AND (length(title) <= 280)),\n CHECK (visibility IN ('private', 'shared', 'public')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_memory_projects","tbl_name": "cotton_memory_projects","sql": "CREATE TABLE cotton_memory_projects (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n slug TEXT NOT NULL,\n name TEXT NOT NULL,\n repos TEXT NOT NULL DEFAULT '[]',\n brand TEXT CHECK (brand IS NULL OR json_type(brand) = 'object'),\n description TEXT,\n summary_updated_at TEXT,\n summary_by TEXT,\n status TEXT NOT NULL DEFAULT 'active',\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '', origin_handle TEXT CHECK (origin_handle IS NULL OR length(origin_handle) > 0),\n _born TEXT,\n section_order TEXT CHECK (section_order IS NULL OR json_type(section_order) = 'array'), trashed_at TEXT,\n UNIQUE (workspace_id, slug),\n CHECK (length(trim(name)) > 0),\n CHECK (json_type(repos) = 'array'),\n CHECK (length(slug) BETWEEN 1 AND 64 AND slug GLOB '[a-z0-9]*' AND NOT slug GLOB '*[^a-z0-9-]*'),\n CHECK (status IN ('active', 'archived')),\n CHECK ((summary_by IS NULL) OR (length(trim(summary_by)) > 0)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_money_accounts","tbl_name": "cotton_money_accounts","sql": "CREATE TABLE \"cotton_money_accounts\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n subtype TEXT NOT NULL,\n name TEXT NOT NULL,\n counterparty_person_id TEXT,\n currency TEXT NOT NULL,\n institution TEXT,\n number_mask TEXT,\n is_default INTEGER NOT NULL DEFAULT 0,\n is_pooled INTEGER CHECK (is_pooled IS NULL OR is_pooled IN (0,1)),\n archived_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT, trashed_at TEXT,\n CHECK (kind IN ('asset', 'liability', 'income', 'expense', 'equity', 'loan')),\n CHECK (subtype IN ('bank', 'cash', 'credit_card', 'wallet', 'receivable', 'payable', 'loan', 'lent_out', 'fixed_asset')),\n FOREIGN KEY (counterparty_person_id) REFERENCES cotton_people(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_money_evidence","tbl_name": "cotton_money_evidence","sql": "CREATE TABLE cotton_money_evidence (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n transaction_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n ref_id TEXT,\n excerpt TEXT NOT NULL,\n source_label TEXT,\n attached_by TEXT NOT NULL,\n attached_by_label TEXT,\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n trashed_at TEXT,\n CHECK (attached_by IN ('import', 'assistant', 'owner')),\n CHECK (kind IN ('statement_line', 'document', 'message', 'email', 'external')),\n CHECK ((kind = 'external') OR (ref_id IS NOT NULL)),\n FOREIGN KEY (transaction_id) REFERENCES cotton_money_transactions(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_money_statement_lines","tbl_name": "cotton_money_statement_lines","sql": "CREATE TABLE cotton_money_statement_lines (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n statement_id TEXT NOT NULL,\n page INTEGER NOT NULL,\n line_no INTEGER NOT NULL,\n posted_on TEXT NOT NULL,\n text TEXT NOT NULL,\n amount_minor INTEGER NOT NULL,\n direction TEXT NOT NULL,\n balance_after_minor INTEGER,\n reference TEXT,\n fingerprint TEXT NOT NULL,\n ignored_reason TEXT,\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (statement_id, line_no),\n CHECK (amount_minor > 0),\n CHECK (direction IN ('in', 'out')),\n CHECK (length(trim(text)) > 0),\n CHECK (line_no >= 1),\n CHECK (page >= 1),\n FOREIGN KEY (statement_id) REFERENCES cotton_money_statements(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_money_statements","tbl_name": "cotton_money_statements","sql": "CREATE TABLE cotton_money_statements (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n document_id TEXT NOT NULL,\n account_id TEXT,\n kind TEXT NOT NULL,\n period_start TEXT,\n period_end TEXT,\n opening_balance_minor INTEGER,\n closing_balance_minor INTEGER,\n currency TEXT NOT NULL,\n read_status TEXT NOT NULL DEFAULT 'pending',\n read_error TEXT,\n read_by TEXT,\n read_at TEXT,\n line_count INTEGER NOT NULL DEFAULT 0,\n sum_in_minor INTEGER NOT NULL DEFAULT 0,\n sum_out_minor INTEGER NOT NULL DEFAULT 0,\n balance_check TEXT NOT NULL DEFAULT 'unknown',\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (document_id),\n CHECK (balance_check IN ('ok', 'mismatch', 'unknown')),\n CHECK (kind IN ('bank', 'credit_card')),\n CHECK (line_count >= 0),\n CHECK ((period_start IS NULL) OR (period_end IS NULL) OR (period_end >= period_start)),\n CHECK (read_status IN ('pending', 'read', 'mismatch', 'failed')),\n FOREIGN KEY (document_id) REFERENCES cotton_documents(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_money_transactions","tbl_name": "cotton_money_transactions","sql": "CREATE TABLE \"cotton_money_transactions\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n occurred_on TEXT NOT NULL,\n description TEXT NOT NULL DEFAULT '',\n payee_text TEXT,\n account_id TEXT,\n counterparty_person_id TEXT,\n amount_minor INTEGER,\n amount_known INTEGER NOT NULL DEFAULT 1 CHECK (amount_known IN (0,1)),\n direction TEXT NOT NULL DEFAULT 'out' CHECK (direction IN ('in','out')),\n currency TEXT,\n for_period TEXT NOT NULL DEFAULT '',\n status TEXT NOT NULL DEFAULT 'actual' CHECK (status IN ('actual','expected')),\n certainty TEXT CHECK (certainty IS NULL OR certainty IN ('fixed','expected','estimate')),\n repeat TEXT NOT NULL DEFAULT 'none' CHECK (repeat IN ('none','monthly')),\n repeat_day INTEGER CHECK (repeat_day IS NULL OR repeat_day BETWEEN 1 AND 31),\n between_us INTEGER NOT NULL DEFAULT 0 CHECK (between_us IN (0,1)),\n moves_money INTEGER NOT NULL DEFAULT 1 CHECK (moves_money IN (0,1)),\n tag TEXT,\n transfer_of TEXT,\n source TEXT NOT NULL DEFAULT 'manual',\n external_hash TEXT,\n notes TEXT,\n settles_transaction_id TEXT,\n due_date TEXT,\n source_inbox_id TEXT,\n created_by TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n trashed_at TEXT,\n CHECK ((settles_transaction_id IS NULL) OR (settles_transaction_id <> id)),\n CHECK (source IN ('capture', 'manual', 'import', 'system', 'schedule', 'migration', 'statement', 'external')),\n FOREIGN KEY (account_id) REFERENCES cotton_money_accounts(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_moods","tbl_name": "cotton_moods","sql": "CREATE TABLE cotton_moods (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n at TEXT NOT NULL,\n line TEXT,\n emotions TEXT NOT NULL DEFAULT '[]',\n emotions_by TEXT NOT NULL DEFAULT 'assistant',\n local_day TEXT NOT NULL,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n trashed_at TEXT,\n CHECK (line IS NULL OR (length(trim(line)) > 0 AND length(line) <= 1000)),\n CHECK (json_type(emotions) = 'array'),\n CHECK (emotions_by IN ('user', 'assistant')),\n CHECK (local_day GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]'),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_msg_contact_handles","tbl_name": "cotton_msg_contact_handles","sql": "CREATE TABLE \"cotton_msg_contact_handles\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n contact_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n value TEXT NOT NULL,\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, kind, value),\n CHECK (kind IN ('phone', 'email', 'cotton', 'instagram', 'facebook', 'linkedin')),\n CHECK (kind <> 'phone' OR (length(value) BETWEEN 8 AND 15 AND NOT value GLOB '*[^0-9]*')),\n CHECK (kind <> 'email' OR (value = lower(value) AND value LIKE '%_@_%' AND value NOT GLOB '* *')),\n CHECK (kind <> 'cotton' OR (length(value) BETWEEN 2 AND 31 AND value GLOB '[a-z0-9]*' AND NOT value GLOB '*[^a-z0-9-]*' AND value GLOB '*[^0-9]*')),\n FOREIGN KEY (contact_id) REFERENCES cotton_msg_contacts(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_msg_contacts","tbl_name": "cotton_msg_contacts","sql": "CREATE TABLE \"cotton_msg_contacts\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n phone_e164 TEXT,\n display_name TEXT,\n person_id TEXT,\n auth_user_id TEXT,\n vip INTEGER NOT NULL DEFAULT 0,\n muted INTEGER NOT NULL DEFAULT 0,\n blocked INTEGER NOT NULL DEFAULT 0,\n on_cotton_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n avatar_key TEXT,\n UNIQUE (workspace_id, phone_e164),\n CHECK (phone_e164 IS NULL OR (length(phone_e164) BETWEEN 8 AND 15 AND NOT phone_e164 GLOB '*[^0-9]*')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_msg_messages","tbl_name": "cotton_msg_messages","sql": "CREATE TABLE \"cotton_msg_messages\" (\n id TEXT PRIMARY KEY,\n thread_id TEXT NOT NULL,\n workspace_id TEXT NOT NULL,\n direction TEXT NOT NULL,\n channel TEXT NOT NULL,\n origin TEXT NOT NULL,\n body TEXT,\n media TEXT NOT NULL DEFAULT '[]',\n external_id TEXT,\n sent_at TEXT NOT NULL,\n created_at TEXT NOT NULL,\n read_at TEXT,\n reply_to_id TEXT,\n reply_to_external_id TEXT,\n reactions TEXT NOT NULL DEFAULT '[]',\n meta TEXT NOT NULL DEFAULT '{}',\n sender_contact_id TEXT,\n sender_participant_id TEXT,\n seq INTEGER,\n edited_at TEXT,\n deleted_at TEXT,\n forward_of_id TEXT,\n mentions TEXT NOT NULL DEFAULT '[]',\n starred_at TEXT,\n hidden_at TEXT,\n send_state TEXT,\n send_error TEXT,\n send_attempts INTEGER NOT NULL DEFAULT 0,\n trashed_at TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (channel IN ('cotton', 'whatsapp', 'imessage', 'sms', 'instagram')),\n CHECK (send_state IS NULL OR send_state IN ('queued', 'sending', 'sent', 'delivered', 'read', 'failed')),\n CHECK (direction IN ('in', 'out')),\n CHECK ((deleted_at IS NOT NULL) OR (trim(COALESCE(body, '')) <> '') OR (json_array_length(media) > 0)),\n CHECK (json_type(media) = 'array'),\n CHECK (json_type(meta) = 'object'),\n CHECK (origin IN ('live', 'imported')),\n CHECK (json_type(reactions) = 'array'),\n CHECK (json_type(mentions) = 'array'),\n FOREIGN KEY (thread_id) REFERENCES cotton_msg_threads(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_msg_owner_settings","tbl_name": "cotton_msg_owner_settings","sql": "CREATE TABLE cotton_msg_owner_settings (\n workspace_id TEXT PRIMARY KEY,\n handle TEXT NOT NULL,\n display_name TEXT NOT NULL,\n avatar_url TEXT,\n availability_copy TEXT,\n allow_new_contacts INTEGER NOT NULL DEFAULT 1,\n app_download_url TEXT,\n read_receipts INTEGER NOT NULL DEFAULT 1,\n discoverable INTEGER NOT NULL DEFAULT 1,\n last_seen_visible INTEGER NOT NULL DEFAULT 1,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '', share_requests TEXT NOT NULL DEFAULT 'contacts_direct' CHECK (share_requests IN ('contacts_direct','ask_always')),\n _born TEXT,\n CHECK (handle NOT IN ('inbox', 'api', 'assets', 'admin', 'settings', 'download', 'privacy', 'terms', 'about', 'app', 'm')),\n CHECK (length(handle) BETWEEN 3 AND 30 AND NOT handle GLOB '*[^a-z0-9-]*'),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_msg_reactions","tbl_name": "cotton_msg_reactions","sql": "CREATE TABLE cotton_msg_reactions (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n thread_id TEXT NOT NULL,\n message_id TEXT NOT NULL,\n actor TEXT NOT NULL,\n emoji TEXT NOT NULL,\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (message_id, actor),\n CHECK (trim(actor) <> ''),\n CHECK (trim(emoji) <> '' AND length(emoji) <= 8),\n FOREIGN KEY (message_id) REFERENCES cotton_msg_messages(id),\n FOREIGN KEY (thread_id) REFERENCES cotton_msg_threads(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_msg_receipts","tbl_name": "cotton_msg_receipts","sql": "CREATE TABLE \"cotton_msg_receipts\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n thread_id TEXT NOT NULL,\n phone TEXT NOT NULL,\n delivered_seq INTEGER NOT NULL DEFAULT 0,\n read_seq INTEGER NOT NULL DEFAULT 0,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (thread_id, phone),\n CHECK ((length(phone) BETWEEN 8 AND 15 AND NOT phone GLOB '*[^0-9]*') OR (length(phone) BETWEEN 2 AND 31 AND phone GLOB '[a-z0-9]*' AND NOT phone GLOB '*[^a-z0-9-]*' AND phone GLOB '*[^0-9]*')),\n FOREIGN KEY (thread_id) REFERENCES cotton_msg_threads(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_msg_thread_filings","tbl_name": "cotton_msg_thread_filings","sql": "CREATE TABLE cotton_msg_thread_filings (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n thread_id TEXT NOT NULL,\n database_id TEXT NOT NULL CHECK (length(trim(database_id)) > 0),\n state TEXT NOT NULL DEFAULT 'filed' CHECK (state IN ('filed','paused','unfiled')),\n paused_by TEXT,\n copied_through TEXT,\n filed_at TEXT NOT NULL,\n unfiled_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (thread_id) REFERENCES cotton_msg_threads(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_msg_thread_marks","tbl_name": "cotton_msg_thread_marks","sql": "CREATE TABLE cotton_msg_thread_marks (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n database_id TEXT NOT NULL CHECK (length(trim(database_id)) > 0),\n thread_id TEXT NOT NULL CHECK (length(trim(thread_id)) > 0),\n pinned_at TEXT,\n muted_until TEXT,\n archived INTEGER NOT NULL DEFAULT 0 CHECK (archived IN (0,1)),\n cleared_before TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_msg_thread_participants","tbl_name": "cotton_msg_thread_participants","sql": "CREATE TABLE \"cotton_msg_thread_participants\" (\n id TEXT PRIMARY KEY,\n thread_id TEXT NOT NULL,\n workspace_id TEXT NOT NULL,\n contact_id TEXT,\n display_name TEXT,\n created_at TEXT NOT NULL,\n role TEXT NOT NULL DEFAULT 'member',\n left_at TEXT,\n is_self INTEGER NOT NULL DEFAULT 0,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (role IN ('admin', 'member')),\n CHECK ((is_self = 1) OR (contact_id IS NOT NULL) OR (NULLIF(trim(COALESCE(display_name, '')), '') IS NOT NULL)),\n FOREIGN KEY (contact_id) REFERENCES cotton_msg_contacts(id),\n FOREIGN KEY (thread_id) REFERENCES cotton_msg_threads(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_msg_threads","tbl_name": "cotton_msg_threads","sql": "CREATE TABLE \"cotton_msg_threads\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n contact_id TEXT,\n kind TEXT NOT NULL DEFAULT 'dm',\n last_message_at TEXT,\n last_message_preview TEXT,\n archived INTEGER NOT NULL DEFAULT 0,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n title TEXT,\n external_key TEXT,\n _hlc TEXT NOT NULL DEFAULT '', photo_key TEXT, description TEXT, created_by_phone TEXT, read_seq INTEGER NOT NULL DEFAULT 0, delivered_seq INTEGER NOT NULL DEFAULT 0, muted_until TEXT, pinned_at TEXT, unread_marked_at TEXT, draft TEXT, draft_reply_to_id TEXT, cleared_before TEXT, summary TEXT CHECK ((summary IS NULL) OR (length(summary) <= 4000)), summary_updated_at TEXT, summary_by TEXT CHECK ((summary_by IS NULL) OR (length(trim(summary_by)) > 0)),\n _born TEXT,\n trashed_at TEXT,\n CHECK (kind IN ('dm', 'group')),\n CHECK (((kind = 'dm') AND ((contact_id IS NOT NULL) OR (NULLIF(trim(COALESCE(title, '')), '') IS NOT NULL))) OR ((kind = 'group') AND (contact_id IS NULL) AND (NULLIF(trim(COALESCE(title, '')), '') IS NOT NULL))),\n FOREIGN KEY (contact_id) REFERENCES cotton_msg_contacts(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_news_editions","tbl_name": "cotton_news_editions","sql": "CREATE TABLE cotton_news_editions (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n status TEXT NOT NULL DEFAULT 'queued',\n trigger_kind TEXT NOT NULL,\n edition_label TEXT,\n covered_from TEXT NOT NULL,\n covered_to TEXT,\n story_count INTEGER,\n read_minutes INTEGER,\n quiet TEXT NOT NULL DEFAULT '[]',\n notes TEXT NOT NULL DEFAULT '[]',\n model TEXT,\n opened_at TEXT,\n status_changed_at TEXT NOT NULL,\n failed_stage TEXT,\n error_code TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK ((status = 'failed') = (failed_stage IS NOT NULL)),\n CHECK (failed_stage IS NULL OR failed_stage IN ('harvest', 'write')),\n CHECK ((read_minutes IS NULL) OR (read_minutes >= 0)),\n CHECK (status IN ('queued', 'harvesting', 'writing', 'ready', 'failed')),\n CHECK ((story_count IS NULL) OR (story_count >= 0)),\n CHECK (trigger_kind IN ('scheduled', 'manual', 'stale_open')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_news_seen","tbl_name": "cotton_news_seen","sql": "CREATE TABLE cotton_news_seen (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n topic_id TEXT NOT NULL,\n \"key\" TEXT NOT NULL,\n title_hash TEXT,\n url TEXT,\n source TEXT NOT NULL,\n first_seen_at TEXT NOT NULL,\n story_id TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, \"key\"),\n CHECK (source IN ('google_news', 'hn', 'brave', 'rss')),\n FOREIGN KEY (topic_id) REFERENCES cotton_news_topics(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_news_settings","tbl_name": "cotton_news_settings","sql": "CREATE TABLE cotton_news_settings (\n workspace_id TEXT PRIMARY KEY,\n edition_times TEXT NOT NULL DEFAULT '[\"07:00\", \"19:00\"]',\n timezone TEXT NOT NULL,\n stale_after_minutes INTEGER NOT NULL DEFAULT 360,\n stale_refresh INTEGER NOT NULL DEFAULT 1,\n notify INTEGER NOT NULL DEFAULT 1,\n next_edition_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (json_type(edition_times) = 'array'),\n CHECK (stale_after_minutes > 0),\n CHECK (length(trim(timezone)) > 0),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_news_stories","tbl_name": "cotton_news_stories","sql": "CREATE TABLE cotton_news_stories (\n id TEXT PRIMARY KEY,\n edition_id TEXT NOT NULL,\n topic_id TEXT,\n rank INTEGER NOT NULL,\n headline TEXT NOT NULL,\n lede TEXT NOT NULL,\n bullets TEXT NOT NULL DEFAULT '[]',\n sources TEXT NOT NULL DEFAULT '[]',\n why_care TEXT,\n read_minutes INTEGER,\n opened_at TEXT,\n feedback TEXT,\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (feedback IS NULL OR feedback IN ('less', 'more')),\n CHECK (rank >= 0),\n CHECK ((read_minutes IS NULL) OR (read_minutes >= 0)),\n FOREIGN KEY (edition_id) REFERENCES cotton_news_editions(id)\n )" }, {"kind": "table","name": "cotton_news_topics","tbl_name": "cotton_news_topics","sql": "CREATE TABLE cotton_news_topics (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n name TEXT NOT NULL,\n brief TEXT NOT NULL DEFAULT '',\n exclusions TEXT NOT NULL DEFAULT '',\n kind TEXT NOT NULL,\n source_url TEXT,\n active INTEGER NOT NULL DEFAULT 1,\n paused_reason TEXT,\n unopened_streak INTEGER NOT NULL DEFAULT 0,\n last_new_at TEXT,\n sort_order REAL NOT NULL DEFAULT 0,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n trashed_at TEXT,\n CHECK (kind IN ('search', 'source')),\n CHECK (length(trim(name)) > 0),\n CHECK (paused_reason IS NULL OR paused_reason IN ('user', 'auto')),\n CHECK ((source_url IS NULL) OR (kind = 'source')),\n CHECK (unopened_streak >= 0),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_note_attachments","tbl_name": "cotton_note_attachments","sql": "CREATE TABLE cotton_note_attachments (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n note_id TEXT NOT NULL,\n record_kind TEXT NOT NULL,\n record_id TEXT NOT NULL,\n position INTEGER NOT NULL,\n caption TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n origin_handle TEXT CHECK (origin_handle IS NULL OR length(origin_handle) > 0),\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (note_id, record_kind, record_id),\n CHECK (record_kind IN ('photo', 'video', 'document')),\n CHECK (length(record_id) > 0),\n CHECK (position >= 0),\n CHECK (caption IS NULL OR length(caption) <= 500),\n FOREIGN KEY (note_id) REFERENCES cotton_notes(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_notes","tbl_name": "cotton_notes","sql": "CREATE TABLE cotton_notes (\n id TEXT PRIMARY KEY,\n kind TEXT NOT NULL DEFAULT 'note',\n title TEXT,\n body TEXT NOT NULL DEFAULT '',\n journal_date TEXT,\n project_id TEXT,\n published_at TEXT,\n public_slug TEXT,\n source_inbox_id TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n archived_at TEXT,\n trashed_at TEXT,\n author_kind TEXT NOT NULL DEFAULT 'user',\n author_label TEXT,\n managed_by TEXT,\n external_id TEXT,\n source_hash TEXT,\n workspace_id TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '', origin_handle TEXT CHECK (origin_handle IS NULL OR length(origin_handle) > 0),\n _born TEXT,\n pinned INTEGER NOT NULL DEFAULT 0 CHECK (pinned IN (0, 1)),\n CHECK (author_kind IN ('user', 'agent')),\n CHECK ((author_kind = 'agent') = (author_label IS NOT NULL)),\n CHECK (kind IN ('note', 'journal')),\n CHECK ((managed_by IS NULL) OR (external_id IS NOT NULL)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_oauth_clients","tbl_name": "cotton_oauth_clients","sql": "CREATE TABLE cotton_oauth_clients (\n client_id TEXT PRIMARY KEY,\n kind TEXT NOT NULL,\n secret_hash TEXT,\n metadata_json TEXT NOT NULL,\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT\n )" }, {"kind": "table","name": "cotton_oauth_grants","tbl_name": "cotton_oauth_grants","sql": "CREATE TABLE cotton_oauth_grants (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n client_id TEXT NOT NULL,\n client_name TEXT NOT NULL,\n scope TEXT NOT NULL,\n created_at TEXT NOT NULL,\n revoked_at TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n token_id TEXT,\n refresh_generation INTEGER NOT NULL DEFAULT 0,\n refresh_rotated_at TEXT,\n refresh_digest TEXT CHECK (refresh_digest IS NULL OR length(refresh_digest) BETWEEN 77 AND 204),\n minted_by TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_outages","tbl_name": "cotton_outages","sql": "CREATE TABLE cotton_outages (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n kind TEXT NOT NULL CHECK (length(trim(kind)) > 0),\n condition TEXT NOT NULL CHECK (length(trim(condition)) > 0),\n machine TEXT,\n title TEXT NOT NULL CHECK (length(trim(title)) > 0),\n effect TEXT NOT NULL CHECK (length(trim(effect)) > 0),\n doing TEXT NOT NULL CHECK (length(trim(doing)) > 0),\n started_at TEXT NOT NULL,\n ended_at TEXT,\n told_open_at TEXT,\n told_close_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_pages","tbl_name": "cotton_pages","sql": "CREATE TABLE cotton_pages (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n url TEXT NOT NULL,\n host TEXT NOT NULL,\n title TEXT,\n read_at TEXT,\n source_inbox_id TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n archived_at TEXT,\n text_state TEXT CHECK (text_state IS NULL OR text_state IN ('kept', 'unreachable', 'unreadable')),\n state TEXT NOT NULL DEFAULT 'unread' CHECK (state IN ('unread', 'reading', 'read')),\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n text TEXT, trashed_at TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_people","tbl_name": "cotton_people","sql": "CREATE TABLE \"cotton_people\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n full_name TEXT NOT NULL,\n org TEXT,\n role_title TEXT,\n city TEXT,\n summary TEXT,\n summary_updated_at TEXT,\n summary_by TEXT,\n contact_source TEXT NOT NULL DEFAULT 'manual',\n device_contact_id TEXT,\n archived_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n birth_month INTEGER,\n birth_day INTEGER,\n birth_year INTEGER,\n timezone TEXT,\n avatar_url TEXT,\n avatar_key TEXT,\n device_contact_snapshot TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n city_filled_at TEXT,\n avatar_photo_id TEXT, trashed_at TEXT, language TEXT NOT NULL DEFAULT 'en' CHECK (length(language) BETWEEN 2 AND 3 AND language NOT GLOB '*[^a-z]*'), face_embedding TEXT CHECK (face_embedding IS NULL OR length(face_embedding) > 0), face_embedding_model TEXT CHECK (face_embedding_model IS NULL OR length(face_embedding_model) > 0), face_embedding_from TEXT CHECK (face_embedding_from IS NULL OR length(face_embedding_from) > 0), city_place TEXT, country TEXT,\n CHECK ((birth_day IS NULL) OR ((birth_day >= 1) AND (birth_day <= 31))),\n CHECK ((birth_month IS NULL) OR ((birth_month >= 1) AND (birth_month <= 12))),\n CHECK (((birth_month IS NOT NULL) + (birth_day IS NOT NULL)) IN (0, 2)),\n CHECK (contact_source IN ('import', 'manual', 'apple_library')),\n CHECK ((summary IS NULL) OR (length(summary) <= 4000)),\n CHECK ((summary_by IS NULL) OR (length(trim(summary_by)) > 0)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_person_handles","tbl_name": "cotton_person_handles","sql": "CREATE TABLE cotton_person_handles (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n person_id TEXT NOT NULL,\n kind TEXT NOT NULL CHECK (kind IN ('phone','email','instagram','facebook','linkedin')),\n value TEXT NOT NULL CHECK (length(trim(value)) > 0),\n normalised TEXT NOT NULL CHECK (length(normalised) > 0),\n source TEXT NOT NULL CHECK (source IN ('manual','contacts','import','suggestion','whatsapp','instagram','facebook','linkedin')),\n verified_at TEXT,\n position INTEGER NOT NULL DEFAULT 0,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT, trashed_at TEXT,\n FOREIGN KEY (person_id) REFERENCES cotton_people(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_person_keys","tbl_name": "cotton_person_keys","sql": "CREATE TABLE cotton_person_keys (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n public_key TEXT NOT NULL,\n name TEXT NOT NULL DEFAULT '',\n sealed_private TEXT NOT NULL,\n vmk_version INTEGER NOT NULL,\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_person_languages","tbl_name": "cotton_person_languages","sql": "CREATE TABLE cotton_person_languages (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n person_id TEXT NOT NULL,\n language TEXT NOT NULL CHECK (length(trim(language)) > 0),\n proficiency TEXT NOT NULL DEFAULT 'fluent' CHECK (proficiency IN ('native','fluent','conversational','basic')),\n position INTEGER NOT NULL DEFAULT 0,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT, trashed_at TEXT,\n FOREIGN KEY (person_id) REFERENCES cotton_people(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_person_notes","tbl_name": "cotton_person_notes","sql": "CREATE TABLE cotton_person_notes (\n id TEXT PRIMARY KEY,\n person_id TEXT NOT NULL,\n body TEXT NOT NULL,\n noted_at TEXT NOT NULL,\n created_at TEXT NOT NULL,\n source_inbox_id TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (person_id) REFERENCES cotton_people(id)\n )" }, {"kind": "table","name": "cotton_person_suggestions","tbl_name": "cotton_person_suggestions","sql": "CREATE TABLE cotton_person_suggestions (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n person_id TEXT,\n contact_id TEXT,\n candidate_id TEXT NOT NULL,\n reason TEXT NOT NULL,\n score REAL NOT NULL,\n state TEXT NOT NULL DEFAULT 'open',\n decided_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (person_id <> candidate_id),\n CHECK (reason IN ('name_exact', 'name_fuzzy', 'handle_name')),\n CHECK (score >= 0 AND score <= 1),\n CHECK (state IN ('open', 'merged', 'different')),\n CHECK ((state = 'open') = (decided_at IS NULL)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_photos","tbl_name": "cotton_photos","sql": "CREATE TABLE \"cotton_photos\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n key TEXT NOT NULL,\n sha256 TEXT NOT NULL,\n content_type TEXT NOT NULL,\n size_bytes INTEGER NOT NULL,\n width INTEGER,\n height INTEGER,\n taken_at TEXT NOT NULL,\n preview TEXT,\n caption TEXT,\n summary TEXT,\n summary_by TEXT,\n summary_at TEXT,\n review_note TEXT,\n review_by TEXT,\n review_at TEXT,\n taken_offset INTEGER,\n latitude REAL,\n longitude REAL,\n place_name TEXT,\n place_city TEXT,\n place_region TEXT,\n place_country TEXT,\n camera_make TEXT,\n camera_model TEXT,\n orientation INTEGER,\n favourite INTEGER NOT NULL DEFAULT 0,\n subtypes TEXT NOT NULL DEFAULT '[]',\n original_filename TEXT,\n aesthetic_score REAL,\n curation_score REAL,\n labels TEXT NOT NULL DEFAULT '[]',\n phash TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '', ocr_text TEXT, is_utility INTEGER CHECK (is_utility IS NULL OR is_utility IN (0, 1)), origin_handle TEXT CHECK (origin_handle IS NULL OR length(origin_handle) > 0),\n _born TEXT,\n trashed_at TEXT, image_embedding TEXT CHECK (image_embedding IS NULL OR length(image_embedding) > 0), image_embedding_model TEXT CHECK (image_embedding_model IS NULL OR length(image_embedding_model) > 0),\n UNIQUE (workspace_id, sha256),\n CHECK (id = 'photo:' || sha256),\n CHECK (sha256 NOT GLOB '*[^0-9a-f]*' AND length(sha256) = 64),\n CHECK (size_bytes >= 0),\n CHECK (width IS NULL OR width > 0),\n CHECK (height IS NULL OR height > 0),\n CHECK (caption IS NULL OR length(caption) <= 500),\n CHECK (review_note IS NULL OR (length(trim(review_note)) > 0 AND length(review_note) <= 280)),\n CHECK ((summary IS NULL) = (summary_at IS NULL)),\n CHECK ((review_note IS NULL) = (review_at IS NULL)),\n CHECK ((latitude IS NULL) = (longitude IS NULL)),\n CHECK (latitude IS NULL OR (latitude >= -90 AND latitude <= 90)),\n CHECK (longitude IS NULL OR (longitude >= -180 AND longitude <= 180)),\n CHECK (orientation IS NULL OR (orientation >= 1 AND orientation <= 8)),\n CHECK (taken_offset IS NULL OR (taken_offset >= -86400 AND taken_offset <= 86400)),\n CHECK (favourite IN (0, 1)),\n CHECK (json_type(subtypes) = 'array'),\n CHECK (json_type(labels) = 'array'),\n CHECK (aesthetic_score IS NULL OR (aesthetic_score >= -1 AND aesthetic_score <= 1)),\n CHECK (curation_score IS NULL OR (curation_score >= -1 AND curation_score <= 1)),\n CHECK (phash IS NULL OR (length(phash) = 16 AND phash NOT GLOB '*[^0-9a-f]*')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_placement_proposals","tbl_name": "cotton_placement_proposals","sql": "CREATE TABLE cotton_placement_proposals (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n title TEXT NOT NULL,\n items TEXT NOT NULL,\n status TEXT NOT NULL DEFAULT 'open',\n decided_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (length(title) > 0),\n CHECK (length(items) > 0),\n CHECK (status IN ('open', 'approved', 'declined')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_posts","tbl_name": "cotton_posts","sql": "CREATE TABLE cotton_posts (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n source TEXT NOT NULL,\n account TEXT NOT NULL,\n external_id TEXT NOT NULL,\n saved INTEGER NOT NULL DEFAULT 0,\n author_handle TEXT,\n author_name TEXT,\n person_id TEXT,\n caption TEXT,\n media TEXT NOT NULL DEFAULT '[]',\n posted_at TEXT,\n saved_at TEXT,\n permalink TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (saved IN (0, 1)),\n CHECK (trim(external_id) <> ''),\n CHECK (json_valid(media) AND json_type(media) = 'array'),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_project_links","tbl_name": "cotton_project_links","sql": "CREATE TABLE \"cotton_project_links\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n project_id TEXT NOT NULL,\n record_kind TEXT NOT NULL,\n record_id TEXT NOT NULL,\n note TEXT,\n applied_by TEXT NOT NULL,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n pinned INTEGER NOT NULL DEFAULT 0,\n \"position\" REAL, origin_handle TEXT CHECK (origin_handle IS NULL OR length(origin_handle) > 0),\n UNIQUE (project_id, record_kind, record_id),\n CHECK (record_kind IN ('thread', 'email_thread', 'person', 'note', 'journal', 'todo', 'event', 'meeting', 'document', 'screenplay', 'page', 'location', 'transaction', 'goal', 'feedback', 'thought', 'photo', 'video', 'memory', 'call', 'album', 'secret', 'repository', 'decision')),\n CHECK (pinned IN (0, 1)),\n CHECK (record_kind <> 'memory' OR \"position\" IS NOT NULL),\n CHECK (applied_by IN ('router', 'user', 'agent')),\n CHECK (length(record_id) > 0),\n CHECK (note IS NULL OR length(note) <= 500),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (project_id) REFERENCES cotton_memory_projects(id)\n )" }, {"kind": "table","name": "cotton_prompts","tbl_name": "cotton_prompts","sql": "CREATE TABLE cotton_prompts (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n session_id TEXT NOT NULL,\n project_id TEXT,\n seq INTEGER NOT NULL,\n ts TEXT NOT NULL,\n text TEXT NOT NULL,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '', role TEXT NOT NULL DEFAULT 'user' CHECK (role IN ('user', 'assistant')),\n _born TEXT,\n UNIQUE (session_id, seq),\n CHECK (seq >= 0),\n CHECK ((length(trim(text)) > 0) AND (length(text) <= 8000)),\n FOREIGN KEY (session_id) REFERENCES cotton_sessions(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_push_acks","tbl_name": "cotton_push_acks","sql": "CREATE TABLE cotton_push_acks (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n device_id TEXT NOT NULL CHECK (length(trim(device_id)) > 0),\n push_id TEXT NOT NULL CHECK (length(trim(push_id)) > 0),\n received_at TEXT NOT NULL,\n how TEXT NOT NULL CHECK (how IN ('shown','delivered','opened')),\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_records","tbl_name": "cotton_records","sql": "CREATE TABLE cotton_records (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n table_id TEXT NOT NULL,\n data TEXT NOT NULL,\n project_id TEXT,\n position REAL,\n byline TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n deleted_at TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (length(id) > 0),\n CHECK (length(table_id) > 0),\n CHECK (json_type(data) = 'object'),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_repo_bundles","tbl_name": "cotton_repo_bundles","sql": "CREATE TABLE cotton_repo_bundles (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n repo_id TEXT NOT NULL,\n object_key TEXT NOT NULL,\n kind TEXT NOT NULL,\n basis_sha TEXT,\n head_sha TEXT NOT NULL,\n refs_json TEXT NOT NULL DEFAULT '{}',\n bytes INTEGER NOT NULL,\n sha256 TEXT NOT NULL,\n superseded_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, repo_id, sha256),\n CHECK (kind IN ('full', 'incremental')),\n CHECK ((kind = 'full') = (basis_sha IS NULL)),\n CHECK (bytes >= 0),\n CHECK (length(sha256) = 64),\n CHECK (length(trim(object_key)) > 0),\n CHECK (json_type(refs_json) = 'object'),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (repo_id) REFERENCES cotton_repos(id)\n )" }, {"kind": "table","name": "cotton_repo_clones","tbl_name": "cotton_repo_clones","sql": "CREATE TABLE cotton_repo_clones (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n repo_id TEXT NOT NULL,\n device_id TEXT NOT NULL,\n state TEXT NOT NULL,\n sentence TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, repo_id, device_id),\n CHECK (state IN ('ok', 'forked')),\n CHECK (length(trim(device_id)) > 0),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (repo_id) REFERENCES cotton_repos(id)\n )" }, {"kind": "table","name": "cotton_repo_comments","tbl_name": "cotton_repo_comments","sql": "CREATE TABLE cotton_repo_comments (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n repo_id TEXT NOT NULL,\n target_kind TEXT NOT NULL,\n target_number INTEGER NOT NULL,\n kind TEXT NOT NULL,\n remote_id INTEGER NOT NULL,\n author TEXT,\n body TEXT,\n review_state TEXT,\n path TEXT,\n line INTEGER,\n html_url TEXT,\n remote_created_at TEXT,\n remote_updated_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, repo_id, kind, remote_id),\n CHECK (target_kind IN ('pull', 'issue')),\n CHECK (kind IN ('comment', 'review', 'review_comment')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (repo_id) REFERENCES cotton_repos(id)\n )" }, {"kind": "table","name": "cotton_repo_commits","tbl_name": "cotton_repo_commits","sql": "CREATE TABLE cotton_repo_commits (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n repo_id TEXT NOT NULL,\n sha TEXT NOT NULL,\n message TEXT NOT NULL,\n author_name TEXT,\n author_login TEXT,\n authored_at TEXT,\n parents TEXT NOT NULL DEFAULT '[]',\n html_url TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, repo_id, sha),\n CHECK (json_type(parents) = 'array'),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (repo_id) REFERENCES cotton_repos(id)\n )" }, {"kind": "table","name": "cotton_repo_issues","tbl_name": "cotton_repo_issues","sql": "CREATE TABLE cotton_repo_issues (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n repo_id TEXT NOT NULL,\n number INTEGER NOT NULL,\n remote_id INTEGER,\n title TEXT NOT NULL,\n body TEXT,\n state TEXT NOT NULL,\n author TEXT,\n labels TEXT NOT NULL DEFAULT '[]',\n comments_count INTEGER,\n html_url TEXT,\n remote_created_at TEXT,\n remote_updated_at TEXT,\n closed_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, repo_id, number),\n CHECK (state IN ('open', 'closed')),\n CHECK (json_type(labels) = 'array'),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (repo_id) REFERENCES cotton_repos(id)\n )" }, {"kind": "table","name": "cotton_repo_jobs","tbl_name": "cotton_repo_jobs","sql": "CREATE TABLE cotton_repo_jobs (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n run_id TEXT NOT NULL,\n index_in_run INTEGER NOT NULL,\n task_id INTEGER NOT NULL,\n name TEXT NOT NULL,\n runs_on TEXT NOT NULL,\n needs_json TEXT NOT NULL DEFAULT '[]',\n status TEXT NOT NULL DEFAULT 'queued',\n conclusion TEXT,\n runner_uuid TEXT,\n timeout_minutes INTEGER,\n outputs_json TEXT NOT NULL DEFAULT '{}',\n steps_json TEXT NOT NULL DEFAULT '[]',\n summary TEXT,\n log_lines INTEGER NOT NULL DEFAULT 0,\n log_ack INTEGER NOT NULL DEFAULT 0,\n log_key TEXT,\n cancel_requested INTEGER NOT NULL DEFAULT 0,\n requeues INTEGER NOT NULL DEFAULT 0,\n started_at TEXT,\n finished_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n token_digest TEXT,\n UNIQUE (workspace_id, run_id, index_in_run),\n UNIQUE (workspace_id, task_id),\n CHECK (index_in_run > 0),\n CHECK (task_id > 0),\n CHECK (length(trim(name)) > 0),\n CHECK (length(trim(runs_on)) > 0),\n CHECK (json_type(needs_json) = 'array'),\n CHECK (json_type(outputs_json) = 'object'),\n CHECK (json_type(steps_json) = 'array'),\n CHECK (status IN ('queued', 'in_progress', 'completed')),\n CHECK (conclusion IS NULL OR conclusion IN ('success', 'failure', 'cancelled', 'skipped', 'timed_out')),\n CHECK (status <> 'completed' OR conclusion IS NOT NULL),\n CHECK (status = 'completed' OR conclusion IS NULL),\n CHECK (timeout_minutes IS NULL OR timeout_minutes > 0),\n CHECK (log_lines >= 0),\n CHECK (log_ack >= 0),\n CHECK (log_ack <= log_lines),\n CHECK (cancel_requested IN (0, 1)),\n CHECK (requeues >= 0),\n CHECK (summary IS NULL OR length(summary) <= 65536),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (run_id) REFERENCES cotton_repo_runs(id)\n )" }, {"kind": "table","name": "cotton_repo_labels","tbl_name": "cotton_repo_labels","sql": "CREATE TABLE cotton_repo_labels (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n repo_id TEXT NOT NULL,\n name TEXT NOT NULL,\n color TEXT,\n description TEXT,\n remote_id INTEGER,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, repo_id, name),\n CHECK (length(trim(name)) > 0),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (repo_id) REFERENCES cotton_repos(id)\n )" }, {"kind": "table","name": "cotton_repo_merge_queue","tbl_name": "cotton_repo_merge_queue","sql": "CREATE TABLE cotton_repo_merge_queue (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n repo_id TEXT NOT NULL,\n pull_id TEXT NOT NULL,\n pull_number INTEGER NOT NULL,\n base_ref TEXT NOT NULL,\n head_sha TEXT,\n state TEXT NOT NULL DEFAULT 'queued',\n failures INTEGER NOT NULL DEFAULT 0,\n reason TEXT,\n train_number INTEGER,\n train_base_sha TEXT,\n train_tip_sha TEXT,\n train_run_id TEXT,\n landed_sha TEXT,\n enqueued_at TEXT NOT NULL,\n finished_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n train_squash_sha TEXT,\n CHECK (length(repo_id) > 0),\n CHECK (length(pull_id) > 0),\n CHECK (pull_number > 0),\n CHECK (length(base_ref) > 0),\n CHECK (state IN ('queued', 'checking', 'landed', 'ejected')),\n CHECK (failures >= 0),\n CHECK (reason IS NULL OR length(reason) <= 2048),\n CHECK (train_number IS NULL OR train_number > 0),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_repo_pulls","tbl_name": "cotton_repo_pulls","sql": "CREATE TABLE cotton_repo_pulls (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n repo_id TEXT NOT NULL,\n number INTEGER NOT NULL,\n remote_id INTEGER,\n title TEXT NOT NULL,\n body TEXT,\n state TEXT NOT NULL,\n merged INTEGER NOT NULL DEFAULT 0,\n draft INTEGER NOT NULL DEFAULT 0,\n author TEXT,\n head_ref TEXT,\n head_sha TEXT,\n base_ref TEXT,\n mergeable INTEGER,\n additions INTEGER,\n deletions INTEGER,\n changed_files INTEGER,\n comments_count INTEGER,\n review_comments_count INTEGER,\n labels TEXT NOT NULL DEFAULT '[]',\n checks_state TEXT,\n checks TEXT NOT NULL DEFAULT '[]',\n html_url TEXT,\n remote_created_at TEXT,\n remote_updated_at TEXT,\n merged_at TEXT,\n closed_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n merge_commit_sha TEXT,\n UNIQUE (workspace_id, repo_id, number),\n CHECK (state IN ('open', 'closed')),\n CHECK (merged IN (0, 1)),\n CHECK (draft IN (0, 1)),\n CHECK (mergeable IS NULL OR mergeable IN (0, 1)),\n CHECK (checks_state IS NULL OR checks_state IN ('pending', 'success', 'failure', 'error', 'warning')),\n CHECK (json_type(labels) = 'array'),\n CHECK (json_type(checks) = 'array'),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (repo_id) REFERENCES cotton_repos(id)\n )" }, {"kind": "table","name": "cotton_repo_releases","tbl_name": "cotton_repo_releases","sql": "CREATE TABLE cotton_repo_releases (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n repo_id TEXT NOT NULL,\n tag TEXT NOT NULL,\n name TEXT,\n body TEXT,\n draft INTEGER NOT NULL DEFAULT 0,\n prerelease INTEGER NOT NULL DEFAULT 0,\n target_sha TEXT,\n author TEXT,\n published_at TEXT,\n assets_json TEXT NOT NULL DEFAULT '[]',\n html_url TEXT,\n remote_id INTEGER,\n synced_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, repo_id, tag),\n CHECK (draft IN (0, 1)),\n CHECK (prerelease IN (0, 1)),\n CHECK (length(trim(tag)) > 0),\n CHECK (json_type(assets_json) = 'array'),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (repo_id) REFERENCES cotton_repos(id)\n )" }, {"kind": "table","name": "cotton_repo_rules","tbl_name": "cotton_repo_rules","sql": "CREATE TABLE cotton_repo_rules (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n repo_id TEXT NOT NULL,\n branch TEXT NOT NULL,\n required_contexts_json TEXT NOT NULL DEFAULT '[]',\n required_approvals INTEGER NOT NULL DEFAULT 0,\n block_outdated INTEGER NOT NULL DEFAULT 0,\n allow_push INTEGER NOT NULL DEFAULT 0,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, repo_id, branch),\n CHECK (length(trim(branch)) > 0),\n CHECK (json_type(required_contexts_json) = 'array'),\n CHECK (required_approvals >= 0),\n CHECK (block_outdated IN (0, 1)),\n CHECK (allow_push IN (0, 1)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (repo_id) REFERENCES cotton_repos(id)\n )" }, {"kind": "table","name": "cotton_repo_runners","tbl_name": "cotton_repo_runners","sql": "CREATE TABLE cotton_repo_runners (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n repo_id TEXT,\n uuid TEXT NOT NULL,\n name TEXT NOT NULL,\n labels_json TEXT NOT NULL DEFAULT '[]',\n device_id TEXT,\n credential_id TEXT NOT NULL,\n version TEXT,\n last_seen_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, uuid),\n CHECK (length(trim(uuid)) > 0),\n CHECK (length(trim(name)) > 0),\n CHECK (length(trim(credential_id)) > 0),\n CHECK (json_type(labels_json) = 'array'),\n CHECK (repo_id IS NULL OR length(repo_id) > 0),\n CHECK (device_id IS NULL OR length(device_id) > 0),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (repo_id) REFERENCES cotton_repos(id)\n )" }, {"kind": "table","name": "cotton_repo_runs","tbl_name": "cotton_repo_runs","sql": "CREATE TABLE cotton_repo_runs (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n repo_id TEXT NOT NULL,\n index_in_repo INTEGER NOT NULL,\n workflow TEXT NOT NULL,\n workflow_name TEXT,\n event TEXT NOT NULL,\n ref TEXT NOT NULL,\n sha TEXT NOT NULL,\n pull_id TEXT,\n status TEXT NOT NULL DEFAULT 'queued',\n conclusion TEXT,\n triggered_by TEXT NOT NULL DEFAULT 'worker',\n started_at TEXT,\n finished_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, repo_id, index_in_repo),\n CHECK (index_in_repo > 0),\n CHECK (length(trim(workflow)) > 0),\n CHECK (event IN ('push', 'pull_request', 'merge_group', 'schedule', 'workflow_dispatch')),\n CHECK (length(trim(ref)) > 0),\n CHECK (length(sha) BETWEEN 7 AND 64),\n CHECK (status IN ('queued', 'in_progress', 'completed')),\n CHECK (conclusion IS NULL OR conclusion IN ('success', 'failure', 'cancelled', 'skipped', 'timed_out')),\n CHECK (status <> 'completed' OR conclusion IS NOT NULL),\n CHECK (status = 'completed' OR conclusion IS NULL),\n CHECK (triggered_by IN ('worker', 'owner', 'schedule')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (repo_id) REFERENCES cotton_repos(id)\n )" }, {"kind": "table","name": "cotton_repo_vars","tbl_name": "cotton_repo_vars","sql": "CREATE TABLE cotton_repo_vars (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n repo_id TEXT NOT NULL,\n name TEXT NOT NULL,\n value TEXT NOT NULL,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, repo_id, name),\n CHECK (length(trim(name)) > 0),\n CHECK (name NOT GLOB '*[^A-Za-z0-9_]*'),\n CHECK (length(value) <= 65536),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_repos","tbl_name": "cotton_repos","sql": "CREATE TABLE cotton_repos (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n key TEXT NOT NULL,\n host TEXT NOT NULL,\n owner TEXT NOT NULL,\n name TEXT NOT NULL,\n kind TEXT NOT NULL,\n default_branch TEXT,\n description TEXT,\n web_url TEXT NOT NULL,\n open_pulls INTEGER,\n open_issues INTEGER,\n sync_state TEXT NOT NULL DEFAULT 'pending',\n last_error TEXT,\n synced_at TEXT,\n pulls_cursor TEXT,\n issues_cursor TEXT,\n held INTEGER NOT NULL DEFAULT 0,\n origin TEXT,\n head_sha TEXT,\n held_at TEXT,\n bundle_state TEXT,\n last_bundle_error TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, key),\n CHECK (kind IN ('github', 'forgejo', 'cotton')),\n CHECK (sync_state IN ('pending', 'ok', 'no_token', 'error', 'unsupported', 'held')),\n CHECK (held IN (0, 1)),\n CHECK (origin IS NULL OR origin IN ('forgejo', 'github', 'cotton')),\n CHECK (bundle_state IS NULL OR bundle_state IN ('none', 'bundling', 'ok', 'error')),\n CHECK (length(trim(key)) > 0),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_revocations","tbl_name": "cotton_revocations","sql": "CREATE TABLE cotton_revocations (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n subject_table TEXT NOT NULL,\n subject_id TEXT NOT NULL,\n revoked_at TEXT NOT NULL,\n actor TEXT NOT NULL,\n reason TEXT NOT NULL CHECK (reason IN ('revoked','lost','succeeded','stolen','erased','restored','spent','pruned')),\n successor TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n p_sig TEXT,\n signer_person TEXT, replaced_by TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_screenplay_characters","tbl_name": "cotton_screenplay_characters","sql": "CREATE TABLE cotton_screenplay_characters (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n screenplay_id TEXT NOT NULL,\n name TEXT NOT NULL,\n aliases TEXT,\n bio TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n trashed_at TEXT,\n want TEXT,\n arc TEXT,\n age TEXT,\n casting_thoughts TEXT,\n picture_photo_id TEXT,\n UNIQUE (screenplay_id, name),\n CHECK (length(trim(name)) > 0),\n CHECK (aliases IS NULL OR json_type(aliases) = 'array'),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (screenplay_id) REFERENCES cotton_screenplays(id)\n )" }, {"kind": "table","name": "cotton_screenplay_documents","tbl_name": "cotton_screenplay_documents","sql": "CREATE TABLE cotton_screenplay_documents (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n screenplay_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n body TEXT NOT NULL,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT, trashed_at TEXT,\n UNIQUE (screenplay_id, kind),\n CHECK (length(kind) BETWEEN 1 AND 40 AND NOT kind GLOB '*[^a-z0-9_-]*'),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (screenplay_id) REFERENCES cotton_screenplays(id)\n )" }, {"kind": "table","name": "cotton_screenplay_draft_scenes","tbl_name": "cotton_screenplay_draft_scenes","sql": "CREATE TABLE cotton_screenplay_draft_scenes (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n draft_id TEXT NOT NULL,\n scene_id TEXT NOT NULL,\n \"position\" REAL NOT NULL,\n heading TEXT,\n body TEXT NOT NULL,\n purpose TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (draft_id, scene_id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (draft_id) REFERENCES cotton_screenplay_drafts(id)\n )" }, {"kind": "table","name": "cotton_screenplay_drafts","tbl_name": "cotton_screenplay_drafts","sql": "CREATE TABLE cotton_screenplay_drafts (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n screenplay_id TEXT NOT NULL,\n name TEXT NOT NULL,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (length(trim(name)) > 0),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (screenplay_id) REFERENCES cotton_screenplays(id)\n )" }, {"kind": "table","name": "cotton_screenplay_scenes","tbl_name": "cotton_screenplay_scenes","sql": "CREATE TABLE cotton_screenplay_scenes (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n screenplay_id TEXT NOT NULL,\n \"position\" REAL NOT NULL,\n heading TEXT,\n body TEXT NOT NULL,\n purpose TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n archived_at TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n act TEXT,\n sequence TEXT,\n status TEXT,\n location TEXT,\n characters_in_scene TEXT,\n characters_set_by TEXT, trashed_at TEXT,\n CHECK (act IS NULL OR act IN ('1', '2', '3', '4', '5')),\n CHECK (status IS NULL OR status IN ('outline', 'drafted', 'locked')),\n CHECK (characters_set_by IS NULL OR characters_set_by IN ('engine', 'owner')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (screenplay_id) REFERENCES cotton_screenplays(id)\n )" }, {"kind": "table","name": "cotton_screenplays","tbl_name": "cotton_screenplays","sql": "CREATE TABLE cotton_screenplays (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n title TEXT NOT NULL,\n logline TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n archived_at TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT, trashed_at TEXT,\n CHECK (length(trim(title)) > 0),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_secret_placements","tbl_name": "cotton_secret_placements","sql": "CREATE TABLE cotton_secret_placements (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n secret_id TEXT NOT NULL,\n device_id TEXT NOT NULL CHECK (length(device_id) > 0),\n path TEXT NOT NULL,\n mode INTEGER NOT NULL DEFAULT 384,\n format TEXT NOT NULL DEFAULT 'raw',\n env_name TEXT,\n applied_at TEXT,\n applied_hash TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT, apply_problem TEXT,\n UNIQUE (workspace_id, device_id, path),\n CHECK (format IN ('raw', 'env')),\n CHECK ((format = 'env') = (env_name IS NOT NULL)),\n CHECK (mode BETWEEN 0 AND 511),\n CHECK (path GLOB '~/?*' AND NOT path GLOB '*/../*' AND NOT path GLOB '*/..'),\n CHECK (applied_hash IS NULL OR (length(applied_hash) = 64 AND NOT applied_hash GLOB '*[^0-9a-f]*')),\n FOREIGN KEY (secret_id) REFERENCES cotton_secrets(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_secrets","tbl_name": "cotton_secrets","sql": "CREATE TABLE cotton_secrets (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n name TEXT NOT NULL CHECK (length(name) BETWEEN 1 AND 120),\n site TEXT CHECK (site IS NULL OR length(site) BETWEEN 1 AND 255),\n username TEXT CHECK (username IS NULL OR length(username) BETWEEN 1 AND 255),\n service TEXT CHECK (service IS NULL OR (length(service) BETWEEN 1 AND 60 AND service GLOB '[a-z0-9]*' AND NOT service GLOB '*[^a-z0-9._-]*')),\n value_enc TEXT CHECK (value_enc IS NULL OR length(value_enc) > 0),\n vmk_version INTEGER NOT NULL DEFAULT 0,\n hint TEXT CHECK (hint IS NULL OR length(hint) <= 4),\n last_used_at TEXT,\n expires_at TEXT,\n trashed_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (kind IN ('login', 'api_key', 'note', 'card', 'identity', 'document')),\n CHECK (vmk_version >= 0),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_serving_machine","tbl_name": "cotton_serving_machine","sql": "CREATE TABLE cotton_serving_machine (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n epoch INTEGER NOT NULL,\n device_credential_id TEXT NOT NULL,\n author_id TEXT NOT NULL,\n relay_key TEXT,\n backup_access_key_id TEXT,\n since TEXT NOT NULL,\n confirmed_by TEXT,\n start_positions TEXT CHECK (start_positions IS NULL OR json_type(start_positions) = 'object'),\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_session_messages","tbl_name": "cotton_session_messages","sql": "CREATE TABLE cotton_session_messages (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n project_id TEXT,\n to_kind TEXT NOT NULL,\n to_session_id TEXT,\n from_kind TEXT NOT NULL,\n from_session_id TEXT,\n kind TEXT NOT NULL,\n body TEXT NOT NULL,\n reply_to TEXT,\n request_ref TEXT,\n thought_id TEXT,\n status TEXT NOT NULL DEFAULT 'open',\n claimed_by_session_id TEXT,\n claimed_at TEXT,\n done_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '', media TEXT NOT NULL DEFAULT '[]' CHECK (json_type(media) = 'array'),\n _born TEXT,\n CHECK (to_kind IN ('owner', 'project', 'session')),\n CHECK (from_kind IN ('owner', 'session')),\n CHECK (kind IN ('instruction', 'question', 'answer', 'report', 'decision', 'stop')),\n CHECK (status IN ('open', 'claimed', 'done', 'withdrawn')),\n CHECK (length(trim(body)) > 0 AND length(body) <= 8000),\n CHECK (to_kind <> 'session' OR to_session_id IS NOT NULL),\n CHECK (to_kind <> 'project' OR project_id IS NOT NULL),\n CHECK (from_kind <> 'session' OR from_session_id IS NOT NULL),\n CHECK (kind NOT IN ('decision', 'stop') OR to_kind = 'session'),\n CHECK (kind <> 'decision' OR request_ref IS NOT NULL),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (to_session_id) REFERENCES cotton_sessions(id)\n )" }, {"kind": "table","name": "cotton_session_tasks","tbl_name": "cotton_session_tasks","sql": "CREATE TABLE cotton_session_tasks (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n session_id TEXT NOT NULL,\n seq INTEGER NOT NULL,\n text TEXT NOT NULL,\n state TEXT NOT NULL,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (session_id, seq),\n CHECK (seq >= 0),\n CHECK (length(text) <= 500),\n CHECK (state IN ('open', 'active', 'done')),\n FOREIGN KEY (session_id) REFERENCES cotton_sessions(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_sessions","tbl_name": "cotton_sessions","sql": "CREATE TABLE cotton_sessions (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n project_id TEXT,\n tool TEXT NOT NULL,\n external_id TEXT,\n machine TEXT,\n repo_url TEXT,\n branch TEXT,\n cwd TEXT,\n started_at TEXT,\n last_active_at TEXT NOT NULL,\n ended_at TEXT,\n summary TEXT,\n title TEXT,\n shipped TEXT NOT NULL DEFAULT '[]',\n turn_count INTEGER NOT NULL DEFAULT 0,\n prompt_count INTEGER NOT NULL DEFAULT 0,\n transcript_ref TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '', account TEXT, listened_at TEXT, model TEXT,\n _born TEXT,\n device_id TEXT,\n state TEXT CHECK (state IS NULL OR state IN ('queued', 'starting', 'running', 'idle', 'waiting', 'ended', 'failed', 'withdrawn')),\n state_at TEXT,\n waiting_kind TEXT CHECK (waiting_kind IS NULL OR waiting_kind IN ('permission', 'question', 'input')),\n waiting_ref TEXT,\n last_line TEXT CHECK (last_line IS NULL OR length(last_line) <= 280),\n exit_code INTEGER,\n permission_mode TEXT CHECK (permission_mode IS NULL OR permission_mode IN ('bypass', 'ask')),\n host_owned INTEGER NOT NULL DEFAULT 0 CHECK (host_owned IN (0, 1)),\n todo_id TEXT,\n requested_device_id TEXT,\n chosen_by TEXT CHECK (chosen_by IS NULL OR chosen_by IN ('owner', 'dispatcher')),\n prompt TEXT NOT NULL DEFAULT '',\n hold_reason TEXT CHECK (hold_reason IS NULL OR length(hold_reason) <= 200),\n claimed_at TEXT,\n report_message_id TEXT,\n error TEXT,\n kind TEXT NOT NULL DEFAULT 'thread' CHECK (kind IN ('conversation', 'thread')),\n parent_session_id TEXT,\n todo_database TEXT CHECK (todo_database IS NULL OR length(todo_database) > 0), trashed_at TEXT,\n UNIQUE (tool, external_id),\n CHECK (tool IN ('claude-code', 'codex', 'kimi', 'gemini', 'opencode', 'other')),\n CHECK (external_id IS NULL OR length(trim(external_id)) > 0),\n CHECK (machine IS NULL OR length(trim(machine)) > 0),\n CHECK ((summary IS NULL) OR (length(summary) <= 2000)),\n CHECK ((title IS NULL) OR (length(title) <= 140)),\n CHECK (json_type(shipped) = 'array'),\n CHECK (turn_count >= 0),\n CHECK (prompt_count >= 0),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_storage_rules","tbl_name": "cotton_storage_rules","sql": "CREATE TABLE cotton_storage_rules (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n device_id TEXT NOT NULL,\n tool TEXT NOT NULL CHECK (tool IN ('photo','video','document','meeting','thread','person','other','whatsapp','instagram')),\n keep_rule TEXT NOT NULL DEFAULT 'all' CHECK (keep_rule IN ('all','recent_90_days','only_opened')),\n held_bytes INTEGER,\n freeable_bytes INTEGER,\n held_count INTEGER,\n total_count INTEGER,\n measured_at TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, device_id, tool),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_stories","tbl_name": "cotton_stories","sql": "CREATE TABLE cotton_stories (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n source TEXT NOT NULL CHECK (source IN ('whatsapp', 'instagram', 'facebook')),\n account TEXT NOT NULL,\n external_id TEXT NOT NULL,\n person_id TEXT,\n sender TEXT,\n sender_label TEXT,\n kind TEXT NOT NULL,\n caption TEXT,\n media_key TEXT,\n media_content_type TEXT,\n media_dropped_at TEXT,\n posted_at TEXT NOT NULL,\n expires_at TEXT NOT NULL,\n seen_at TEXT,\n kept INTEGER NOT NULL DEFAULT 0 CHECK (kept IN (0, 1)),\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, source, external_id),\n CHECK (trim(external_id) <> ''),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_table_definitions","tbl_name": "cotton_table_definitions","sql": "CREATE TABLE cotton_table_definitions (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n definition TEXT NOT NULL,\n builtin INTEGER NOT NULL DEFAULT 0,\n instructions_edited INTEGER NOT NULL DEFAULT 0,\n builtin_revision INTEGER,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT, builtin_hash TEXT, builtin_stamp INTEGER,\n CHECK (length(id) > 0),\n CHECK (length(definition) > 0),\n CHECK (builtin IN (0, 1)),\n CHECK (instructions_edited IN (0, 1)),\n CHECK (builtin_revision IS NULL OR builtin_revision >= 1),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_theme_definitions","tbl_name": "cotton_theme_definitions","sql": "CREATE TABLE cotton_theme_definitions (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n definition TEXT NOT NULL,\n builtin INTEGER NOT NULL DEFAULT 0,\n builtin_revision INTEGER,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT, builtin_hash TEXT, builtin_stamp INTEGER,\n CHECK (length(id) > 0),\n CHECK (length(definition) > 0),\n CHECK (builtin IN (0, 1)),\n CHECK (builtin_revision IS NULL OR builtin_revision >= 1),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_thought_attachments","tbl_name": "cotton_thought_attachments","sql": "CREATE TABLE cotton_thought_attachments (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n thought_id TEXT NOT NULL,\n record_kind TEXT NOT NULL,\n record_id TEXT NOT NULL,\n position INTEGER NOT NULL,\n caption TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (thought_id, record_kind, record_id),\n CHECK (record_kind IN ('photo', 'video', 'document')),\n CHECK (length(record_id) > 0),\n CHECK (position >= 0),\n CHECK (caption IS NULL OR length(caption) <= 500),\n FOREIGN KEY (thought_id) REFERENCES cotton_inbox_items(id),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_todo_recurrences","tbl_name": "cotton_todo_recurrences","sql": "CREATE TABLE cotton_todo_recurrences (\n id TEXT PRIMARY KEY,\n title TEXT NOT NULL,\n notes TEXT,\n priority INTEGER NOT NULL DEFAULT 0,\n rrule TEXT NOT NULL,\n dtstart TEXT NOT NULL,\n paused INTEGER NOT NULL DEFAULT 0,\n materialized_until TEXT,\n source_inbox_id TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n workspace_id TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT, trashed_at TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_todos","tbl_name": "cotton_todos","sql": "CREATE TABLE cotton_todos (\n id TEXT PRIMARY KEY,\n title TEXT NOT NULL,\n notes TEXT,\n label TEXT,\n status TEXT NOT NULL DEFAULT 'open',\n due_at TEXT,\n snoozed_until TEXT,\n priority INTEGER NOT NULL DEFAULT 0,\n completed_at TEXT,\n source_inbox_id TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n recurrence_id TEXT,\n occurrence_at TEXT,\n workspace_id TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT, trashed_at TEXT,\n UNIQUE (recurrence_id, occurrence_at),\n CHECK (status IN ('open', 'done', 'dropped', 'missed')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_tool_assets","tbl_name": "cotton_tool_assets","sql": "CREATE TABLE cotton_tool_assets (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n tool_id TEXT NOT NULL CHECK (length(trim(tool_id)) > 0),\n name TEXT NOT NULL CHECK (length(trim(name)) > 0),\n bytes TEXT NOT NULL,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_tool_definitions","tbl_name": "cotton_tool_definitions","sql": "CREATE TABLE cotton_tool_definitions (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n definition TEXT NOT NULL,\n builtin INTEGER NOT NULL DEFAULT 0,\n instructions_edited INTEGER NOT NULL DEFAULT 0,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (length(id) > 0),\n CHECK (length(definition) > 0),\n CHECK (builtin IN (0, 1)),\n CHECK (instructions_edited IN (0, 1)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_toolkits","tbl_name": "cotton_toolkits","sql": "CREATE TABLE cotton_toolkits (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n name TEXT NOT NULL,\n description TEXT,\n picture TEXT,\n tools TEXT NOT NULL DEFAULT '[]',\n shipped INTEGER NOT NULL DEFAULT 0,\n position INTEGER NOT NULL DEFAULT 0,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT, trashed_at TEXT,\n CHECK (length(id) > 0),\n CHECK (length(name) > 0),\n CHECK (json_type(tools) = 'array'),\n CHECK (picture IS NULL OR json_valid(picture)),\n CHECK (shipped IN (0, 1)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_undos","tbl_name": "cotton_undos","sql": "CREATE TABLE cotton_undos (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n change_id TEXT NOT NULL,\n undo_change_id TEXT NOT NULL,\n at TEXT NOT NULL,\n actor TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_usage","tbl_name": "cotton_usage","sql": "CREATE TABLE cotton_usage (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n device TEXT NOT NULL,\n kind TEXT NOT NULL CHECK (kind IN ('view_opened', 'record_opened', 'act_fired', 'search')),\n tool TEXT NOT NULL,\n view TEXT NOT NULL,\n record TEXT,\n at TEXT NOT NULL,\n record_byline TEXT,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n)" }, {"kind": "table","name": "cotton_vault_keys","tbl_name": "cotton_vault_keys","sql": "CREATE TABLE cotton_vault_keys (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n device_id TEXT NOT NULL CHECK (length(device_id) > 0),\n public_key TEXT NOT NULL CHECK (length(public_key) > 0),\n wrapped_vmk TEXT CHECK (wrapped_vmk IS NULL OR length(wrapped_vmk) > 0),\n vmk_version INTEGER NOT NULL DEFAULT 0,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n UNIQUE (workspace_id, device_id),\n CHECK (vmk_version >= 0),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_vault_retired_keys","tbl_name": "cotton_vault_retired_keys","sql": "CREATE TABLE cotton_vault_retired_keys (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n version INTEGER NOT NULL,\n under_version INTEGER NOT NULL,\n under_kcv TEXT NOT NULL,\n wrapped TEXT NOT NULL,\n retired_at TEXT NOT NULL,\n actor TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_vault_state","tbl_name": "cotton_vault_state","sql": "CREATE TABLE cotton_vault_state (\n workspace_id TEXT PRIMARY KEY,\n vmk_version INTEGER NOT NULL,\n rotated_at TEXT NOT NULL,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (vmk_version >= 1),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_videos","tbl_name": "cotton_videos","sql": "CREATE TABLE \"cotton_videos\" (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n key TEXT NOT NULL,\n sha256 TEXT NOT NULL,\n content_type TEXT NOT NULL,\n size_bytes INTEGER NOT NULL,\n width INTEGER,\n height INTEGER,\n duration_ms INTEGER,\n taken_at TEXT NOT NULL,\n preview TEXT,\n poster_key TEXT,\n caption TEXT,\n summary TEXT,\n summary_by TEXT,\n summary_at TEXT,\n review_note TEXT,\n review_by TEXT,\n review_at TEXT,\n taken_offset INTEGER,\n latitude REAL,\n longitude REAL,\n place_name TEXT,\n place_city TEXT,\n place_region TEXT,\n place_country TEXT,\n camera_make TEXT,\n camera_model TEXT,\n orientation INTEGER,\n favourite INTEGER NOT NULL DEFAULT 0,\n subtypes TEXT NOT NULL DEFAULT '[]',\n original_filename TEXT,\n aesthetic_score REAL,\n curation_score REAL,\n labels TEXT NOT NULL DEFAULT '[]',\n phash TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '', origin_handle TEXT CHECK (origin_handle IS NULL OR length(origin_handle) > 0),\n _born TEXT,\n trashed_at TEXT,\n UNIQUE (workspace_id, sha256),\n CHECK (id = 'video:' || sha256),\n CHECK (sha256 NOT GLOB '*[^0-9a-f]*' AND length(sha256) = 64),\n CHECK (size_bytes >= 0),\n CHECK (width IS NULL OR width > 0),\n CHECK (height IS NULL OR height > 0),\n CHECK (caption IS NULL OR length(caption) <= 500),\n CHECK (review_note IS NULL OR (length(trim(review_note)) > 0 AND length(review_note) <= 280)),\n CHECK ((summary IS NULL) = (summary_at IS NULL)),\n CHECK ((review_note IS NULL) = (review_at IS NULL)),\n CHECK ((latitude IS NULL) = (longitude IS NULL)),\n CHECK (latitude IS NULL OR (latitude >= -90 AND latitude <= 90)),\n CHECK (longitude IS NULL OR (longitude >= -180 AND longitude <= 180)),\n CHECK (orientation IS NULL OR (orientation >= 1 AND orientation <= 8)),\n CHECK (taken_offset IS NULL OR (taken_offset >= -86400 AND taken_offset <= 86400)),\n CHECK (favourite IN (0, 1)),\n CHECK (json_type(subtypes) = 'array'),\n CHECK (json_type(labels) = 'array'),\n CHECK (aesthetic_score IS NULL OR (aesthetic_score >= -1 AND aesthetic_score <= 1)),\n CHECK (curation_score IS NULL OR (curation_score >= -1 AND curation_score <= 1)),\n CHECK (phash IS NULL OR (length(phash) = 16 AND phash NOT GLOB '*[^0-9a-f]*')),\n CHECK (duration_ms IS NULL OR duration_ms >= 0),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_voice_vocabulary","tbl_name": "cotton_voice_vocabulary","sql": "CREATE TABLE cotton_voice_vocabulary (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n term TEXT NOT NULL,\n source TEXT NOT NULL,\n use_count INTEGER NOT NULL DEFAULT 0,\n last_used_at TEXT,\n created_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (source IN ('manual', 'auto')),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_widgets","tbl_name": "cotton_widgets","sql": "CREATE TABLE cotton_widgets (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL,\n device_id TEXT NOT NULL,\n device_name TEXT,\n kind TEXT NOT NULL,\n size TEXT NOT NULL,\n configured TEXT,\n place INTEGER NOT NULL DEFAULT 0,\n shows_database TEXT,\n shows_view TEXT,\n name TEXT NOT NULL DEFAULT '',\n database_name TEXT,\n last_drawn_at TEXT NOT NULL,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n CHECK (length(device_id) > 0),\n CHECK (length(kind) > 0),\n CHECK (size IN ('small', 'medium', 'large', 'extraLarge', 'accessoryCircular', 'accessoryRectangular', 'accessoryInline')),\n CHECK (place >= 0),\n CHECK ((shows_view IS NULL) OR (length(shows_view) > 0)),\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n )" }, {"kind": "table","name": "cotton_workspaces","tbl_name": "cotton_workspaces","sql": "CREATE TABLE cotton_workspaces (\n id TEXT PRIMARY KEY,\n name TEXT NOT NULL,\n owner_user_id TEXT NOT NULL,\n created_at TEXT NOT NULL,\n city_name TEXT,\n city_lat REAL,\n city_lon REAL,\n msg_import_self_names TEXT NOT NULL DEFAULT '{}',\n _hlc TEXT NOT NULL DEFAULT '',\n _born TEXT,\n relay_name TEXT,\n session_permission_default TEXT NOT NULL DEFAULT 'bypass' CHECK (session_permission_default IN ('bypass', 'ask')),\n kind TEXT CHECK (kind IS NULL OR kind IN ('personal', 'shared')),\n namespace TEXT CHECK (namespace IS NULL OR length(namespace) > 0),\n owner_person_id TEXT,\n relay_domain TEXT,\n relay_tunnel_host TEXT,\n front_door TEXT,\n front_door_address TEXT,\n relay_roster TEXT,\n CHECK (((city_name IS NOT NULL) + (city_lat IS NOT NULL) + (city_lon IS NOT NULL)) IN (0, 3))\n )" }, {"kind": "table","name": "fts_decisions","tbl_name": "fts_decisions","sql": "CREATE VIRTUAL TABLE fts_decisions USING fts5(\n title, why, content = 'cotton_decisions', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_document_pages","tbl_name": "fts_document_pages","sql": "CREATE VIRTUAL TABLE fts_document_pages USING fts5(\n text, content = 'cotton_document_pages', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_documents","tbl_name": "fts_documents","sql": "CREATE VIRTUAL TABLE fts_documents USING fts5(\n title, issuer, summary, original_name, content = 'cotton_documents', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_emails","tbl_name": "fts_emails","sql": "CREATE VIRTUAL TABLE fts_emails USING fts5(\n subject, body, content = 'cotton_emails', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_events","tbl_name": "fts_events","sql": "CREATE VIRTUAL TABLE fts_events USING fts5(\n title, notes, location, content = 'cotton_events', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_locations","tbl_name": "fts_locations","sql": "CREATE VIRTUAL TABLE fts_locations USING fts5(\n name, address, note, content = 'cotton_locations', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_mail","tbl_name": "fts_mail","sql": "CREATE VIRTUAL TABLE fts_mail USING fts5(\n subject, body, from_name, from_email, content = 'cotton_emails', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_meetings","tbl_name": "fts_meetings","sql": "CREATE VIRTUAL TABLE fts_meetings USING fts5(\n title, summary_md, content = 'cotton_meetings', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_memories","tbl_name": "fts_memories","sql": "CREATE VIRTUAL TABLE fts_memories USING fts5(\n title, body, content = 'cotton_memories', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_messages","tbl_name": "fts_messages","sql": "CREATE VIRTUAL TABLE fts_messages USING fts5(\n body, content = 'cotton_msg_messages', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_moods","tbl_name": "fts_moods","sql": "CREATE VIRTUAL TABLE fts_moods USING fts5(\n line, content = 'cotton_moods', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_notes","tbl_name": "fts_notes","sql": "CREATE VIRTUAL TABLE fts_notes USING fts5(\n title, body, content = 'cotton_notes', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_pages","tbl_name": "fts_pages","sql": "CREATE VIRTUAL TABLE fts_pages USING fts5(\n title, text, content = 'cotton_pages', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_people","tbl_name": "fts_people","sql": "CREATE VIRTUAL TABLE fts_people USING fts5(\n full_name, org, role_title, summary, content = 'cotton_people', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_photos","tbl_name": "fts_photos","sql": "CREATE VIRTUAL TABLE fts_photos USING fts5(\n caption, summary, ocr_text, content = 'cotton_photos', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_posts","tbl_name": "fts_posts","sql": "CREATE VIRTUAL TABLE fts_posts USING fts5(\n caption, author_name, author_handle, content = 'cotton_posts', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_prompts","tbl_name": "fts_prompts","sql": "CREATE VIRTUAL TABLE fts_prompts USING fts5(\n text, content = 'cotton_prompts', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_repo_issues","tbl_name": "fts_repo_issues","sql": "CREATE VIRTUAL TABLE fts_repo_issues USING fts5(\n title, body, content = 'cotton_repo_issues', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_repo_pulls","tbl_name": "fts_repo_pulls","sql": "CREATE VIRTUAL TABLE fts_repo_pulls USING fts5(\n title, body, content = 'cotton_repo_pulls', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_secrets","tbl_name": "fts_secrets","sql": "CREATE VIRTUAL TABLE fts_secrets USING fts5(\n name, site, username, service, content = 'cotton_secrets', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_session_messages","tbl_name": "fts_session_messages","sql": "CREATE VIRTUAL TABLE fts_session_messages USING fts5(\n body, content = 'cotton_session_messages', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_thoughts","tbl_name": "fts_thoughts","sql": "CREATE VIRTUAL TABLE fts_thoughts USING fts5(\n raw_text, content = 'cotton_inbox_items', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_todos","tbl_name": "fts_todos","sql": "CREATE VIRTUAL TABLE fts_todos USING fts5(\n title, notes, content = 'cotton_todos', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "table","name": "fts_videos","tbl_name": "fts_videos","sql": "CREATE VIRTUAL TABLE fts_videos USING fts5(\n caption, summary, content = 'cotton_videos', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" }, {"kind": "trigger","name": "cotton_ai_jobs_safe_insert","tbl_name": "cotton_ai_jobs","sql": "CREATE TRIGGER cotton_ai_jobs_safe_insert BEFORE INSERT ON cotton_ai_jobs\n WHEN EXISTS (SELECT 1 FROM json_tree(NEW.input) WHERE\n lower(replace(CAST(key AS TEXT),'-','_')) IN\n ('data','bytes','base64','image_bytes','audio_bytes','file_bytes','api_key','apikey','authorization','credential','credentials','password','secret','token','access_token','refresh_token','private_key')\n OR (type='text' AND (lower(value) LIKE 'data:%;base64,%' OR value LIKE 'sk-ant-%' OR value LIKE 'Bearer %' OR value LIKE '-----BEGIN %PRIVATE KEY%')))\n BEGIN SELECT RAISE(ABORT,'ai_job_unsafe_input'); END" }, {"kind": "trigger","name": "cotton_ai_jobs_safe_update","tbl_name": "cotton_ai_jobs","sql": "CREATE TRIGGER cotton_ai_jobs_safe_update BEFORE UPDATE OF input ON cotton_ai_jobs\n WHEN EXISTS (SELECT 1 FROM json_tree(NEW.input) WHERE\n lower(replace(CAST(key AS TEXT),'-','_')) IN\n ('data','bytes','base64','image_bytes','audio_bytes','file_bytes','api_key','apikey','authorization','credential','credentials','password','secret','token','access_token','refresh_token','private_key')\n OR (type='text' AND (lower(value) LIKE 'data:%;base64,%' OR value LIKE 'sk-ant-%' OR value LIKE 'Bearer %' OR value LIKE '-----BEGIN %PRIVATE KEY%')))\n BEGIN SELECT RAISE(ABORT,'ai_job_unsafe_input'); END" }, {"kind": "trigger","name": "cotton_money_statement_lines_no_delete_booked","tbl_name": "cotton_money_statement_lines","sql": "CREATE TRIGGER cotton_money_statement_lines_no_delete_booked\n BEFORE DELETE ON cotton_money_statement_lines\n WHEN EXISTS (SELECT 1 FROM cotton_money_evidence AS e WHERE e.kind = 'statement_line' AND e.ref_id = OLD.id)\n BEGIN SELECT RAISE(ABORT, 'a booked statement line is never deleted'); END" }, {"kind": "trigger","name": "fts_decisions_ad","tbl_name": "cotton_decisions","sql": "CREATE TRIGGER fts_decisions_ad AFTER DELETE ON cotton_decisions WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_decisions'), 0) BEGIN\n INSERT INTO fts_decisions (fts_decisions, rowid, title, why) VALUES ('delete', old.rowid, old.title, old.why);\n END" }, {"kind": "trigger","name": "fts_decisions_ai","tbl_name": "cotton_decisions","sql": "CREATE TRIGGER fts_decisions_ai AFTER INSERT ON cotton_decisions WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_decisions'), 0) BEGIN\n INSERT INTO fts_decisions (rowid, title, why) VALUES (new.rowid, new.title, new.why);\n END" }, {"kind": "trigger","name": "fts_decisions_au","tbl_name": "cotton_decisions","sql": "CREATE TRIGGER fts_decisions_au AFTER UPDATE OF title, why ON cotton_decisions\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_decisions'), 0) AND (new.title IS NOT old.title OR new.why IS NOT old.why) BEGIN\n INSERT INTO fts_decisions (fts_decisions, rowid, title, why) VALUES ('delete', old.rowid, old.title, old.why);\n INSERT INTO fts_decisions (rowid, title, why) VALUES (new.rowid, new.title, new.why);\n END" }, {"kind": "trigger","name": "fts_document_pages_ad","tbl_name": "cotton_document_pages","sql": "CREATE TRIGGER fts_document_pages_ad AFTER DELETE ON cotton_document_pages WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_document_pages'), 0) BEGIN\n INSERT INTO fts_document_pages (fts_document_pages, rowid, text) VALUES ('delete', old.rowid, old.text);\n END" }, {"kind": "trigger","name": "fts_document_pages_ai","tbl_name": "cotton_document_pages","sql": "CREATE TRIGGER fts_document_pages_ai AFTER INSERT ON cotton_document_pages WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_document_pages'), 0) BEGIN\n INSERT INTO fts_document_pages (rowid, text) VALUES (new.rowid, new.text);\n END" }, {"kind": "trigger","name": "fts_document_pages_au","tbl_name": "cotton_document_pages","sql": "CREATE TRIGGER fts_document_pages_au AFTER UPDATE OF text ON cotton_document_pages\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_document_pages'), 0) AND (new.text IS NOT old.text) BEGIN\n INSERT INTO fts_document_pages (fts_document_pages, rowid, text) VALUES ('delete', old.rowid, old.text);\n INSERT INTO fts_document_pages (rowid, text) VALUES (new.rowid, new.text);\n END" }, {"kind": "trigger","name": "fts_documents_ad","tbl_name": "cotton_documents","sql": "CREATE TRIGGER fts_documents_ad AFTER DELETE ON cotton_documents WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_documents'), 0) BEGIN\n INSERT INTO fts_documents (fts_documents, rowid, title, issuer, summary, original_name) VALUES ('delete', old.rowid, old.title, old.issuer, old.summary, old.original_name);\n END" }, {"kind": "trigger","name": "fts_documents_ai","tbl_name": "cotton_documents","sql": "CREATE TRIGGER fts_documents_ai AFTER INSERT ON cotton_documents WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_documents'), 0) BEGIN\n INSERT INTO fts_documents (rowid, title, issuer, summary, original_name) VALUES (new.rowid, new.title, new.issuer, new.summary, new.original_name);\n END" }, {"kind": "trigger","name": "fts_documents_au","tbl_name": "cotton_documents","sql": "CREATE TRIGGER fts_documents_au AFTER UPDATE OF title, issuer, summary, original_name ON cotton_documents\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_documents'), 0) AND (new.title IS NOT old.title OR new.issuer IS NOT old.issuer OR new.summary IS NOT old.summary OR new.original_name IS NOT old.original_name) BEGIN\n INSERT INTO fts_documents (fts_documents, rowid, title, issuer, summary, original_name) VALUES ('delete', old.rowid, old.title, old.issuer, old.summary, old.original_name);\n INSERT INTO fts_documents (rowid, title, issuer, summary, original_name) VALUES (new.rowid, new.title, new.issuer, new.summary, new.original_name);\n END" }, {"kind": "trigger","name": "fts_emails_ad","tbl_name": "cotton_emails","sql": "CREATE TRIGGER fts_emails_ad AFTER DELETE ON cotton_emails WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_emails'), 0) BEGIN\n INSERT INTO fts_emails (fts_emails, rowid, subject, body) VALUES ('delete', old.rowid, old.subject, old.body);\n END" }, {"kind": "trigger","name": "fts_emails_ai","tbl_name": "cotton_emails","sql": "CREATE TRIGGER fts_emails_ai AFTER INSERT ON cotton_emails WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_emails'), 0) BEGIN\n INSERT INTO fts_emails (rowid, subject, body) VALUES (new.rowid, new.subject, new.body);\n END" }, {"kind": "trigger","name": "fts_emails_au","tbl_name": "cotton_emails","sql": "CREATE TRIGGER fts_emails_au AFTER UPDATE OF subject, body ON cotton_emails\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_emails'), 0) AND (new.subject IS NOT old.subject OR new.body IS NOT old.body) BEGIN\n INSERT INTO fts_emails (fts_emails, rowid, subject, body) VALUES ('delete', old.rowid, old.subject, old.body);\n INSERT INTO fts_emails (rowid, subject, body) VALUES (new.rowid, new.subject, new.body);\n END" }, {"kind": "trigger","name": "fts_events_ad","tbl_name": "cotton_events","sql": "CREATE TRIGGER fts_events_ad AFTER DELETE ON cotton_events WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_events'), 0) BEGIN\n INSERT INTO fts_events (fts_events, rowid, title, notes, location) VALUES ('delete', old.rowid, old.title, old.notes, old.location);\n END" }, {"kind": "trigger","name": "fts_events_ai","tbl_name": "cotton_events","sql": "CREATE TRIGGER fts_events_ai AFTER INSERT ON cotton_events WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_events'), 0) BEGIN\n INSERT INTO fts_events (rowid, title, notes, location) VALUES (new.rowid, new.title, new.notes, new.location);\n END" }, {"kind": "trigger","name": "fts_events_au","tbl_name": "cotton_events","sql": "CREATE TRIGGER fts_events_au AFTER UPDATE OF title, notes, location ON cotton_events\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_events'), 0) AND (new.title IS NOT old.title OR new.notes IS NOT old.notes OR new.location IS NOT old.location) BEGIN\n INSERT INTO fts_events (fts_events, rowid, title, notes, location) VALUES ('delete', old.rowid, old.title, old.notes, old.location);\n INSERT INTO fts_events (rowid, title, notes, location) VALUES (new.rowid, new.title, new.notes, new.location);\n END" }, {"kind": "trigger","name": "fts_locations_ad","tbl_name": "cotton_locations","sql": "CREATE TRIGGER fts_locations_ad AFTER DELETE ON cotton_locations WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_locations'), 0) BEGIN\n INSERT INTO fts_locations (fts_locations, rowid, name, address, note) VALUES ('delete', old.rowid, old.name, old.address, old.note);\n END" }, {"kind": "trigger","name": "fts_locations_ai","tbl_name": "cotton_locations","sql": "CREATE TRIGGER fts_locations_ai AFTER INSERT ON cotton_locations WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_locations'), 0) BEGIN\n INSERT INTO fts_locations (rowid, name, address, note) VALUES (new.rowid, new.name, new.address, new.note);\n END" }, {"kind": "trigger","name": "fts_locations_au","tbl_name": "cotton_locations","sql": "CREATE TRIGGER fts_locations_au AFTER UPDATE OF name, address, note ON cotton_locations\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_locations'), 0) AND (new.name IS NOT old.name OR new.address IS NOT old.address OR new.note IS NOT old.note) BEGIN\n INSERT INTO fts_locations (fts_locations, rowid, name, address, note) VALUES ('delete', old.rowid, old.name, old.address, old.note);\n INSERT INTO fts_locations (rowid, name, address, note) VALUES (new.rowid, new.name, new.address, new.note);\n END" }, {"kind": "trigger","name": "fts_mail_ad","tbl_name": "cotton_emails","sql": "CREATE TRIGGER fts_mail_ad AFTER DELETE ON cotton_emails WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_mail'), 0) BEGIN\n INSERT INTO fts_mail (fts_mail, rowid, subject, body, from_name, from_email) VALUES ('delete', old.rowid, old.subject, old.body, old.from_name, old.from_email);\n END" }, {"kind": "trigger","name": "fts_mail_ai","tbl_name": "cotton_emails","sql": "CREATE TRIGGER fts_mail_ai AFTER INSERT ON cotton_emails WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_mail'), 0) BEGIN\n INSERT INTO fts_mail (rowid, subject, body, from_name, from_email) VALUES (new.rowid, new.subject, new.body, new.from_name, new.from_email);\n END" }, {"kind": "trigger","name": "fts_mail_au","tbl_name": "cotton_emails","sql": "CREATE TRIGGER fts_mail_au AFTER UPDATE OF subject, body, from_name, from_email ON cotton_emails\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_mail'), 0) AND (new.subject IS NOT old.subject OR new.body IS NOT old.body OR new.from_name IS NOT old.from_name OR new.from_email IS NOT old.from_email) BEGIN\n INSERT INTO fts_mail (fts_mail, rowid, subject, body, from_name, from_email) VALUES ('delete', old.rowid, old.subject, old.body, old.from_name, old.from_email);\n INSERT INTO fts_mail (rowid, subject, body, from_name, from_email) VALUES (new.rowid, new.subject, new.body, new.from_name, new.from_email);\n END" }, {"kind": "trigger","name": "fts_meetings_ad","tbl_name": "cotton_meetings","sql": "CREATE TRIGGER fts_meetings_ad AFTER DELETE ON cotton_meetings WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_meetings'), 0) BEGIN\n INSERT INTO fts_meetings (fts_meetings, rowid, title, summary_md) VALUES ('delete', old.rowid, old.title, old.summary_md);\n END" }, {"kind": "trigger","name": "fts_meetings_ai","tbl_name": "cotton_meetings","sql": "CREATE TRIGGER fts_meetings_ai AFTER INSERT ON cotton_meetings WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_meetings'), 0) BEGIN\n INSERT INTO fts_meetings (rowid, title, summary_md) VALUES (new.rowid, new.title, new.summary_md);\n END" }, {"kind": "trigger","name": "fts_meetings_au","tbl_name": "cotton_meetings","sql": "CREATE TRIGGER fts_meetings_au AFTER UPDATE OF title, summary_md ON cotton_meetings\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_meetings'), 0) AND (new.title IS NOT old.title OR new.summary_md IS NOT old.summary_md) BEGIN\n INSERT INTO fts_meetings (fts_meetings, rowid, title, summary_md) VALUES ('delete', old.rowid, old.title, old.summary_md);\n INSERT INTO fts_meetings (rowid, title, summary_md) VALUES (new.rowid, new.title, new.summary_md);\n END" }, {"kind": "trigger","name": "fts_memories_ad","tbl_name": "cotton_memories","sql": "CREATE TRIGGER fts_memories_ad AFTER DELETE ON cotton_memories WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_memories'), 0) BEGIN\n INSERT INTO fts_memories (fts_memories, rowid, title, body) VALUES ('delete', old.rowid, old.title, old.body);\n END" }, {"kind": "trigger","name": "fts_memories_ai","tbl_name": "cotton_memories","sql": "CREATE TRIGGER fts_memories_ai AFTER INSERT ON cotton_memories WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_memories'), 0) BEGIN\n INSERT INTO fts_memories (rowid, title, body) VALUES (new.rowid, new.title, new.body);\n END" }, {"kind": "trigger","name": "fts_memories_au","tbl_name": "cotton_memories","sql": "CREATE TRIGGER fts_memories_au AFTER UPDATE OF title, body ON cotton_memories\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_memories'), 0) AND (new.title IS NOT old.title OR new.body IS NOT old.body) BEGIN\n INSERT INTO fts_memories (fts_memories, rowid, title, body) VALUES ('delete', old.rowid, old.title, old.body);\n INSERT INTO fts_memories (rowid, title, body) VALUES (new.rowid, new.title, new.body);\n END" }, {"kind": "trigger","name": "fts_messages_ad","tbl_name": "cotton_msg_messages","sql": "CREATE TRIGGER fts_messages_ad AFTER DELETE ON cotton_msg_messages WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_messages'), 0) BEGIN\n INSERT INTO fts_messages (fts_messages, rowid, body) VALUES ('delete', old.rowid, old.body);\n END" }, {"kind": "trigger","name": "fts_messages_ai","tbl_name": "cotton_msg_messages","sql": "CREATE TRIGGER fts_messages_ai AFTER INSERT ON cotton_msg_messages WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_messages'), 0) BEGIN\n INSERT INTO fts_messages (rowid, body) VALUES (new.rowid, new.body);\n END" }, {"kind": "trigger","name": "fts_messages_au","tbl_name": "cotton_msg_messages","sql": "CREATE TRIGGER fts_messages_au AFTER UPDATE OF body ON cotton_msg_messages\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_messages'), 0) AND (new.body IS NOT old.body) BEGIN\n INSERT INTO fts_messages (fts_messages, rowid, body) VALUES ('delete', old.rowid, old.body);\n INSERT INTO fts_messages (rowid, body) VALUES (new.rowid, new.body);\n END" }, {"kind": "trigger","name": "fts_moods_ad","tbl_name": "cotton_moods","sql": "CREATE TRIGGER fts_moods_ad AFTER DELETE ON cotton_moods WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_moods'), 0) BEGIN\n INSERT INTO fts_moods (fts_moods, rowid, line) VALUES ('delete', old.rowid, old.line);\n END" }, {"kind": "trigger","name": "fts_moods_ai","tbl_name": "cotton_moods","sql": "CREATE TRIGGER fts_moods_ai AFTER INSERT ON cotton_moods WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_moods'), 0) BEGIN\n INSERT INTO fts_moods (rowid, line) VALUES (new.rowid, new.line);\n END" }, {"kind": "trigger","name": "fts_moods_au","tbl_name": "cotton_moods","sql": "CREATE TRIGGER fts_moods_au AFTER UPDATE OF line ON cotton_moods\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_moods'), 0) AND (new.line IS NOT old.line) BEGIN\n INSERT INTO fts_moods (fts_moods, rowid, line) VALUES ('delete', old.rowid, old.line);\n INSERT INTO fts_moods (rowid, line) VALUES (new.rowid, new.line);\n END" }, {"kind": "trigger","name": "fts_notes_ad","tbl_name": "cotton_notes","sql": "CREATE TRIGGER fts_notes_ad AFTER DELETE ON cotton_notes WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_notes'), 0) BEGIN\n INSERT INTO fts_notes (fts_notes, rowid, title, body) VALUES ('delete', old.rowid, old.title, old.body);\n END" }, {"kind": "trigger","name": "fts_notes_ai","tbl_name": "cotton_notes","sql": "CREATE TRIGGER fts_notes_ai AFTER INSERT ON cotton_notes WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_notes'), 0) BEGIN\n INSERT INTO fts_notes (rowid, title, body) VALUES (new.rowid, new.title, new.body);\n END" }, {"kind": "trigger","name": "fts_notes_au","tbl_name": "cotton_notes","sql": "CREATE TRIGGER fts_notes_au AFTER UPDATE OF title, body ON cotton_notes\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_notes'), 0) AND (new.title IS NOT old.title OR new.body IS NOT old.body) BEGIN\n INSERT INTO fts_notes (fts_notes, rowid, title, body) VALUES ('delete', old.rowid, old.title, old.body);\n INSERT INTO fts_notes (rowid, title, body) VALUES (new.rowid, new.title, new.body);\n END" }, {"kind": "trigger","name": "fts_pages_ad","tbl_name": "cotton_pages","sql": "CREATE TRIGGER fts_pages_ad AFTER DELETE ON cotton_pages WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_pages'), 0) BEGIN\n INSERT INTO fts_pages (fts_pages, rowid, title, text) VALUES ('delete', old.rowid, old.title, old.text);\n END" }, {"kind": "trigger","name": "fts_pages_ai","tbl_name": "cotton_pages","sql": "CREATE TRIGGER fts_pages_ai AFTER INSERT ON cotton_pages WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_pages'), 0) BEGIN\n INSERT INTO fts_pages (rowid, title, text) VALUES (new.rowid, new.title, new.text);\n END" }, {"kind": "trigger","name": "fts_pages_au","tbl_name": "cotton_pages","sql": "CREATE TRIGGER fts_pages_au AFTER UPDATE OF title, text ON cotton_pages\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_pages'), 0) AND (new.title IS NOT old.title OR new.text IS NOT old.text) BEGIN\n INSERT INTO fts_pages (fts_pages, rowid, title, text) VALUES ('delete', old.rowid, old.title, old.text);\n INSERT INTO fts_pages (rowid, title, text) VALUES (new.rowid, new.title, new.text);\n END" }, {"kind": "trigger","name": "fts_people_ad","tbl_name": "cotton_people","sql": "CREATE TRIGGER fts_people_ad AFTER DELETE ON cotton_people WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_people'), 0) BEGIN\n INSERT INTO fts_people (fts_people, rowid, full_name, org, role_title, summary) VALUES ('delete', old.rowid, old.full_name, old.org, old.role_title, old.summary);\n END" }, {"kind": "trigger","name": "fts_people_ai","tbl_name": "cotton_people","sql": "CREATE TRIGGER fts_people_ai AFTER INSERT ON cotton_people WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_people'), 0) BEGIN\n INSERT INTO fts_people (rowid, full_name, org, role_title, summary) VALUES (new.rowid, new.full_name, new.org, new.role_title, new.summary);\n END" }, {"kind": "trigger","name": "fts_people_au","tbl_name": "cotton_people","sql": "CREATE TRIGGER fts_people_au AFTER UPDATE OF full_name, org, role_title, summary ON cotton_people\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_people'), 0) AND (new.full_name IS NOT old.full_name OR new.org IS NOT old.org OR new.role_title IS NOT old.role_title OR new.summary IS NOT old.summary) BEGIN\n INSERT INTO fts_people (fts_people, rowid, full_name, org, role_title, summary) VALUES ('delete', old.rowid, old.full_name, old.org, old.role_title, old.summary);\n INSERT INTO fts_people (rowid, full_name, org, role_title, summary) VALUES (new.rowid, new.full_name, new.org, new.role_title, new.summary);\n END" }, {"kind": "trigger","name": "fts_photos_ad","tbl_name": "cotton_photos","sql": "CREATE TRIGGER fts_photos_ad AFTER DELETE ON cotton_photos WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_photos'), 0) BEGIN\n INSERT INTO fts_photos (fts_photos, rowid, caption, summary, ocr_text) VALUES ('delete', old.rowid, old.caption, old.summary, old.ocr_text);\n END" }, {"kind": "trigger","name": "fts_photos_ai","tbl_name": "cotton_photos","sql": "CREATE TRIGGER fts_photos_ai AFTER INSERT ON cotton_photos WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_photos'), 0) BEGIN\n INSERT INTO fts_photos (rowid, caption, summary, ocr_text) VALUES (new.rowid, new.caption, new.summary, new.ocr_text);\n END" }, {"kind": "trigger","name": "fts_photos_au","tbl_name": "cotton_photos","sql": "CREATE TRIGGER fts_photos_au AFTER UPDATE OF caption, summary, ocr_text ON cotton_photos\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_photos'), 0) AND (new.caption IS NOT old.caption OR new.summary IS NOT old.summary OR new.ocr_text IS NOT old.ocr_text) BEGIN\n INSERT INTO fts_photos (fts_photos, rowid, caption, summary, ocr_text) VALUES ('delete', old.rowid, old.caption, old.summary, old.ocr_text);\n INSERT INTO fts_photos (rowid, caption, summary, ocr_text) VALUES (new.rowid, new.caption, new.summary, new.ocr_text);\n END" }, {"kind": "trigger","name": "fts_posts_ad","tbl_name": "cotton_posts","sql": "CREATE TRIGGER fts_posts_ad AFTER DELETE ON cotton_posts WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_posts'), 0) BEGIN\n INSERT INTO fts_posts (fts_posts, rowid, caption, author_name, author_handle) VALUES ('delete', old.rowid, old.caption, old.author_name, old.author_handle);\n END" }, {"kind": "trigger","name": "fts_posts_ai","tbl_name": "cotton_posts","sql": "CREATE TRIGGER fts_posts_ai AFTER INSERT ON cotton_posts WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_posts'), 0) BEGIN\n INSERT INTO fts_posts (rowid, caption, author_name, author_handle) VALUES (new.rowid, new.caption, new.author_name, new.author_handle);\n END" }, {"kind": "trigger","name": "fts_posts_au","tbl_name": "cotton_posts","sql": "CREATE TRIGGER fts_posts_au AFTER UPDATE OF caption, author_name, author_handle ON cotton_posts\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_posts'), 0) AND (new.caption IS NOT old.caption OR new.author_name IS NOT old.author_name OR new.author_handle IS NOT old.author_handle) BEGIN\n INSERT INTO fts_posts (fts_posts, rowid, caption, author_name, author_handle) VALUES ('delete', old.rowid, old.caption, old.author_name, old.author_handle);\n INSERT INTO fts_posts (rowid, caption, author_name, author_handle) VALUES (new.rowid, new.caption, new.author_name, new.author_handle);\n END" }, {"kind": "trigger","name": "fts_prompts_ad","tbl_name": "cotton_prompts","sql": "CREATE TRIGGER fts_prompts_ad AFTER DELETE ON cotton_prompts WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_prompts'), 0) BEGIN\n INSERT INTO fts_prompts (fts_prompts, rowid, text) VALUES ('delete', old.rowid, old.text);\n END" }, {"kind": "trigger","name": "fts_prompts_ai","tbl_name": "cotton_prompts","sql": "CREATE TRIGGER fts_prompts_ai AFTER INSERT ON cotton_prompts WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_prompts'), 0) BEGIN\n INSERT INTO fts_prompts (rowid, text) VALUES (new.rowid, new.text);\n END" }, {"kind": "trigger","name": "fts_prompts_au","tbl_name": "cotton_prompts","sql": "CREATE TRIGGER fts_prompts_au AFTER UPDATE OF text ON cotton_prompts\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_prompts'), 0) AND (new.text IS NOT old.text) BEGIN\n INSERT INTO fts_prompts (fts_prompts, rowid, text) VALUES ('delete', old.rowid, old.text);\n INSERT INTO fts_prompts (rowid, text) VALUES (new.rowid, new.text);\n END" }, {"kind": "trigger","name": "fts_repo_issues_ad","tbl_name": "cotton_repo_issues","sql": "CREATE TRIGGER fts_repo_issues_ad AFTER DELETE ON cotton_repo_issues WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_repo_issues'), 0) BEGIN\n INSERT INTO fts_repo_issues (fts_repo_issues, rowid, title, body) VALUES ('delete', old.rowid, old.title, old.body);\n END" }, {"kind": "trigger","name": "fts_repo_issues_ai","tbl_name": "cotton_repo_issues","sql": "CREATE TRIGGER fts_repo_issues_ai AFTER INSERT ON cotton_repo_issues WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_repo_issues'), 0) BEGIN\n INSERT INTO fts_repo_issues (rowid, title, body) VALUES (new.rowid, new.title, new.body);\n END" }, {"kind": "trigger","name": "fts_repo_issues_au","tbl_name": "cotton_repo_issues","sql": "CREATE TRIGGER fts_repo_issues_au AFTER UPDATE OF title, body ON cotton_repo_issues\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_repo_issues'), 0) AND (new.title IS NOT old.title OR new.body IS NOT old.body) BEGIN\n INSERT INTO fts_repo_issues (fts_repo_issues, rowid, title, body) VALUES ('delete', old.rowid, old.title, old.body);\n INSERT INTO fts_repo_issues (rowid, title, body) VALUES (new.rowid, new.title, new.body);\n END" }, {"kind": "trigger","name": "fts_repo_pulls_ad","tbl_name": "cotton_repo_pulls","sql": "CREATE TRIGGER fts_repo_pulls_ad AFTER DELETE ON cotton_repo_pulls WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_repo_pulls'), 0) BEGIN\n INSERT INTO fts_repo_pulls (fts_repo_pulls, rowid, title, body) VALUES ('delete', old.rowid, old.title, old.body);\n END" }, {"kind": "trigger","name": "fts_repo_pulls_ai","tbl_name": "cotton_repo_pulls","sql": "CREATE TRIGGER fts_repo_pulls_ai AFTER INSERT ON cotton_repo_pulls WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_repo_pulls'), 0) BEGIN\n INSERT INTO fts_repo_pulls (rowid, title, body) VALUES (new.rowid, new.title, new.body);\n END" }, {"kind": "trigger","name": "fts_repo_pulls_au","tbl_name": "cotton_repo_pulls","sql": "CREATE TRIGGER fts_repo_pulls_au AFTER UPDATE OF title, body ON cotton_repo_pulls\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_repo_pulls'), 0) AND (new.title IS NOT old.title OR new.body IS NOT old.body) BEGIN\n INSERT INTO fts_repo_pulls (fts_repo_pulls, rowid, title, body) VALUES ('delete', old.rowid, old.title, old.body);\n INSERT INTO fts_repo_pulls (rowid, title, body) VALUES (new.rowid, new.title, new.body);\n END" }, {"kind": "trigger","name": "fts_secrets_ad","tbl_name": "cotton_secrets","sql": "CREATE TRIGGER fts_secrets_ad AFTER DELETE ON cotton_secrets WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_secrets'), 0) BEGIN\n INSERT INTO fts_secrets (fts_secrets, rowid, name, site, username, service) VALUES ('delete', old.rowid, old.name, old.site, old.username, old.service);\n END" }, {"kind": "trigger","name": "fts_secrets_ai","tbl_name": "cotton_secrets","sql": "CREATE TRIGGER fts_secrets_ai AFTER INSERT ON cotton_secrets WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_secrets'), 0) BEGIN\n INSERT INTO fts_secrets (rowid, name, site, username, service) VALUES (new.rowid, new.name, new.site, new.username, new.service);\n END" }, {"kind": "trigger","name": "fts_secrets_au","tbl_name": "cotton_secrets","sql": "CREATE TRIGGER fts_secrets_au AFTER UPDATE OF name, site, username, service ON cotton_secrets\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_secrets'), 0) AND (new.name IS NOT old.name OR new.site IS NOT old.site OR new.username IS NOT old.username OR new.service IS NOT old.service) BEGIN\n INSERT INTO fts_secrets (fts_secrets, rowid, name, site, username, service) VALUES ('delete', old.rowid, old.name, old.site, old.username, old.service);\n INSERT INTO fts_secrets (rowid, name, site, username, service) VALUES (new.rowid, new.name, new.site, new.username, new.service);\n END" }, {"kind": "trigger","name": "fts_session_messages_ad","tbl_name": "cotton_session_messages","sql": "CREATE TRIGGER fts_session_messages_ad AFTER DELETE ON cotton_session_messages WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_session_messages'), 0) BEGIN\n INSERT INTO fts_session_messages (fts_session_messages, rowid, body) VALUES ('delete', old.rowid, old.body);\n END" }, {"kind": "trigger","name": "fts_session_messages_ai","tbl_name": "cotton_session_messages","sql": "CREATE TRIGGER fts_session_messages_ai AFTER INSERT ON cotton_session_messages WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_session_messages'), 0) BEGIN\n INSERT INTO fts_session_messages (rowid, body) VALUES (new.rowid, new.body);\n END" }, {"kind": "trigger","name": "fts_session_messages_au","tbl_name": "cotton_session_messages","sql": "CREATE TRIGGER fts_session_messages_au AFTER UPDATE OF body ON cotton_session_messages\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_session_messages'), 0) AND (new.body IS NOT old.body) BEGIN\n INSERT INTO fts_session_messages (fts_session_messages, rowid, body) VALUES ('delete', old.rowid, old.body);\n INSERT INTO fts_session_messages (rowid, body) VALUES (new.rowid, new.body);\n END" }, {"kind": "trigger","name": "fts_thoughts_ad","tbl_name": "cotton_inbox_items","sql": "CREATE TRIGGER fts_thoughts_ad AFTER DELETE ON cotton_inbox_items WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_thoughts'), 0) BEGIN\n INSERT INTO fts_thoughts (fts_thoughts, rowid, raw_text) VALUES ('delete', old.rowid, old.raw_text);\n END" }, {"kind": "trigger","name": "fts_thoughts_ai","tbl_name": "cotton_inbox_items","sql": "CREATE TRIGGER fts_thoughts_ai AFTER INSERT ON cotton_inbox_items WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_thoughts'), 0) BEGIN\n INSERT INTO fts_thoughts (rowid, raw_text) VALUES (new.rowid, new.raw_text);\n END" }, {"kind": "trigger","name": "fts_thoughts_au","tbl_name": "cotton_inbox_items","sql": "CREATE TRIGGER fts_thoughts_au AFTER UPDATE OF raw_text ON cotton_inbox_items\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_thoughts'), 0) AND (new.raw_text IS NOT old.raw_text) BEGIN\n INSERT INTO fts_thoughts (fts_thoughts, rowid, raw_text) VALUES ('delete', old.rowid, old.raw_text);\n INSERT INTO fts_thoughts (rowid, raw_text) VALUES (new.rowid, new.raw_text);\n END" }, {"kind": "trigger","name": "fts_todos_ad","tbl_name": "cotton_todos","sql": "CREATE TRIGGER fts_todos_ad AFTER DELETE ON cotton_todos WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_todos'), 0) BEGIN\n INSERT INTO fts_todos (fts_todos, rowid, title, notes) VALUES ('delete', old.rowid, old.title, old.notes);\n END" }, {"kind": "trigger","name": "fts_todos_ai","tbl_name": "cotton_todos","sql": "CREATE TRIGGER fts_todos_ai AFTER INSERT ON cotton_todos WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_todos'), 0) BEGIN\n INSERT INTO fts_todos (rowid, title, notes) VALUES (new.rowid, new.title, new.notes);\n END" }, {"kind": "trigger","name": "fts_todos_au","tbl_name": "cotton_todos","sql": "CREATE TRIGGER fts_todos_au AFTER UPDATE OF title, notes ON cotton_todos\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_todos'), 0) AND (new.title IS NOT old.title OR new.notes IS NOT old.notes) BEGIN\n INSERT INTO fts_todos (fts_todos, rowid, title, notes) VALUES ('delete', old.rowid, old.title, old.notes);\n INSERT INTO fts_todos (rowid, title, notes) VALUES (new.rowid, new.title, new.notes);\n END" }, {"kind": "trigger","name": "fts_videos_ad","tbl_name": "cotton_videos","sql": "CREATE TRIGGER fts_videos_ad AFTER DELETE ON cotton_videos WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_videos'), 0) BEGIN\n INSERT INTO fts_videos (fts_videos, rowid, caption, summary) VALUES ('delete', old.rowid, old.caption, old.summary);\n END" }, {"kind": "trigger","name": "fts_videos_ai","tbl_name": "cotton_videos","sql": "CREATE TRIGGER fts_videos_ai AFTER INSERT ON cotton_videos WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_videos'), 0) BEGIN\n INSERT INTO fts_videos (rowid, caption, summary) VALUES (new.rowid, new.caption, new.summary);\n END" }, {"kind": "trigger","name": "fts_videos_au","tbl_name": "cotton_videos","sql": "CREATE TRIGGER fts_videos_au AFTER UPDATE OF caption, summary ON cotton_videos\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_videos'), 0) AND (new.caption IS NOT old.caption OR new.summary IS NOT old.summary) BEGIN\n INSERT INTO fts_videos (fts_videos, rowid, caption, summary) VALUES ('delete', old.rowid, old.caption, old.summary);\n INSERT INTO fts_videos (rowid, caption, summary) VALUES (new.rowid, new.caption, new.summary);\n END" }]