Skip to main content

Nquiry Data Dictionary

Last Updated: 2026-02-10 (last reviewed 2026-04-29) Database: Amazon RDS PostgreSQL Application: Nquiry - Compliance-critical investigation management


Table of Contents

  1. Core Tables
  2. Multi-Tenant Tables
  3. Investigation Tables
  4. Evidence Tables
  5. Analysis & Reporting Tables
  6. Billing & Usage Tables
  7. Template Tables
  8. Audit & Compliance Tables
  9. Enum Types
  10. Helper Functions

Core Tables

user_profile

User account information, linked to Cognito auth.

ColumnTypeNullableDefaultDescription
profile_idUUIDNOuuid_generate_v4()Primary key
user_idUUIDNO-Reference to auth.users(id)
emailTEXTYES-User email address
full_nameTEXTYES-Display name
roleTEXTNO'user'System role: user, admin, manager
current_organization_idUUIDYES-Currently selected organization
created_atTIMESTAMPTZYESNOW()Record creation timestamp
updated_atTIMESTAMPTZYESNOW()Last update timestamp

Constraints: UNIQUE(user_id), role IN ('user', 'admin', 'manager')


Multi-Tenant Tables

organization

Teams and personal workspaces. Every user has at least one.

ColumnTypeNullableDefaultDescription
organization_idUUIDNOgen_random_uuid()Primary key
nameTEXTNO-Organization display name
slugTEXTNO-URL-friendly identifier (unique)
typeTEXTNO'personal'personal or team
billing_emailTEXTYES-Email for billing notifications
billing_statusTEXTYES'trial'trial, active, past_due, canceled
billing_planTEXTYES'trial'trial, professional, team, enterprise
stripe_customer_idTEXTYES-Stripe customer ID (unique)
stripe_subscription_idTEXTYES-Stripe subscription ID (unique)
settingsJSONBYES'{}'Organization-specific settings
storage_used_bytesBIGINTNO0Current storage usage
storage_quota_bytesBIGINTNO2147483648Max storage (default 2GB for trial)
ai_usage_limitINTEGERYES25Max AI generations (25 total for trial)
current_period_startDATEYES-Billing period start date
current_period_endDATEYES-Billing period end date
trial_started_atTIMESTAMPTZYES-When the trial period began
trial_ends_atTIMESTAMPTZYES-When the trial period expires (14 days)
trial_investigation_limitINTEGERYES1Max investigations completable during trial
completed_investigation_countINTEGERYES0Number of investigations marked complete
trial_ai_usedINTEGERYES0Total AI generations used during trial (not reset)
created_atTIMESTAMPTZNOnow()Record creation timestamp
updated_atTIMESTAMPTZNOnow()Last update timestamp

Constraints: type IN ('personal', 'team'), billing_status IN ('trial', 'active', 'past_due', 'canceled'), billing_plan IN ('trial', 'professional', 'team', 'enterprise')

organization_member

User membership in organizations with role-based access.

ColumnTypeNullableDefaultDescription
member_idUUIDNOgen_random_uuid()Primary key
organization_idUUIDNO-FK to organization
user_idUUIDNO-FK to auth.users
roleTEXTNO'member'owner, admin, member, viewer
invited_byUUIDYES-User who sent the invite
joined_atTIMESTAMPTZYESnow()When user joined
created_atTIMESTAMPTZNOnow()Record creation timestamp
updated_atTIMESTAMPTZNOnow()Last update timestamp

Constraints: UNIQUE(organization_id, user_id), role IN ('owner', 'admin', 'member', 'viewer')

Role Hierarchy: owner > admin > member > viewer

organization_invitation

Pending invitations to join an organization.

ColumnTypeNullableDefaultDescription
invitation_idUUIDNOgen_random_uuid()Primary key
organization_idUUIDNO-FK to organization
emailTEXTNO-Invited email address
roleTEXTNO'member'Role to assign on acceptance
tokenTEXTNOrandom hexUnique invitation token
invited_byUUIDNO-User who created invitation
expires_atTIMESTAMPTZNOnow() + 7 daysToken expiration
accepted_atTIMESTAMPTZYES-When invitation was accepted
created_atTIMESTAMPTZNOnow()Record creation timestamp

Constraints: UNIQUE(organization_id, email), role IN ('admin', 'member', 'viewer')

investigation_member

Per-investigation membership for the inquiry-centric model (NQU-115). Tracks who has access to each investigation.

ColumnTypeNullableDefaultDescription
member_idUUIDNOgen_random_uuid()Primary key
investigation_idUUIDNO-FK to investigation
user_idUUIDNO-FK to auth.users
roleTEXTNO'member'owner or member
invited_byUUIDYES-User who sent the invite
joined_atTIMESTAMPTZYESnow()When user joined
created_atTIMESTAMPTZNOnow()Record creation timestamp

Constraints: UNIQUE(investigation_id, user_id), role IN ('owner', 'member')

Backfill: Existing investigation creators were backfilled with role='owner' on migration.

inquiry_invitation

Pending invitations to join an investigation (NQU-115).

ColumnTypeNullableDefaultDescription
invitation_idUUIDNOgen_random_uuid()Primary key
investigation_idUUIDNO-FK to investigation
emailTEXTNO-Invited email address
roleTEXTNO'member'Role to assign on acceptance
invited_byUUIDNO-User who created invitation
tokenTEXTNOrandom hex (32 bytes)Unique invitation token
expires_atTIMESTAMPTZNOnow() + 7 daysToken expiration
accepted_atTIMESTAMPTZYES-When invitation was accepted
created_atTIMESTAMPTZNOnow()Record creation timestamp

Constraints: UNIQUE(investigation_id, email), role IN ('member')


Investigation Tables

investigation

Core project/case entity. Supports multiple work types.

ColumnTypeNullableDefaultDescription
investigation_idUUIDNOuuid_generate_v4()Primary key
organization_idUUIDNO-FK to organization
created_byUUIDNO-User who created it
titleTEXTNO-Project title
focus_statementTEXTYES-Scope/purpose statement
statusTEXTNO'planning'Workflow status
work_typework_typeNO'investigation'Type of engagement
custom_work_type_labelTEXTYES-Custom label when work_type='other'
source_template_idUUIDYES-Template used to create this project
created_atTIMESTAMPTZYESNOW()Record creation timestamp
updated_atTIMESTAMPTZYESNOW()Last update timestamp

Constraints:

  • status IN ('planning', 'collection', 'analysis', 'reporting', 'complete', 'archived')
  • custom_work_type_label required when work_type = 'other'

topic

Logical groupings of questions within an investigation.

ColumnTypeNullableDefaultDescription
topic_idUUIDNOuuid_generate_v4()Primary key
investigation_idUUIDNO-FK to investigation
titleTEXTNO-Topic title
descriptionTEXTYES-Topic description
investigator_notesTEXTYES-Internal notes
sequence_orderINTEGERNO0Display order
created_atTIMESTAMPTZYESNOW()Record creation timestamp
updated_atTIMESTAMPTZYESNOW()Last update timestamp

question

Questions to be answered by the investigation.

ColumnTypeNullableDefaultDescription
question_idUUIDNOuuid_generate_v4()Primary key
investigation_idUUIDNO-FK to investigation
topic_idUUIDYES-FK to topic (optional grouping)
question_textTEXTNO-The question text
sequence_orderINTEGERNO0Display order
finding_statusTEXTNO'pending'Finding determination
finding_summaryTEXTYES-Summary of finding
created_atTIMESTAMPTZYESNOW()Record creation timestamp
updated_atTIMESTAMPTZYESNOW()Last update timestamp

Constraints: finding_status IN ('pending', 'substantiated', 'not_substantiated', 'inconclusive')

background_document

Investigation context documents (charge letters, org charts, etc.).

ColumnTypeNullableDefaultDescription
background_doc_idUUIDNOgen_random_uuid()Primary key
investigation_idUUIDNO-FK to investigation
titleTEXTNO-Document title
descriptionTEXTYES-Document description
document_typebackground_document_typeYES'other'Type of document
file_pathTEXTYES-S3 path
file_typeTEXTYES-MIME type
file_sizeBIGINTYES-Size in bytes
content_textTEXTYES-Extracted text content
include_in_analysisBOOLEANYEStrueInclude in AI analysis
display_orderINTEGERYES0Display order
created_atTIMESTAMPTZYESnow()Record creation timestamp
updated_atTIMESTAMPTZYESnow()Last update timestamp

framework_document

Evaluation frameworks, policies, standards attached to investigation.

ColumnTypeNullableDefaultDescription
document_idUUIDNOuuid_generate_v4()Primary key
investigation_idUUIDNO-FK to investigation
titleTEXTNO-Document title
file_nameTEXTNO-Original filename
file_pathTEXTNO-S3 storage path
file_sizeINTEGERYES-Size in bytes
document_typeTEXTNO'other'policy, standard, framework, regulation, other
descriptionTEXTYES-Document description
display_orderINTEGERYES0Display order
include_in_analysisBOOLEANYEStrueInclude in AI analysis
uploaded_atTIMESTAMPTZYESNOW()Upload timestamp
created_atTIMESTAMPTZYESNOW()Record creation timestamp
updated_atTIMESTAMPTZYESNOW()Last update timestamp

Evidence Tables

evidence

Evidence items collected for an investigation.

ColumnTypeNullableDefaultDescription
evidence_idUUIDNOuuid_generate_v4()Primary key
investigation_idUUIDNO-FK to investigation
evidence_typeTEXTNO-document, interview, website, observation, dataset, note, standard
titleTEXTNO-Evidence title
descriptionTEXTYES-Evidence description
content_textTEXTYES-Text content or transcript
sourceTEXTYES-Source of evidence
source_dateDATEYES-Date of source material
investigator_notesTEXTYES-Internal notes
to_be_collectedBOOLEANNOtrueWhether evidence is pending collection (auto-toggles to false when content is added)
collected_atTIMESTAMPTZYESNOW()When evidence was collected
created_atTIMESTAMPTZYESNOW()Record creation timestamp
updated_atTIMESTAMPTZYESNOW()Last update timestamp

Constraints: evidence_type IN ('document', 'interview', 'website', 'observation', 'dataset', 'note', 'standard')

evidence_attachment

File attachments for evidence items.

ColumnTypeNullableDefaultDescription
attachment_idUUIDNOuuid_generate_v4()Primary key
evidence_idUUIDNO-FK to evidence
file_nameTEXTNO-Original filename
file_pathTEXTNO-S3 storage path
file_typeTEXTNO-MIME type
file_sizeINTEGERYES-Size in bytes
extracted_textTEXTYES-OCR/extracted text
display_orderINTEGERNO0Display order
uploaded_atTIMESTAMPTZYESNOW()Upload timestamp

evidence_note

Notes/annotations on evidence items.

ColumnTypeNullableDefaultDescription
note_idUUIDNOuuid_generate_v4()Primary key
evidence_idUUIDNO-FK to evidence
user_idUUIDNO-User who created note
note_textTEXTNO-Note content
note_typeTEXTNO'general'observation, analysis, follow_up, concern, general
created_atTIMESTAMPTZYESNOW()Record creation timestamp
updated_atTIMESTAMPTZYESNOW()Last update timestamp

Many-to-many relationship between evidence and questions.

ColumnTypeNullableDefaultDescription
link_idUUIDNOuuid_generate_v4()Primary key
question_idUUIDNO-FK to question
evidence_idUUIDNO-FK to evidence
relevance_notesTEXTYES-Why this evidence is relevant
created_atTIMESTAMPTZYESNOW()Record creation timestamp

Constraints: UNIQUE(question_id, evidence_id)


Analysis & Reporting Tables

analysis

AI-generated analyses for investigations.

ColumnTypeNullableDefaultDescription
analysis_idUUIDNOuuid_generate_v4()Primary key
investigation_idUUIDNO-FK to investigation
question_idUUIDYES-FK to question (for question-specific analysis)
topic_idUUIDYES-FK to topic (for topic-specific analysis)
analysis_typeTEXTNO-Type of analysis
analysis_textTEXTNO-Generated analysis content
structured_outputJSONBYES-Validated JSON output matching analysis schema
retrieval_statsJSONBYES-Similarity score stats from semantic search
faithfulness_scoreFLOATYES-Ratio of claims grounded in evidence (0-1)
faithfulness_detailsJSONBYES-Detailed claim verification results
coverage_scoreFLOATYES-Ratio of question elements addressed (0-1)
coverage_detailsJSONBYES-Elements checked and gaps identified
quality_confidenceTEXTYES-Overall quality: established/probable/possible/insufficient
evidence_citedJSONBYES-Evidence references used
ai_model_versionTEXTYES-Model used for generation
prompt_idUUIDYES-FK to prompt_template used
prompt_versionINTEGERYES-Version of prompt at generation time
validation_passedBOOLEANYES-Whether output passed Zod schema validation
validation_errorsJSONBYES-Validation error details if failed
user_feedbackTEXTYES-User feedback on analysis
feedback_incorporatedBOOLEANYESfalseWhether feedback was applied
iteration_numberINTEGERYES1Regeneration count
user_actionTEXTYES-Latest user feedback action on this analysis
user_action_atTIMESTAMPTZYES-When user_action was last set
user_action_metadataJSONBYES'{}'Additional metadata for the user action
detail_reviewed_atTIMESTAMPTZYES-When investigator first expanded the detail section
citation_checked_atTIMESTAMPTZYES-When investigator first opened a citation in the side panel
generation_started_atTIMESTAMPTZYES-Set before Claude API call; enables orphan staleness detection
generation_retry_countINTEGERNO0Number of orphan recovery retries (max 2)
generation_errorTEXTYES-Error message when generation_status = 'failed'
created_atTIMESTAMPTZYESNOW()Record creation timestamp
updated_atTIMESTAMPTZYESNOW()Last update timestamp

Constraints:

  • analysis_type IN ('question_analysis', 'overall_summary', 'gap_analysis', 'error_check', 'topic_analysis')
  • quality_confidence IN ('established', 'probable', 'possible', 'insufficient')
  • user_action IN ('viewed', 'regenerated', 'edited', 'accepted', 'rejected', 'needs_revision')

Prompt Traceability: Every analysis records prompt_id and prompt_version to enable performance tracking and rollback analysis.

Quality Metrics: Each analysis stores comprehensive quality metrics:

  • retrieval_stats: Semantic search similarity scores and distribution
  • faithfulness_score/details: Verification that claims are grounded in evidence
  • coverage_score/details: Verification that all question elements are addressed
  • quality_confidence: Overall confidence level mapped to evidence framework

User Feedback Tracking: Each analysis tracks the latest user action (agree, disagree, needs_revision, regenerate, edit, view) for measuring AI quality outcomes. Full event history is stored in analysis_feedback.

Engagement Gates: detail_reviewed_at and citation_checked_at track investigator engagement before allowing judgment. Both gates must be unlocked (non-NULL) before the Agree/Disagree/Unsure controls become active. Gate timestamps are set once and persist across sessions.

Generation Durability (NQU-167): generation_started_at, generation_retry_count, and generation_error enable orphan recovery on server restart. If a container dies mid-generation, the orphan recovery module detects stale records via generation_started_at and marks them failed. Quality checks that were interrupted are re-triggered automatically. Max 2 retries per record.

analysis_feedback

Event history of user feedback actions on analyses. Supports tracking the full lifecycle of user interaction with AI output.

ColumnTypeNullableDefaultDescription
feedback_idUUIDNOgen_random_uuid()Primary key
analysis_idUUIDNO-FK to analysis
user_idUUIDNO-User who took the action
actionTEXTNO-Feedback action: viewed, regenerated, edited, accepted, rejected, needs_revision
reasonTEXTYES-Optional reason (e.g., why regenerated or rejected)
feedback_categoriesTEXT[]YES'{}'Multi-select rejection taxonomy categories (NQU-138)
metadataJSONBYES'{}'Additional context (edit details, etc.)
created_atTIMESTAMPTZYESNOW()When the feedback event occurred

Constraints: action IN ('viewed', 'regenerated', 'edited', 'accepted', 'rejected', 'needs_revision')

Indexes:

  • idx_analysis_feedback_analysis_id on (analysis_id)
  • idx_analysis_feedback_user_id on (user_id)
  • idx_analysis_feedback_action on (action)
  • idx_analysis_feedback_created_at on (created_at)
  • idx_analysis_feedback_categories GIN on (feedback_categories) WHERE feedback_categories != '{}'
  • idx_analysis_feedback_rejected on (created_at DESC) WHERE action = 'rejected'

report

Generated reports from investigations.

ColumnTypeNullableDefaultDescription
report_idUUIDNOuuid_generate_v4()Primary key
investigation_idUUIDNO-FK to investigation
version_numberINTEGERNO1Report version
statusTEXTNO'draft'draft, review, final
content_structuredJSONBYES-Structured report content
content_fullTEXTYES-Full text content
endnotesJSONBYES-Citations/references
generated_atTIMESTAMPTZYESNOW()Generation timestamp
finalized_atTIMESTAMPTZYES-When marked final

prompt_template

AI prompt templates for analysis generation.

ColumnTypeNullableDefaultDescription
prompt_idUUIDNOuuid_generate_v4()Primary key
prompt_typeTEXTNO-Unique prompt identifier
prompt_nameTEXTNO-Display name
system_promptTEXTNO-System message template
user_prompt_templateTEXTNO-User message template
is_activeBOOLEANYEStrueWhether currently in use
versionINTEGERYES1Auto-incremented on content changes
created_atTIMESTAMPTZYESNOW()Record creation timestamp
updated_atTIMESTAMPTZYESNOW()Last update timestamp

Trigger: trg_archive_prompt_version - Automatically archives previous version to prompt_template_history on UPDATE.

prompt_template_history

Version history for prompt templates. Enables rollback and audit of prompt changes.

ColumnTypeNullableDefaultDescription
history_idUUIDNOgen_random_uuid()Primary key
prompt_idUUIDNO-FK to prompt_template
prompt_typeTEXTNO-Prompt type at time of archive
prompt_nameTEXTNO-Name at time of archive
system_promptTEXTNO-System prompt at time of archive
user_prompt_templateTEXTNO-User prompt at time of archive
versionINTEGERNO-Version number that was replaced
was_activeBOOLEANNO-Whether prompt was active
changed_byUUIDYES-FK to user_profile (if tracked)
change_reasonTEXTYES-Optional reason for change
archived_atTIMESTAMPTZNONOW()When this version was replaced
original_created_atTIMESTAMPTZYES-Original created_at value
original_updated_atTIMESTAMPTZYES-Original updated_at value

Helper Functions:

  • get_prompt_history(prompt_type) - Returns all versions including current
  • get_prompt_version(prompt_type, version) - Returns full content of a specific version
  • rollback_prompt(prompt_type, version, reason) - Restores a previous version
  • compare_prompt_versions(prompt_type, v1, v2) - Side-by-side comparison

Billing & Usage Tables

ai_usage

Tracks AI generation usage for billing quota enforcement.

ColumnTypeNullableDefaultDescription
usage_idUUIDNOgen_random_uuid()Primary key
organization_idUUIDNO-FK to organization
user_idUUIDNO-User who triggered usage
usage_typeTEXTNO-Type of AI operation
tokens_inputINTEGERYES-Input tokens consumed
tokens_outputINTEGERYES-Output tokens generated
cost_usdDECIMAL(10,6)YES-Estimated cost in USD
billing_period_startDATENO-Period start date
billing_period_endDATENO-Period end date
created_atTIMESTAMPTZNOnow()Record creation timestamp

Constraints: usage_type IN ('analysis_generation', 'analysis_regeneration', 'ai_chat', 'report_section')

storage_usage

Detailed tracking of file storage per organization.

ColumnTypeNullableDefaultDescription
usage_idUUIDNOgen_random_uuid()Primary key
organization_idUUIDNO-FK to organization
bucket_nameTEXTNO-S3 bucket name
file_pathTEXTNO-Full file path
file_size_bytesBIGINTNO-File size
file_typeTEXTYES-MIME type
uploaded_byUUIDYES-User who uploaded
created_atTIMESTAMPTZNOnow()Upload timestamp

Constraints: UNIQUE(organization_id, bucket_name, file_path)


Template Tables

project_template

Reusable templates for creating new projects.

ColumnTypeNullableDefaultDescription
template_idUUIDNOgen_random_uuid()Primary key
organization_idUUIDNO-FK to organization
nameVARCHAR(200)NO-Template name
descriptionTEXTYES-Template description
work_typeVARCHAR(50)YES'investigation'Default work type
created_byUUIDNO-User who created template
created_atTIMESTAMPTZYESNOW()Record creation timestamp
updated_atTIMESTAMPTZYESNOW()Last update timestamp

template_topic

Topics within a project template.

ColumnTypeNullableDefaultDescription
template_topic_idUUIDNOgen_random_uuid()Primary key
template_idUUIDNO-FK to project_template
titleVARCHAR(200)NO-Topic title
descriptionTEXTYES-Topic description
investigator_notesTEXTYES-Default notes
sequence_orderINTEGERYES0Display order
created_atTIMESTAMPTZYESNOW()Record creation timestamp

template_question

Questions within a project template.

ColumnTypeNullableDefaultDescription
template_question_idUUIDNOgen_random_uuid()Primary key
template_idUUIDNO-FK to project_template
template_topic_idUUIDYES-FK to template_topic
question_textTEXTNO-Question text
sequence_orderINTEGERYES0Display order
created_atTIMESTAMPTZYESNOW()Record creation timestamp

template_background_document

Background documents within a project template.

ColumnTypeNullableDefaultDescription
template_bg_doc_idUUIDNOgen_random_uuid()Primary key
template_idUUIDNO-FK to project_template
titleVARCHAR(200)NO-Document title
descriptionTEXTYES-Document description
document_typeVARCHAR(50)YES-Type of document
file_nameVARCHAR(255)YES-Original filename
file_pathVARCHAR(500)YES-S3 storage path
file_typeVARCHAR(100)YES-MIME type
file_sizeINTEGERYES-Size in bytes
display_orderINTEGERYES0Display order
created_atTIMESTAMPTZYESNOW()Record creation timestamp

template_framework_document

Framework documents within a project template.

ColumnTypeNullableDefaultDescription
template_fw_doc_idUUIDNOgen_random_uuid()Primary key
template_idUUIDNO-FK to project_template
titleVARCHAR(200)NO-Document title
descriptionTEXTYES-Document description
document_typeVARCHAR(50)YES-Type of document
file_nameVARCHAR(255)YES-Original filename
file_pathVARCHAR(500)YES-S3 storage path
file_typeVARCHAR(100)YES-MIME type
file_sizeINTEGERYES-Size in bytes
display_orderINTEGERYES0Display order
created_atTIMESTAMPTZYESNOW()Record creation timestamp

Audit & Compliance Tables

audit_log

Immutable audit trail for FedRAMP/HIPAA compliance.

ColumnTypeNullableDefaultDescription
log_idUUIDNOgen_random_uuid()Primary key
created_atTIMESTAMPTZNOnow()When action occurred
user_idUUIDYES-User who performed action
organization_idUUIDYES-Organization context
actionaudit_actionNO-Action type (enum)
resource_typeaudit_resource_typeNO-Resource type (enum)
resource_idUUIDYES-ID of affected resource
ip_addressINETYES-Client IP address
user_agentTEXTYES-Client user agent
metadataJSONBYES'{}'Additional context
successBOOLEANNOtrueWhether action succeeded
error_messageTEXTYES-Error details if failed
contains_phiBOOLEANYESfalseHIPAA: PHI was accessed

Note: This table is append-only. No updates or deletes allowed.


Enum Types

work_type

Project/investigation type:

  • evaluation
  • review
  • audit
  • inspection
  • investigation
  • inquiry
  • assessment
  • case
  • other

background_document_type

Context document types:

  • charge_letter
  • org_chart
  • scope_memo
  • policy
  • other

audit_action

Auditable actions (see audit_logging migration for full list):

  • Authentication: auth.login, auth.logout, auth.login_failed, auth.password_reset
  • Investigation: investigation.create, investigation.view, investigation.update, investigation.delete
  • Evidence: evidence.create, evidence.view, evidence.update, evidence.delete, evidence.download
  • Analysis: analysis.generate, analysis.view
  • Report: report.generate, report.view, report.download
  • Organization: organization.create, organization.update, member management
  • GDPR: gdpr.data_export, gdpr.account_delete

audit_resource_type

Auditable resource types:

  • user, organization, investigation, evidence, topic, question, analysis, report, invitation, system, prompt

Helper Functions

FunctionReturnsDescription
user_organization_ids()SETOF UUIDReturns all organization IDs for current user
user_has_org_access(org_id, min_role)BOOLEANChecks if user has at least min_role in org
is_admin()BOOLEANChecks if current user is system admin
handle_new_user()TRIGGERAuto-creates profile and personal org on signup
check_storage_quota(org_id, bytes)BOOLEANReturns true if upload fits within quota
get_storage_stats(org_id)TABLEReturns storage usage breakdown
get_ai_usage_count(org_id)INTEGERReturns AI usage count for current period
check_ai_usage_quota(org_id)BOOLEANReturns true if under AI usage limit
record_ai_usage(...)UUIDRecords an AI usage event
sync_billing_quotas(org_id)VOIDUpdates quotas based on billing status
cleanup_old_audit_logs(days)INTEGERRemoves audit logs older than retention period
get_prompt_history(prompt_type)TABLEReturns all versions of a prompt
get_prompt_version(prompt_type, version)TABLEReturns full content of a specific version
rollback_prompt(prompt_type, version, reason)INTEGERRestores a previous version, returns new ver
compare_prompt_versions(type, v1, v2)TABLESide-by-side comparison of two versions
archive_prompt_version()TRIGGERAuto-archives prompt before UPDATE
user_has_investigation_access(investigation_id)BOOLEANDual-check: investigation_member OR org membership

S3 Storage Buckets

BucketPurposePath Pattern
evidenceEvidence attachments{org_id}/{investigation_id}/{evidence_id}/{filename}
framework-documentsFramework/policy docs{org_id}/{investigation_id}/{document_id}/{filename}

Dropped Tables

These tables were removed and should not be used:

TableRemovedReplaced By
evaluation_guide2026-01-27framework_document
investigation_guide_link2026-01-27N/A (was junction table)