CREATE TYPE "public"."risk_level" AS ENUM('LOW', 'MEDIUM', 'HIGH', 'CRITICAL');--> statement-breakpoint
CREATE TYPE "public"."threat_type" AS ENUM('INTERNAL_XFER', 'MAKER_ONLY', 'BULK_ACCESS', 'AFTER_HOURS', 'GEO_ANOMALY', 'VELOCITY_BREACH');--> statement-breakpoint
CREATE TYPE "public"."user_role" AS ENUM('admin', 'risk_manager', 'auditor');--> statement-breakpoint
CREATE TYPE "public"."webhook_event" AS ENUM('THREAT_DETECTED', 'THREAT_NEUTRALIZED', 'SESSION_LOCKED', 'COMPLIANCE_ALERT', 'BIO_VAULT_BREACH');--> statement-breakpoint
CREATE TYPE "public"."webhook_integration" AS ENUM('FINACLE', 'T24', 'FLEXCUBE', 'CUSTOM', 'SMS_GATEWAY', 'EMAIL_GATEWAY');--> statement-breakpoint
CREATE TYPE "public"."ubo_erasure_state" AS ENUM('ACTIVE', 'SUPERSEDED', 'ERASED');--> statement-breakpoint
CREATE TYPE "public"."ubo_erasure_trigger" AS ENUM('corporate', 'departure', 'individual_pending', 'regulator_order');--> statement-breakpoint
CREATE TABLE "active_sessions" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"user_id" varchar NOT NULL,
	"session_token" text NOT NULL,
	"ip_address" text,
	"user_agent" text,
	"device_type" text,
	"geo_location" text,
	"risk_score" numeric(5, 4) DEFAULT '0',
	"is_revoked" boolean DEFAULT false NOT NULL,
	"revoked_by" varchar,
	"revoked_at" timestamp,
	"last_activity" timestamp DEFAULT NOW() NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"expires_at" timestamp NOT NULL
);
--> statement-breakpoint
CREATE TABLE "ai_threat_scores" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"threat_event_id" varchar,
	"model_version" text NOT NULL,
	"score" numeric(5, 4) NOT NULL,
	"confidence" numeric(5, 4) NOT NULL,
	"explanation" text,
	"factors" text,
	"processing_time_ms" integer,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "ai_thresholds" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"threshold_name" text NOT NULL,
	"threshold_value" numeric(10, 4) NOT NULL,
	"description" text,
	"updated_by" varchar,
	"updated_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "ai_thresholds_threshold_name_unique" UNIQUE("threshold_name")
);
--> statement-breakpoint
CREATE TABLE "api_keys" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"key_hash" text NOT NULL,
	"key_prefix" text NOT NULL,
	"tenant_id" text,
	"permissions" text,
	"rate_limit" integer DEFAULT 1000 NOT NULL,
	"is_active" boolean DEFAULT true NOT NULL,
	"last_used_at" timestamp,
	"expires_at" timestamp,
	"created_by" varchar,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "api_usage_metrics" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"endpoint" text NOT NULL,
	"method" text NOT NULL,
	"status_code" integer NOT NULL,
	"response_time_ms" integer NOT NULL,
	"user_id" varchar,
	"api_key_id" varchar,
	"tenant_id" text,
	"request_size" integer,
	"response_size" integer,
	"error_message" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "audit_logs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"timestamp" timestamp DEFAULT NOW() NOT NULL,
	"user_id" varchar,
	"action" text NOT NULL,
	"resource" text NOT NULL,
	"details" text,
	"ip_address" text,
	"previous_value" text,
	"new_value" text
);
--> statement-breakpoint
CREATE TABLE "backup_records" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"backup_type" text NOT NULL,
	"status" text NOT NULL,
	"size_bytes" integer,
	"tables_included" text,
	"duration" integer,
	"checksum" text,
	"storage_location" text,
	"retention_days" integer DEFAULT 90 NOT NULL,
	"initiated_by" varchar,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"completed_at" timestamp,
	"tenant_id" text
);
--> statement-breakpoint
CREATE TABLE "change_approvals" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"change_request_id" varchar,
	"approver_role" text NOT NULL,
	"decision" text NOT NULL,
	"comments" text,
	"decided_by" varchar,
	"decided_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "change_requests" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"change_id" text NOT NULL,
	"title" text NOT NULL,
	"description" text,
	"change_type" text NOT NULL,
	"risk_level" text DEFAULT 'low' NOT NULL,
	"status" text DEFAULT 'draft' NOT NULL,
	"requested_by" varchar,
	"approved_by" varchar,
	"implemented_by" varchar,
	"rollback_plan" text,
	"impact_assessment" text,
	"scheduled_at" timestamp,
	"implemented_at" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "cicd_pipeline_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"pipeline_id" text NOT NULL,
	"pipeline_name" text NOT NULL,
	"provider" text NOT NULL,
	"trigger_type" text NOT NULL,
	"status" text NOT NULL,
	"scope" text DEFAULT 'GLOBAL' NOT NULL,
	"dispatch_ok" integer DEFAULT 0 NOT NULL,
	"duration_ms" integer DEFAULT 0 NOT NULL,
	"triggered_by" text,
	"change_request_id" text,
	"commit_sha" text,
	"executed_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "compliance_check_results" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text NOT NULL,
	"run_id" varchar NOT NULL,
	"check_id" text NOT NULL,
	"scope" text NOT NULL,
	"status" text NOT NULL,
	"detail" text,
	"evidence_ref" text,
	"evidence_json" text,
	"checked_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "compliance_check_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text NOT NULL,
	"run_type" text DEFAULT 'on_demand' NOT NULL,
	"triggered_by" varchar,
	"total_checks" integer DEFAULT 0 NOT NULL,
	"pass_count" integer DEFAULT 0 NOT NULL,
	"fail_count" integer DEFAULT 0 NOT NULL,
	"not_assessed_count" integer DEFAULT 0 NOT NULL,
	"source_digest" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "ccr_tenant_id_uniq" UNIQUE("tenant_id","id")
);
--> statement-breakpoint
CREATE TABLE "compliance_reports" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"report_type" text NOT NULL,
	"title" text NOT NULL,
	"status" text DEFAULT 'generating' NOT NULL,
	"framework" text NOT NULL,
	"period" text NOT NULL,
	"findings" text,
	"evidence_count" integer DEFAULT 0 NOT NULL,
	"controls_passed" integer DEFAULT 0 NOT NULL,
	"controls_failed" integer DEFAULT 0 NOT NULL,
	"controls_total" integer DEFAULT 0 NOT NULL,
	"risk_score" numeric(5, 2),
	"signed_hash" text,
	"run_id" varchar,
	"source_digest" text,
	"generated_by" varchar,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"completed_at" timestamp
);
--> statement-breakpoint
CREATE TABLE "conversations" (
	"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "conversations_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
	"title" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "dlp_findings" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"finding_type" text NOT NULL,
	"severity" text DEFAULT 'medium' NOT NULL,
	"source" text NOT NULL,
	"endpoint" text,
	"data_pattern" text NOT NULL,
	"match_count" integer DEFAULT 1 NOT NULL,
	"sample_context" text,
	"status" text DEFAULT 'open' NOT NULL,
	"remediation" text,
	"tenant_id" text,
	"detected_by" text DEFAULT 'automated' NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"resolved_at" timestamp
);
--> statement-breakpoint
CREATE TABLE "dlp_policies" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"description" text,
	"pattern_type" text NOT NULL,
	"regex" text NOT NULL,
	"severity" text DEFAULT 'high' NOT NULL,
	"action" text DEFAULT 'alert' NOT NULL,
	"is_active" boolean DEFAULT true NOT NULL,
	"scan_scope" text DEFAULT 'all' NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "export_jobs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"export_type" text NOT NULL,
	"format" text NOT NULL,
	"status" text DEFAULT 'pending' NOT NULL,
	"filters" text,
	"file_name" text,
	"file_size" integer,
	"download_url" text,
	"requested_by" varchar,
	"error_message" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"completed_at" timestamp,
	"tenant_id" text
);
--> statement-breakpoint
CREATE TABLE "geo_policies" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"policy_type" text NOT NULL,
	"allowed_regions" text[] NOT NULL,
	"blocked_regions" text[],
	"data_classification" text DEFAULT 'standard' NOT NULL,
	"enforcement_mode" text DEFAULT 'monitor' NOT NULL,
	"tenant_id" text,
	"is_active" boolean DEFAULT true NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "geo_violations" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"policy_id" varchar,
	"violation_type" text NOT NULL,
	"source_ip" text,
	"source_region" text NOT NULL,
	"target_region" text,
	"endpoint" text,
	"user_id" varchar,
	"action" text NOT NULL,
	"severity" text DEFAULT 'medium' NOT NULL,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "ghost_core_events" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"event_type" text NOT NULL,
	"status" text NOT NULL,
	"affected_systems" text,
	"transactions_processed" integer,
	"shadow_ledger_balance" text,
	"duration" integer,
	"details" text,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "health_checks" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"component_name" text NOT NULL,
	"status" text NOT NULL,
	"response_time_ms" integer,
	"details" text,
	"last_checked_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "i18n_overrides" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text NOT NULL,
	"locale" text NOT NULL,
	"key" text NOT NULL,
	"value" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "incident_slas" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"incident_id" text NOT NULL,
	"severity" text NOT NULL,
	"title" text NOT NULL,
	"description" text,
	"status" text DEFAULT 'open' NOT NULL,
	"assigned_to" varchar,
	"escalation_level" integer DEFAULT 0 NOT NULL,
	"sla_target_minutes" integer NOT NULL,
	"acknowledged_at" timestamp,
	"resolved_at" timestamp,
	"breached_at" timestamp,
	"is_sla_breached" boolean DEFAULT false NOT NULL,
	"root_cause" text,
	"resolution" text,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "ip_policies" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text,
	"policy_type" text NOT NULL,
	"ip_address" text NOT NULL,
	"cidr_range" text,
	"description" text,
	"is_active" boolean DEFAULT true NOT NULL,
	"hit_count" integer DEFAULT 0 NOT NULL,
	"last_hit_at" timestamp,
	"created_by" varchar,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"expires_at" timestamp
);
--> statement-breakpoint
CREATE TABLE "messages" (
	"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "messages_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
	"conversation_id" integer NOT NULL,
	"role" text NOT NULL,
	"content" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "notification_logs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"channel" text NOT NULL,
	"recipient" text NOT NULL,
	"subject" text,
	"body" text,
	"status" text DEFAULT 'pending' NOT NULL,
	"error_message" text,
	"retry_count" integer DEFAULT 0 NOT NULL,
	"sent_at" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"tenant_id" text
);
--> statement-breakpoint
CREATE TABLE "observer_logs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"agent_id" text NOT NULL,
	"agent_name" text NOT NULL,
	"event_type" text NOT NULL,
	"severity" text NOT NULL,
	"details" text,
	"action_taken" text,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "posture_scores" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"overall_score" numeric(5, 2) NOT NULL,
	"category_scores" text NOT NULL,
	"risk_level" text NOT NULL,
	"compliance_score" numeric(5, 2),
	"vulnerability_score" numeric(5, 2),
	"incident_score" numeric(5, 2),
	"access_control_score" numeric(5, 2),
	"data_protection_score" numeric(5, 2),
	"network_security_score" numeric(5, 2),
	"total_findings" integer DEFAULT 0 NOT NULL,
	"critical_findings" integer DEFAULT 0 NOT NULL,
	"recommendations" text,
	"assessed_by" text DEFAULT 'automated' NOT NULL,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "rate_limit_events" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"policy_id" varchar,
	"endpoint" text NOT NULL,
	"ip_address" text,
	"api_key_id" varchar,
	"action" text NOT NULL,
	"current_count" integer NOT NULL,
	"limit_value" integer NOT NULL,
	"window_type" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "rate_limit_policies" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"scope" text DEFAULT 'global' NOT NULL,
	"tenant_id" text,
	"api_key_id" varchar,
	"endpoint" text,
	"requests_per_minute" integer DEFAULT 60 NOT NULL,
	"requests_per_hour" integer DEFAULT 1000 NOT NULL,
	"requests_per_day" integer DEFAULT 10000 NOT NULL,
	"burst_limit" integer DEFAULT 100 NOT NULL,
	"throttle_action" text DEFAULT 'reject' NOT NULL,
	"is_active" boolean DEFAULT true NOT NULL,
	"created_by" varchar,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "report_executions" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"schedule_id" text NOT NULL,
	"schedule_name" text NOT NULL,
	"report_type" text NOT NULL,
	"status" text NOT NULL,
	"scope" text DEFAULT 'GLOBAL' NOT NULL,
	"duration_ms" integer DEFAULT 0 NOT NULL,
	"report_size" integer DEFAULT 0 NOT NULL,
	"recipient_count" integer DEFAULT 0 NOT NULL,
	"triggered_by" text,
	"error" text,
	"executed_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "sbom_components" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"version" text NOT NULL,
	"component_type" text NOT NULL,
	"license" text,
	"supplier" text,
	"hash" text,
	"is_direct_dep" boolean DEFAULT true NOT NULL,
	"last_scanned_at" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "sessions" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"user_id" varchar NOT NULL,
	"token" text NOT NULL,
	"expires_at" timestamp NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"last_activity" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "sessions_token_unique" UNIQUE("token")
);
--> statement-breakpoint
CREATE TABLE "slo_targets" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"service_name" text NOT NULL,
	"metric_type" text NOT NULL,
	"target_value" numeric(10, 4) NOT NULL,
	"window_days" integer DEFAULT 30 NOT NULL,
	"current_value" numeric(10, 4),
	"burn_rate" numeric(10, 4),
	"budget_remaining" numeric(10, 4),
	"status" text DEFAULT 'healthy' NOT NULL,
	"last_checked_at" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "soar_executions" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"playbook_id" text NOT NULL,
	"playbook_name" text NOT NULL,
	"trigger" text NOT NULL,
	"status" text NOT NULL,
	"actions_executed" integer,
	"actions_total" integer,
	"started_at" timestamp DEFAULT NOW() NOT NULL,
	"completed_at" timestamp,
	"executed_by" text,
	"result" text,
	"tenant_id" text
);
--> statement-breakpoint
CREATE TABLE "sso_configs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text NOT NULL,
	"provider" text NOT NULL,
	"entity_id" text,
	"metadata_url" text,
	"client_id" text,
	"client_secret" text,
	"issuer_url" text,
	"callback_url" text,
	"is_active" boolean DEFAULT true NOT NULL,
	"settings" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "system_metrics" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"timestamp" timestamp DEFAULT NOW() NOT NULL,
	"metric_name" text NOT NULL,
	"metric_value" numeric(20, 4) NOT NULL,
	"unit" text
);
--> statement-breakpoint
CREATE TABLE "tenants" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"slug" text NOT NULL,
	"industry" text NOT NULL,
	"tier" text NOT NULL,
	"is_active" boolean DEFAULT true NOT NULL,
	"settings" text,
	"data_region" text DEFAULT 'ug-east' NOT NULL,
	"max_users" integer DEFAULT 50 NOT NULL,
	"encryption_key_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "tenants_slug_unique" UNIQUE("slug")
);
--> statement-breakpoint
CREATE TABLE "threat_events" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"timestamp" timestamp DEFAULT NOW() NOT NULL,
	"maker_id" text NOT NULL,
	"checker_id" text,
	"amount" numeric(20, 2),
	"currency" text DEFAULT 'UGX' NOT NULL,
	"threat_type" "threat_type" NOT NULL,
	"risk_level" "risk_level" NOT NULL,
	"terminal_ip" text,
	"branch" text,
	"description" text,
	"is_neutralized" boolean DEFAULT false NOT NULL,
	"neutralized_by" varchar,
	"neutralized_at" timestamp,
	"anomaly_score" numeric(5, 4),
	"feature_contributions" text
);
--> statement-breakpoint
CREATE TABLE "users" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"username" text NOT NULL,
	"password" text NOT NULL,
	"role" "user_role" DEFAULT 'auditor' NOT NULL,
	"secondary_roles" text[] DEFAULT ARRAY[]::text[] NOT NULL,
	"full_name" text NOT NULL,
	"department" text,
	"is_active" boolean DEFAULT true NOT NULL,
	"last_login" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "users_username_unique" UNIQUE("username")
);
--> statement-breakpoint
CREATE TABLE "vulnerability_findings" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"component_id" varchar,
	"cve_id" text NOT NULL,
	"severity" text NOT NULL,
	"cvss_score" numeric(4, 1),
	"description" text,
	"affected_versions" text,
	"fixed_version" text,
	"status" text DEFAULT 'open' NOT NULL,
	"assigned_to" text,
	"sla_deadline" timestamp,
	"patched_at" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "webhook_configs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text,
	"name" text NOT NULL,
	"integration_type" "webhook_integration" NOT NULL,
	"endpoint_url" text NOT NULL,
	"auth_type" text DEFAULT 'bearer' NOT NULL,
	"auth_token" text,
	"events" text NOT NULL,
	"is_active" boolean DEFAULT true NOT NULL,
	"retry_count" integer DEFAULT 3 NOT NULL,
	"timeout_ms" integer DEFAULT 5000 NOT NULL,
	"created_by" varchar,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"last_triggered" timestamp
);
--> statement-breakpoint
CREATE TABLE "webhook_logs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text,
	"webhook_id" varchar,
	"event_type" "webhook_event" NOT NULL,
	"payload" text NOT NULL,
	"response_status" integer,
	"response_body" text,
	"execution_time_ms" integer,
	"success" boolean DEFAULT false NOT NULL,
	"error_message" text,
	"triggered_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "er_clusters" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"entities" text DEFAULT '[]' NOT NULL,
	"risk_score" numeric(4, 3) DEFAULT '0' NOT NULL,
	"risk_level" text DEFAULT 'LOW' NOT NULL,
	"indicators" text DEFAULT '[]' NOT NULL,
	"pattern" text NOT NULL,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "er_entities" (
	"id" varchar PRIMARY KEY NOT NULL,
	"type" text NOT NULL,
	"value" text NOT NULL,
	"attributes" text DEFAULT '{}' NOT NULL,
	"risk_score" numeric(4, 3) DEFAULT '0' NOT NULL,
	"linked_entities" text DEFAULT '[]' NOT NULL,
	"cluster_id" text,
	"first_seen" timestamp DEFAULT NOW() NOT NULL,
	"last_seen" timestamp DEFAULT NOW() NOT NULL,
	"tenant_id" text
);
--> statement-breakpoint
CREATE TABLE "er_entity_links" (
	"id" varchar PRIMARY KEY NOT NULL,
	"source_id" varchar NOT NULL,
	"target_id" varchar NOT NULL,
	"link_type" text NOT NULL,
	"strength" numeric(4, 3) NOT NULL,
	"evidence" text DEFAULT '[]' NOT NULL,
	"last_confirmed" timestamp DEFAULT NOW() NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "explanation_dossiers" (
	"id" varchar PRIMARY KEY NOT NULL,
	"type" text NOT NULL,
	"subject_id" text NOT NULL,
	"subject_name" text NOT NULL,
	"decision_date" timestamp NOT NULL,
	"decision" text NOT NULL,
	"decision_confidence" numeric(4, 3) NOT NULL,
	"summary" text NOT NULL,
	"detailed_reasoning" text NOT NULL,
	"factors_considered" text NOT NULL,
	"appeal_process" text NOT NULL,
	"appeal_deadline" timestamp NOT NULL,
	"contact_information" text NOT NULL,
	"pdpo_compliant" boolean DEFAULT true NOT NULL,
	"data_retention_days" integer DEFAULT 365 NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "fincrime_case_events" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text NOT NULL,
	"case_id" varchar NOT NULL,
	"event_type" text NOT NULL,
	"from_state" text,
	"to_state" text,
	"actor_user_id" varchar,
	"actor_role" text,
	"event_payload" text NOT NULL,
	"payload_hash" text NOT NULL,
	"audit_chain_entry_id" integer,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "fincrime_case_evidence" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text NOT NULL,
	"case_id" varchar NOT NULL,
	"evidence_type" text NOT NULL,
	"opaque_ref" text,
	"encrypted_note" text,
	"added_by_user_id" varchar NOT NULL,
	"added_by_role" text NOT NULL,
	"payload_hash" text NOT NULL,
	"audit_chain_entry_id" integer,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "fcev_type_valid" CHECK ("fincrime_case_evidence"."evidence_type" IN ('INVESTIGATION_NOTE','DOCUMENT_REF','TRANSACTION_REF','KYT_REF','SANCTIONS_REF','ADVERSE_MEDIA_REF')),
	CONSTRAINT "fcev_has_content" CHECK ("fincrime_case_evidence"."opaque_ref" IS NOT NULL OR "fincrime_case_evidence"."encrypted_note" IS NOT NULL)
);
--> statement-breakpoint
CREATE TABLE "fincrime_cases" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text NOT NULL,
	"source_type" text NOT NULL,
	"source_ref" text,
	"source_signal_hash" text NOT NULL,
	"subject_ref" text NOT NULL,
	"subject_ref_kind" text DEFAULT 'OPAQUE_EXTERNAL_REF' NOT NULL,
	"state" text DEFAULT 'OPEN' NOT NULL,
	"assigned_investigator_id" varchar,
	"disposition" text,
	"disposition_reason" text,
	"str_filed" boolean DEFAULT false NOT NULL,
	"audit_chain_entry_id" integer,
	"opened_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL,
	"dispositioned_at" timestamp,
	CONSTRAINT "fcc_tenant_id_uniq" UNIQUE("tenant_id","id"),
	CONSTRAINT "fcc_signal_hash_uniq" UNIQUE("tenant_id","source_signal_hash"),
	CONSTRAINT "fcc_state_valid" CHECK ("fincrime_cases"."state" IN ('OPEN','UNDER_INVESTIGATION','PENDING_MLCO_REVIEW','DISPOSITIONED')),
	CONSTRAINT "fcc_disposition_valid" CHECK ("fincrime_cases"."disposition" IS NULL OR "fincrime_cases"."disposition" IN ('CLEARED','ESCALATED_TO_EDD','STR_RECOMMENDED')),
	CONSTRAINT "fcc_no_silent_close" CHECK (("fincrime_cases"."state" = 'DISPOSITIONED' AND "fincrime_cases"."disposition" IS NOT NULL AND "fincrime_cases"."disposition_reason" IS NOT NULL AND "fincrime_cases"."dispositioned_at" IS NOT NULL) OR ("fincrime_cases"."state" <> 'DISPOSITIONED' AND "fincrime_cases"."disposition" IS NULL AND "fincrime_cases"."disposition_reason" IS NULL AND "fincrime_cases"."dispositioned_at" IS NULL))
);
--> statement-breakpoint
CREATE TABLE "fincrime_ingest_keys" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"key_hash" text NOT NULL,
	"label" text NOT NULL,
	"scopes_json" text NOT NULL,
	"tenant_id" text NOT NULL,
	"issued_by" text NOT NULL,
	"issued_at" timestamp DEFAULT NOW() NOT NULL,
	"expires_at" timestamp NOT NULL,
	"revoked_at" timestamp,
	"last_used_at" timestamp,
	"use_count" integer DEFAULT 0 NOT NULL,
	CONSTRAINT "fincrime_ingest_keys_key_hash_unique" UNIQUE("key_hash")
);
--> statement-breakpoint
CREATE TABLE "fincrime_str_approvals" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text NOT NULL,
	"str_report_id" varchar NOT NULL,
	"case_id" varchar NOT NULL,
	"approver_user_id" varchar NOT NULL,
	"approver_role" text NOT NULL,
	"approval_type" text DEFAULT 'MLCO_AUTHORITY' NOT NULL,
	"report_hash" text NOT NULL,
	"reason" text,
	"audit_chain_entry_id" integer,
	"approved_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "fsa_approver_role_valid" CHECK ("fincrime_str_approvals"."approver_role" IN ('risk_manager','admin'))
);
--> statement-breakpoint
CREATE TABLE "fincrime_str_reports" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text NOT NULL,
	"case_id" varchar NOT NULL,
	"status" text DEFAULT 'PREPARED' NOT NULL,
	"subject_ref" text NOT NULL,
	"subject_ref_kind" text DEFAULT 'OPAQUE_EXTERNAL_REF' NOT NULL,
	"encrypted_narrative" text,
	"narrative_hash" text,
	"fia_reference" text,
	"filed_at" timestamp,
	"acknowledged_at" timestamp,
	"prepared_by_user_id" varchar NOT NULL,
	"prepared_by_role" text NOT NULL,
	"retention_years" integer DEFAULT 10 NOT NULL,
	"retention_until" timestamp NOT NULL,
	"audit_chain_entry_id" integer,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "fsr_tenant_id_uniq" UNIQUE("tenant_id","id"),
	CONSTRAINT "fsr_status_valid" CHECK ("fincrime_str_reports"."status" IN ('PREPARED','FILED','ACKNOWLEDGED','NOT_FILED')),
	CONSTRAINT "fsr_no_fabricated_ack" CHECK (("fincrime_str_reports"."status" IN ('PREPARED','NOT_FILED') AND "fincrime_str_reports"."fia_reference" IS NULL AND "fincrime_str_reports"."filed_at" IS NULL AND "fincrime_str_reports"."acknowledged_at" IS NULL) OR ("fincrime_str_reports"."status" = 'FILED' AND "fincrime_str_reports"."fia_reference" IS NOT NULL AND "fincrime_str_reports"."filed_at" IS NOT NULL AND "fincrime_str_reports"."acknowledged_at" IS NULL) OR ("fincrime_str_reports"."status" = 'ACKNOWLEDGED' AND "fincrime_str_reports"."fia_reference" IS NOT NULL AND "fincrime_str_reports"."filed_at" IS NOT NULL AND "fincrime_str_reports"."acknowledged_at" IS NOT NULL)),
	CONSTRAINT "fsr_retention_min_years" CHECK ("fincrime_str_reports"."retention_years" >= 10),
	CONSTRAINT "fsr_retention_future" CHECK ("fincrime_str_reports"."retention_until" >= "fincrime_str_reports"."created_at")
);
--> statement-breakpoint
CREATE TABLE "jit_grants" (
	"id" varchar PRIMARY KEY NOT NULL,
	"user_id" text NOT NULL,
	"username" text NOT NULL,
	"original_role" text NOT NULL,
	"elevated_role" text NOT NULL,
	"reason" text NOT NULL,
	"approved_by" text,
	"status" text DEFAULT 'pending' NOT NULL,
	"policy_id" text,
	"resources" text DEFAULT '[]' NOT NULL,
	"actions" text DEFAULT '[]' NOT NULL,
	"max_actions" integer,
	"actions_used" integer DEFAULT 0 NOT NULL,
	"audit_log" text DEFAULT '[]' NOT NULL,
	"requested_at" timestamp DEFAULT NOW() NOT NULL,
	"granted_at" timestamp,
	"expires_at" timestamp NOT NULL,
	"revoked_at" timestamp,
	"revoked_by" text,
	"tenant_id" text
);
--> statement-breakpoint
CREATE TABLE "jit_policies" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"description" text NOT NULL,
	"target_role" text NOT NULL,
	"max_duration_minutes" integer DEFAULT 60 NOT NULL,
	"requires_approval" boolean DEFAULT true NOT NULL,
	"approver_roles" text DEFAULT '[]' NOT NULL,
	"allowed_resources" text DEFAULT '[]' NOT NULL,
	"allowed_actions" text DEFAULT '[]' NOT NULL,
	"max_actions_per_grant" integer,
	"cooldown_period_minutes" integer DEFAULT 60 NOT NULL,
	"enabled" boolean DEFAULT true NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "kyc_agent_decisions" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"customer_id" varchar NOT NULL,
	"agent_id" text NOT NULL,
	"agent_type" text NOT NULL,
	"decision" text NOT NULL,
	"confidence" numeric(4, 3) NOT NULL,
	"evidence" text NOT NULL,
	"signature_hash" text NOT NULL,
	"decided_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "kyc_customers" (
	"id" varchar PRIMARY KEY NOT NULL,
	"national_id" text NOT NULL,
	"national_id_hmac" text,
	"full_name" text NOT NULL,
	"date_of_birth" text NOT NULL,
	"phone_number" text NOT NULL,
	"email" text,
	"address" text,
	"photo_url" text,
	"status" text DEFAULT 'PENDING' NOT NULL,
	"risk_tier" text DEFAULT 'LOW' NOT NULL,
	"tenant_id" text,
	"onboarded_at" timestamp,
	"last_verified_at" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "kyc_decision_approvals" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text NOT NULL,
	"decision_id" varchar NOT NULL,
	"customer_id" varchar NOT NULL,
	"approver_user_id" varchar NOT NULL,
	"approver_role" text NOT NULL,
	"approval_type" text DEFAULT 'SENIOR_AUTHORITY' NOT NULL,
	"signals_hash" text NOT NULL,
	"reason" text,
	"audit_chain_entry_id" integer,
	"approved_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "kda_approver_role_valid" CHECK ("kyc_decision_approvals"."approver_role" IN ('risk_manager','admin'))
);
--> statement-breakpoint
CREATE TABLE "kyc_decision_outcomes" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text NOT NULL,
	"customer_id" varchar NOT NULL,
	"disposition" text NOT NULL,
	"str_flag" boolean DEFAULT false NOT NULL,
	"str_reason" text,
	"state" text DEFAULT 'PROPOSED' NOT NULL,
	"requires_senior_approval" boolean DEFAULT false NOT NULL,
	"risk_tier" text,
	"signals_snapshot" text NOT NULL,
	"signals_hash" text NOT NULL,
	"explanation" text NOT NULL,
	"decided_by_user_id" varchar NOT NULL,
	"decided_by_role" text NOT NULL,
	"audit_chain_entry_id" integer,
	"decided_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "kdo_disposition_valid" CHECK ("kyc_decision_outcomes"."disposition" IN ('APPROVE','REJECT','ESCALATE_TO_EDD')),
	CONSTRAINT "kdo_state_valid" CHECK ("kyc_decision_outcomes"."state" IN ('PROPOSED','PENDING_SENIOR_APPROVAL','FINAL'))
);
--> statement-breakpoint
CREATE TABLE "kyc_life_events" (
	"id" varchar PRIMARY KEY NOT NULL,
	"customer_id" varchar NOT NULL,
	"event_type" text NOT NULL,
	"details" text NOT NULL,
	"trigger_re_verification" boolean DEFAULT false NOT NULL,
	"detected_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "kyt_results" (
	"id" varchar PRIMARY KEY NOT NULL,
	"user_id" text NOT NULL,
	"amount" numeric(20, 2) NOT NULL,
	"currency" text DEFAULT 'UGX' NOT NULL,
	"recipient_id" text,
	"recipient_type" text NOT NULL,
	"channel" text NOT NULL,
	"risk_level" text NOT NULL,
	"risk_score" numeric(4, 3) NOT NULL,
	"risk_factors" text DEFAULT '[]' NOT NULL,
	"recommendation" text NOT NULL,
	"required_verification" text DEFAULT '[]' NOT NULL,
	"processing_time_ms" integer,
	"tenant_id" text,
	"scored_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "pam_accounts" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"type" text NOT NULL,
	"privilege_level" text NOT NULL,
	"description" text,
	"owner" text NOT NULL,
	"rotation_policy_days" integer DEFAULT 90 NOT NULL,
	"last_rotated" timestamp,
	"next_rotation" timestamp,
	"requires_approval" boolean DEFAULT true NOT NULL,
	"approvers" text DEFAULT '[]' NOT NULL,
	"max_session_duration_min" integer DEFAULT 60 NOT NULL,
	"allowed_time_windows" text,
	"mfa_required" boolean DEFAULT true NOT NULL,
	"justification_required" boolean DEFAULT true NOT NULL,
	"checkout_count" integer DEFAULT 0 NOT NULL,
	"last_accessed" timestamp,
	"status" text DEFAULT 'active' NOT NULL,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "pam_requests" (
	"id" varchar PRIMARY KEY NOT NULL,
	"account_id" varchar NOT NULL,
	"account_name" text NOT NULL,
	"requester_id" text NOT NULL,
	"requester_name" text NOT NULL,
	"justification" text NOT NULL,
	"requested_duration_min" integer NOT NULL,
	"status" text DEFAULT 'pending' NOT NULL,
	"risk_score" numeric(4, 3),
	"reviewed_by" text,
	"reviewed_at" timestamp,
	"review_notes" text,
	"expires_at" timestamp,
	"session_id" varchar,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "pam_sessions" (
	"id" varchar PRIMARY KEY NOT NULL,
	"access_request_id" varchar NOT NULL,
	"account_id" varchar NOT NULL,
	"account_name" text NOT NULL,
	"user_id" text NOT NULL,
	"user_name" text NOT NULL,
	"start_time" timestamp DEFAULT NOW() NOT NULL,
	"end_time" timestamp,
	"duration_minutes" integer,
	"status" text DEFAULT 'active' NOT NULL,
	"commands" text DEFAULT '[]' NOT NULL,
	"risk_events" text DEFAULT '[]' NOT NULL,
	"recording_url" text,
	"tenant_id" text
);
--> statement-breakpoint
CREATE TABLE "peer_comparisons" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"employee_id" varchar NOT NULL,
	"employee_name" text NOT NULL,
	"peer_group_name" text NOT NULL,
	"deviations_json" text DEFAULT '[]' NOT NULL,
	"overall_deviation_score" numeric(5, 4) NOT NULL,
	"risk_level" text NOT NULL,
	"recommendations_json" text DEFAULT '[]' NOT NULL,
	"tenant_id" text,
	"compared_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "peer_employees" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"department" text NOT NULL,
	"role" text NOT NULL,
	"branch" text NOT NULL,
	"hire_date" timestamp NOT NULL,
	"peer_group_id" varchar,
	"behavior_profile" text DEFAULT '{}' NOT NULL,
	"risk_score" numeric(4, 3) DEFAULT '0' NOT NULL,
	"last_activity" timestamp,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "peer_groups" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"description" text NOT NULL,
	"criteria_json" text DEFAULT '{}' NOT NULL,
	"member_count" integer DEFAULT 0 NOT NULL,
	"baseline_json" text DEFAULT '{}' NOT NULL,
	"tenant_id" text,
	"last_updated" timestamp DEFAULT NOW() NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "regulator_sessions" (
	"id" varchar PRIMARY KEY NOT NULL,
	"regulator_id" text NOT NULL,
	"regulator_name" text NOT NULL,
	"organization" text NOT NULL,
	"access_level" text NOT NULL,
	"ip_address" text NOT NULL,
	"started_at" timestamp DEFAULT NOW() NOT NULL,
	"expires_at" timestamp NOT NULL,
	"last_activity" timestamp DEFAULT NOW() NOT NULL,
	"actions_performed" text DEFAULT '[]' NOT NULL,
	"sandbox_environment_id" text,
	"is_active" boolean DEFAULT true NOT NULL
);
--> statement-breakpoint
CREATE TABLE "sandbox_environments" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"created_for" text NOT NULL,
	"is_active" boolean DEFAULT true NOT NULL,
	"baseline_snapshot" text NOT NULL,
	"modified_entities" text DEFAULT '[]' NOT NULL,
	"allowed_actions" text DEFAULT '[]' NOT NULL,
	"data_isolation" boolean DEFAULT true NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"expires_at" timestamp NOT NULL
);
--> statement-breakpoint
CREATE TABLE "soar_action_results" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"execution_id" varchar NOT NULL,
	"action_id" text NOT NULL,
	"action_name" text NOT NULL,
	"status" text NOT NULL,
	"start_time" timestamp,
	"end_time" timestamp,
	"output" text,
	"error" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "soar_playbooks" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"description" text NOT NULL,
	"trigger" text NOT NULL,
	"enabled" boolean DEFAULT true NOT NULL,
	"priority" integer DEFAULT 5 NOT NULL,
	"conditions" text,
	"actions" text NOT NULL,
	"execution_count" integer DEFAULT 0 NOT NULL,
	"last_executed" timestamp,
	"average_execution_time_ms" integer DEFAULT 0 NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL,
	"tenant_id" text
);
--> statement-breakpoint
CREATE TABLE "suspicious_activity_reports" (
	"id" varchar PRIMARY KEY NOT NULL,
	"reference_number" text NOT NULL,
	"status" text DEFAULT 'DRAFT' NOT NULL,
	"priority" text DEFAULT 'ROUTINE' NOT NULL,
	"subject_type" text NOT NULL,
	"subject_name" text NOT NULL,
	"subject_id" text NOT NULL,
	"activity_type" text NOT NULL,
	"activity_date" timestamp NOT NULL,
	"amount" numeric(20, 2),
	"currency" text DEFAULT 'UGX' NOT NULL,
	"description" text NOT NULL,
	"proof_chain_hash" text NOT NULL,
	"kyc_decisions" text DEFAULT '[]' NOT NULL,
	"transaction_ids" text DEFAULT '[]' NOT NULL,
	"prepared_by" text NOT NULL,
	"reviewed_by" text,
	"filing_notes" text,
	"fia_reference" text,
	"submitted_at" timestamp,
	"acknowledged_at" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "suspicious_activity_reports_reference_number_unique" UNIQUE("reference_number")
);
--> statement-breakpoint
CREATE TABLE "threat_feed_sync_log" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text,
	"feed_id" text NOT NULL,
	"feed_name" text NOT NULL,
	"status" text NOT NULL,
	"indicators_added" integer DEFAULT 0 NOT NULL,
	"indicators_updated" integer DEFAULT 0 NOT NULL,
	"error_message" text,
	"duration_ms" integer,
	"synced_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "threat_feeds" (
	"id" varchar PRIMARY KEY NOT NULL,
	"tenant_id" text,
	"name" text NOT NULL,
	"type" text NOT NULL,
	"url" text NOT NULL,
	"encrypted_api_key" text,
	"enabled" boolean DEFAULT true NOT NULL,
	"refresh_interval_min" integer DEFAULT 60 NOT NULL,
	"last_sync" timestamp,
	"indicator_count" integer DEFAULT 0 NOT NULL,
	"status" text DEFAULT 'active' NOT NULL,
	"error_message" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "threat_indicators" (
	"id" varchar PRIMARY KEY NOT NULL,
	"tenant_id" text,
	"feed_id" varchar,
	"type" text NOT NULL,
	"value" text NOT NULL,
	"severity" text DEFAULT 'medium' NOT NULL,
	"source" text NOT NULL,
	"confidence" integer DEFAULT 50 NOT NULL,
	"tags" text DEFAULT '[]' NOT NULL,
	"description" text,
	"metadata" text,
	"first_seen" timestamp DEFAULT NOW() NOT NULL,
	"last_seen" timestamp DEFAULT NOW() NOT NULL,
	"expires_at" timestamp,
	"match_count" integer DEFAULT 0 NOT NULL,
	"is_active" boolean DEFAULT true NOT NULL
);
--> statement-breakpoint
CREATE TABLE "threat_matches" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"indicator_id" varchar NOT NULL,
	"matched_value" text NOT NULL,
	"matched_context" text NOT NULL,
	"risk_score" numeric(4, 3) NOT NULL,
	"tenant_id" text,
	"matched_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "dsar_audit_trail" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"dsar_id" varchar NOT NULL,
	"action" text NOT NULL,
	"performed_by" text,
	"notes" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "dsar_purge_jobs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"job_ref" varchar(64) NOT NULL,
	"dsar_id" varchar NOT NULL,
	"customer_ref" varchar(128) NOT NULL,
	"status" varchar(32) DEFAULT 'pending' NOT NULL,
	"enqueued_by" varchar(128) NOT NULL,
	"enqueued_at" timestamp with time zone DEFAULT NOW() NOT NULL,
	"started_at" timestamp with time zone,
	"completed_at" timestamp with time zone,
	"attempt" integer DEFAULT 0 NOT NULL,
	"drill_ref" varchar(64),
	"prior_drill_ref" varchar(64),
	"real_rows_erased" integer,
	"legally_retained_rows" integer,
	"prior_erasure_found" integer,
	"receipt_hash" varchar(128),
	"signature_hex" varchar(256),
	"error_message" text,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"tenant_id" varchar,
	CONSTRAINT "dsar_purge_jobs_job_ref_key" UNIQUE("job_ref")
);
--> statement-breakpoint
CREATE TABLE "dsar_requests" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"reference" text NOT NULL,
	"tenant_id" text,
	"subject_name" text NOT NULL,
	"subject_email" text NOT NULL,
	"subject_phone" text,
	"subject_national_id" text,
	"request_type" text NOT NULL,
	"request_channel" text DEFAULT 'portal' NOT NULL,
	"description" text,
	"received_at" timestamp DEFAULT NOW() NOT NULL,
	"sla_deadline" timestamp NOT NULL,
	"status" text DEFAULT 'received' NOT NULL,
	"assigned_to" text,
	"data_extract_url" text,
	"response_notes" text,
	"regulatory_submitted_at" timestamp,
	"regulatory_ref" text,
	"completed_at" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "dsar_requests_reference_unique" UNIQUE("reference")
);
--> statement-breakpoint
CREATE TABLE "pagerduty_configs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text,
	"encrypted_api_key" text NOT NULL,
	"default_service_id" text NOT NULL,
	"default_escalation_policy_id" text,
	"severity_map" text DEFAULT '{"P1":"critical","P2":"error","P3":"warning","P4":"info"}' NOT NULL,
	"auto_resolve_on_close" boolean DEFAULT true NOT NULL,
	"is_active" boolean DEFAULT true NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "pagerduty_incidents" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"config_id" varchar NOT NULL,
	"aegis_incident_id" text,
	"aegis_alert_id" text,
	"pd_incident_id" text,
	"pd_incident_number" integer,
	"dedupe_key" text NOT NULL,
	"title" text NOT NULL,
	"severity" text NOT NULL,
	"status" text DEFAULT 'triggered' NOT NULL,
	"triggered_at" timestamp DEFAULT NOW() NOT NULL,
	"acknowledged_at" timestamp,
	"resolved_at" timestamp,
	CONSTRAINT "pagerduty_incidents_dedupe_key_unique" UNIQUE("dedupe_key")
);
--> statement-breakpoint
CREATE TABLE "scim_configs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text NOT NULL,
	"provider_name" text NOT NULL,
	"encrypted_bearer_token" text NOT NULL,
	"is_active" boolean DEFAULT true NOT NULL,
	"last_sync_at" timestamp,
	"total_users_provisioned" integer DEFAULT 0 NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "scim_configs_tenant_id_unique" UNIQUE("tenant_id")
);
--> statement-breakpoint
CREATE TABLE "scim_provisions" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text NOT NULL,
	"external_id" text NOT NULL,
	"user_name" text NOT NULL,
	"display_name" text,
	"email" text,
	"groups" text DEFAULT '[]' NOT NULL,
	"active" boolean DEFAULT true NOT NULL,
	"local_user_id" varchar,
	"sync_status" text DEFAULT 'synced' NOT NULL,
	"last_sync_at" timestamp DEFAULT NOW() NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "servicenow_configs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text,
	"instance_url" text NOT NULL,
	"username" text NOT NULL,
	"encrypted_password" text NOT NULL,
	"default_assignment_group" text,
	"incident_table" text DEFAULT 'incident' NOT NULL,
	"change_table" text DEFAULT 'change_request' NOT NULL,
	"auto_create_on_p1" boolean DEFAULT true NOT NULL,
	"auto_create_on_p2" boolean DEFAULT true NOT NULL,
	"is_active" boolean DEFAULT true NOT NULL,
	"last_test_at" timestamp,
	"last_test_status" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "servicenow_sync_log" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"config_id" varchar NOT NULL,
	"direction" text NOT NULL,
	"record_type" text NOT NULL,
	"aegis_record_id" text NOT NULL,
	"snow_number" text,
	"snow_sys_id" text,
	"status" text NOT NULL,
	"error_message" text,
	"duration_ms" integer,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "account_lockouts" (
	"key" varchar PRIMARY KEY NOT NULL,
	"failed_attempts" integer DEFAULT 0 NOT NULL,
	"first_failure_at" timestamp DEFAULT NOW() NOT NULL,
	"last_failure_at" timestamp DEFAULT NOW() NOT NULL,
	"locked_until" timestamp,
	"lockout_count" integer DEFAULT 0 NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "adaptive_threshold_configs" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"current_value" numeric(12, 4) NOT NULL,
	"min_value" numeric(12, 4) NOT NULL,
	"max_value" numeric(12, 4) NOT NULL,
	"default_value" numeric(12, 4) NOT NULL,
	"auto_tune_enabled" boolean DEFAULT true NOT NULL,
	"auto_tune_settings_json" text DEFAULT '{}' NOT NULL,
	"metrics_json" text DEFAULT '{}' NOT NULL,
	"history_json" text DEFAULT '[]' NOT NULL,
	"tenant_id" text,
	"last_updated" timestamp DEFAULT NOW() NOT NULL,
	"updated_by" text DEFAULT 'SYSTEM' NOT NULL
);
--> statement-breakpoint
CREATE TABLE "agent_collision_events" (
	"id" varchar PRIMARY KEY NOT NULL,
	"agents" text DEFAULT '[]' NOT NULL,
	"collision_type" text NOT NULL,
	"severity" text NOT NULL,
	"description" text NOT NULL,
	"resolution" text NOT NULL,
	"context_json" text DEFAULT '{}' NOT NULL,
	"resolved_at" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "agent_operational_pauses" (
	"id" varchar PRIMARY KEY NOT NULL,
	"requested_by" text NOT NULL,
	"reason" text NOT NULL,
	"affected_agents" text DEFAULT '[]' NOT NULL,
	"severity" text NOT NULL,
	"status" text DEFAULT 'ACTIVE' NOT NULL,
	"auto_resume_at" timestamp,
	"resolved_at" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "agent_registry" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"type" text NOT NULL,
	"encrypted_api_key" text NOT NULL,
	"permissions" text DEFAULT '[]' NOT NULL,
	"status" text DEFAULT 'ACTIVE' NOT NULL,
	"requests_today" integer DEFAULT 0 NOT NULL,
	"total_requests" integer DEFAULT 0 NOT NULL,
	"last_activity_at" timestamp,
	"suspended_at" timestamp,
	"suspend_reason" text,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "api_changelog" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"version" text NOT NULL,
	"change_type" text NOT NULL,
	"endpoint" text,
	"method" text,
	"title" text NOT NULL,
	"description" text NOT NULL,
	"migration_guide" text,
	"affected_clients" text DEFAULT '[]' NOT NULL,
	"deprecated_at" timestamp,
	"removed_at" timestamp,
	"published_at" timestamp DEFAULT NOW() NOT NULL,
	"author_id" text
);
--> statement-breakpoint
CREATE TABLE "billing_invoices" (
	"id" varchar PRIMARY KEY NOT NULL,
	"tenant_id" varchar NOT NULL,
	"period" text NOT NULL,
	"status" text DEFAULT 'DRAFT' NOT NULL,
	"line_items_json" text DEFAULT '[]' NOT NULL,
	"subtotal_usd" numeric(12, 2) NOT NULL,
	"tax_usd" numeric(12, 2) DEFAULT '0' NOT NULL,
	"total_usd" numeric(12, 2) NOT NULL,
	"due_at" timestamp,
	"paid_at" timestamp,
	"generated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "billing_tenants" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"tier" text NOT NULL,
	"industry" text NOT NULL,
	"contract_start" timestamp NOT NULL,
	"contract_end" timestamp NOT NULL,
	"monthly_commitment_usd" numeric(12, 2) NOT NULL,
	"departments_json" text DEFAULT '[]' NOT NULL,
	"is_active" boolean DEFAULT true NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "billing_usage_records" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" varchar NOT NULL,
	"department_id" text,
	"category" text NOT NULL,
	"units" integer NOT NULL,
	"cost_usd" numeric(12, 4) NOT NULL,
	"metadata" text,
	"recorded_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "ghost_shadow_balances" (
	"account_id" varchar PRIMARY KEY NOT NULL,
	"available_balance" numeric(20, 4) NOT NULL,
	"hold_balance" numeric(20, 4) DEFAULT '0' NOT NULL,
	"currency" text DEFAULT 'UGX' NOT NULL,
	"last_sync_time" timestamp DEFAULT NOW() NOT NULL,
	"sync_sequence" integer DEFAULT 0 NOT NULL,
	"tenant_id" text,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "ghost_shadow_transactions" (
	"id" varchar PRIMARY KEY NOT NULL,
	"account_from" text NOT NULL,
	"account_to" text NOT NULL,
	"amount" numeric(20, 4) NOT NULL,
	"currency" text DEFAULT 'UGX' NOT NULL,
	"type" text NOT NULL,
	"status" text DEFAULT 'PENDING' NOT NULL,
	"merkle_root" text NOT NULL,
	"sequence_number" integer NOT NULL,
	"tenant_id" text,
	"timestamp" timestamp DEFAULT NOW() NOT NULL,
	"reconciled_at" timestamp
);
--> statement-breakpoint
CREATE TABLE "hsm_keys" (
	"id" varchar PRIMARY KEY NOT NULL,
	"purpose" text NOT NULL,
	"algorithm" text NOT NULL,
	"key_size" integer NOT NULL,
	"public_key" text,
	"status" text DEFAULT 'ACTIVE' NOT NULL,
	"version" integer DEFAULT 1 NOT NULL,
	"attestation_hash" text,
	"expires_at" timestamp,
	"rotated_from" varchar,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "hsm_operations" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"key_id" varchar NOT NULL,
	"operation" text NOT NULL,
	"requester_id" text,
	"data_hash" text,
	"success" boolean NOT NULL,
	"duration_ms" integer,
	"error_message" text,
	"performed_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "login_profiles" (
	"user_id" integer PRIMARY KEY NOT NULL,
	"known_ips" text DEFAULT '[]' NOT NULL,
	"known_devices" text DEFAULT '[]' NOT NULL,
	"typical_login_hours" text DEFAULT '[]' NOT NULL,
	"typical_countries" text DEFAULT '[]' NOT NULL,
	"average_session_duration_ms" integer,
	"last_known_ip" text,
	"last_known_country" text,
	"anomaly_count" integer DEFAULT 0 NOT NULL,
	"last_anomaly_at" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "mesh_nodes" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"region" text NOT NULL,
	"type" text NOT NULL,
	"status" text DEFAULT 'ONLINE' NOT NULL,
	"ip_address" text,
	"latency_ms" integer,
	"trust_score" numeric(4, 3) DEFAULT '1' NOT NULL,
	"last_sync_at" timestamp,
	"connections_json" text DEFAULT '[]' NOT NULL,
	"capabilities_json" text DEFAULT '[]' NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "model_drift_history" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"model_id" text NOT NULL,
	"model_version" text NOT NULL,
	"psi_score" numeric(6, 4) NOT NULL,
	"ks_score" numeric(6, 4) NOT NULL,
	"accuracy" numeric(5, 4),
	"false_positive_rate" numeric(5, 4),
	"false_negative_rate" numeric(5, 4),
	"feature_drifts_json" text DEFAULT '[]' NOT NULL,
	"status" text NOT NULL,
	"retraining_triggered" boolean DEFAULT false NOT NULL,
	"tenant_id" text,
	"recorded_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "pen_test_findings" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"pen_test_id" varchar NOT NULL,
	"title" text NOT NULL,
	"severity" text NOT NULL,
	"cvss_score" numeric(4, 1),
	"cwe_id" text,
	"affected_asset" text,
	"description" text NOT NULL,
	"proof" text,
	"remediation" text,
	"status" text DEFAULT 'open' NOT NULL,
	"fixed_at" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "pen_tests" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"test_type" text NOT NULL,
	"scope" text NOT NULL,
	"methodology" text DEFAULT 'OWASP' NOT NULL,
	"status" text DEFAULT 'scheduled' NOT NULL,
	"vendor" text,
	"lead_tester" text,
	"scheduled_start" timestamp,
	"scheduled_end" timestamp,
	"actual_start" timestamp,
	"actual_end" timestamp,
	"critical_findings" integer DEFAULT 0 NOT NULL,
	"high_findings" integer DEFAULT 0 NOT NULL,
	"medium_findings" integer DEFAULT 0 NOT NULL,
	"low_findings" integer DEFAULT 0 NOT NULL,
	"report_url" text,
	"executive_summary" text,
	"remediation_deadline" timestamp,
	"remediated_at" timestamp,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "retention_executions" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"policy_id" varchar NOT NULL,
	"status" text NOT NULL,
	"records_scanned" integer DEFAULT 0 NOT NULL,
	"records_archived" integer DEFAULT 0 NOT NULL,
	"records_deleted" integer DEFAULT 0 NOT NULL,
	"errors" text DEFAULT '[]' NOT NULL,
	"duration_ms" integer,
	"executed_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "retention_policies" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"description" text,
	"data_category" text NOT NULL,
	"retention_days" integer NOT NULL,
	"archive_after_days" integer,
	"delete_after_days" integer,
	"legal_basis" text,
	"regulation" text,
	"is_active" boolean DEFAULT true NOT NULL,
	"exceptions_json" text DEFAULT '[]' NOT NULL,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "revenue_snapshots" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"period" text NOT NULL,
	"mrr" numeric(14, 2) NOT NULL,
	"arr" numeric(14, 2) NOT NULL,
	"new_mrr" numeric(14, 2) DEFAULT '0' NOT NULL,
	"expansion_mrr" numeric(14, 2) DEFAULT '0' NOT NULL,
	"contraction_mrr" numeric(14, 2) DEFAULT '0' NOT NULL,
	"churn_mrr" numeric(14, 2) DEFAULT '0' NOT NULL,
	"net_new_mrr" numeric(14, 2) DEFAULT '0' NOT NULL,
	"active_customers" integer DEFAULT 0 NOT NULL,
	"churned_customers" integer DEFAULT 0 NOT NULL,
	"new_customers" integer DEFAULT 0 NOT NULL,
	"avg_revenue_per_customer" numeric(12, 2),
	"growth_rate_pct" numeric(6, 2),
	"snapshot_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "sbom_diffs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"from_snapshot_id" varchar NOT NULL,
	"to_snapshot_id" varchar NOT NULL,
	"added" text DEFAULT '[]' NOT NULL,
	"removed" text DEFAULT '[]' NOT NULL,
	"updated" text DEFAULT '[]' NOT NULL,
	"new_vulns" text DEFAULT '[]' NOT NULL,
	"resolved_vulns" text DEFAULT '[]' NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "sbom_snapshots" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"snapshot_name" text NOT NULL,
	"component_count" integer DEFAULT 0 NOT NULL,
	"critical_vulns" integer DEFAULT 0 NOT NULL,
	"high_vulns" integer DEFAULT 0 NOT NULL,
	"outdated_components" integer DEFAULT 0 NOT NULL,
	"license_issues" integer DEFAULT 0 NOT NULL,
	"trigger" text DEFAULT 'manual' NOT NULL,
	"commit_hash" text,
	"branch_name" text,
	"components_json" text DEFAULT '[]' NOT NULL,
	"tenant_id" text,
	"snapshot_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "series_b_metrics" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"category" text NOT NULL,
	"metric_name" text NOT NULL,
	"current_value" numeric(14, 4),
	"target_value" numeric(14, 4),
	"unit" text DEFAULT '' NOT NULL,
	"status" text DEFAULT 'in_progress' NOT NULL,
	"notes" text,
	"evidence_links" text DEFAULT '[]' NOT NULL,
	"updated_by" text,
	"period" text,
	"updated_at" timestamp DEFAULT NOW() NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "totp_secrets" (
	"user_id" text PRIMARY KEY NOT NULL,
	"encrypted_secret" text NOT NULL,
	"enabled" boolean DEFAULT false NOT NULL,
	"backup_codes" text DEFAULT '[]' NOT NULL,
	"used_backup_codes" text DEFAULT '[]' NOT NULL,
	"last_used" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "abom_components" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"version" text NOT NULL,
	"type" text NOT NULL,
	"provider" text NOT NULL,
	"purpose" text NOT NULL,
	"risk_level" text DEFAULT 'LOW' NOT NULL,
	"license_type" text,
	"integrity_hash" text,
	"data_access" text DEFAULT '[]' NOT NULL,
	"capabilities" text DEFAULT '[]' NOT NULL,
	"vulnerabilities" text DEFAULT '[]' NOT NULL,
	"status" text DEFAULT 'ACTIVE' NOT NULL,
	"is_approved" boolean DEFAULT false NOT NULL,
	"approved_by" text,
	"approved_at" timestamp,
	"tenant_id" text,
	"registered_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "abom_data_sources" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"type" text NOT NULL,
	"classification" text NOT NULL,
	"retention_days" integer,
	"pii_categories" text DEFAULT '[]' NOT NULL,
	"access_controls" text DEFAULT '[]' NOT NULL,
	"is_encrypted" boolean DEFAULT false NOT NULL,
	"component_ids" text DEFAULT '[]' NOT NULL,
	"tenant_id" text,
	"registered_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "biometric_profiles" (
	"user_id" integer PRIMARY KEY NOT NULL,
	"tenant_id" text,
	"keystroke_baseline_json" text,
	"mouse_baseline_json" text,
	"sample_count" integer DEFAULT 0 NOT NULL,
	"confidence_score" numeric(4, 3) DEFAULT '0' NOT NULL,
	"last_updated" timestamp DEFAULT NOW() NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "cbs_kill_switch_log" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"action" text NOT NULL,
	"reason" text NOT NULL,
	"target_type" text,
	"target_id" text,
	"executed_by" text NOT NULL,
	"reversed_at" timestamp,
	"reversed_by" text,
	"tenant_id" text,
	"executed_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "cbs_transaction_logs" (
	"id" varchar PRIMARY KEY NOT NULL,
	"transaction_id" text NOT NULL,
	"type" text NOT NULL,
	"account_from" text,
	"account_to" text,
	"amount" numeric(20, 4),
	"currency" text DEFAULT 'UGX' NOT NULL,
	"status" text NOT NULL,
	"provider" text,
	"phase" text,
	"error_message" text,
	"request_payload" text,
	"response_payload" text,
	"duration_ms" integer,
	"initiated_by" text,
	"tenant_id" text,
	"logged_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "cbs_transaction_logs_transaction_id_unique" UNIQUE("transaction_id")
);
--> statement-breakpoint
CREATE TABLE "cloud_environments" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"provider" text NOT NULL,
	"region" text NOT NULL,
	"is_primary" boolean DEFAULT false NOT NULL,
	"is_sovereign" boolean DEFAULT false NOT NULL,
	"status" text DEFAULT 'ACTIVE' NOT NULL,
	"services_json" text DEFAULT '[]' NOT NULL,
	"cost_monthly_usd" numeric(12, 2),
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "cloud_migration_plans" (
	"id" varchar PRIMARY KEY NOT NULL,
	"trigger" text NOT NULL,
	"status" text DEFAULT 'PLANNING' NOT NULL,
	"source_environment_id" varchar NOT NULL,
	"target_environment_id" varchar NOT NULL,
	"estimated_duration_hours" integer,
	"components_json" text DEFAULT '[]' NOT NULL,
	"progress_pct" integer DEFAULT 0 NOT NULL,
	"initiated_by" text,
	"completed_at" timestamp,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "cloud_sovereignty_alarms" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"alarm_type" text NOT NULL,
	"severity" text NOT NULL,
	"description" text NOT NULL,
	"affected_environment" text,
	"status" text DEFAULT 'ACTIVE' NOT NULL,
	"acknowledged_by" text,
	"acknowledged_at" timestamp,
	"tenant_id" text,
	"triggered_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "compliance_audit_events" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"framework_id" text NOT NULL,
	"type" text NOT NULL,
	"description" text NOT NULL,
	"performed_by" text NOT NULL,
	"outcome" text,
	"attachments" text DEFAULT '[]' NOT NULL,
	"tenant_id" text,
	"timestamp" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "compliance_controls" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"framework_id" text NOT NULL,
	"category" text NOT NULL,
	"name" text NOT NULL,
	"description" text NOT NULL,
	"status" text DEFAULT 'not_applicable' NOT NULL,
	"priority" text DEFAULT 'medium' NOT NULL,
	"last_assessed" timestamp,
	"next_assessment" timestamp,
	"assignee" text,
	"evidence" text DEFAULT '[]' NOT NULL,
	"gaps" text DEFAULT '[]' NOT NULL,
	"remediation_plan" text,
	"notes" text,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "compliance_gaps" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"framework_id" text NOT NULL,
	"control_id" text NOT NULL,
	"description" text NOT NULL,
	"severity" text NOT NULL,
	"identified_date" timestamp DEFAULT NOW() NOT NULL,
	"target_remediation_date" timestamp NOT NULL,
	"status" text DEFAULT 'open' NOT NULL,
	"assignee" text,
	"remediation_steps" text DEFAULT '[]' NOT NULL,
	"business_impact" text,
	"tenant_id" text,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "fido2_challenges" (
	"id" varchar PRIMARY KEY NOT NULL,
	"challenge" text NOT NULL,
	"user_id" text,
	"type" text NOT NULL,
	"expires_at" timestamp NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "fido2_credentials" (
	"id" varchar PRIMARY KEY NOT NULL,
	"credential_id" text NOT NULL,
	"public_key" text NOT NULL,
	"counter" integer DEFAULT 0 NOT NULL,
	"user_id" text NOT NULL,
	"device_name" text NOT NULL,
	"transports" text DEFAULT '[]' NOT NULL,
	"aaguid" text,
	"attestation_format" text,
	"is_active" boolean DEFAULT true NOT NULL,
	"last_used" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "fido2_credentials_credential_id_unique" UNIQUE("credential_id")
);
--> statement-breakpoint
CREATE TABLE "pci_audit_logs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"event_type" text NOT NULL,
	"user_id" text NOT NULL,
	"user_name" text,
	"resource_type" text NOT NULL,
	"resource_id" text,
	"action" text NOT NULL,
	"success" boolean NOT NULL,
	"ip_address" text NOT NULL,
	"user_agent" text,
	"session_id" text,
	"masking_applied" boolean DEFAULT true NOT NULL,
	"data_elements" text,
	"justification" text,
	"approved_by" text,
	"risk_score" integer DEFAULT 0 NOT NULL,
	"geo_location" text,
	"device_fingerprint" text,
	"tenant_id" text,
	"logged_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "saas_billing_periods" (
	"id" varchar PRIMARY KEY NOT NULL,
	"tenant_id" text NOT NULL,
	"start_date" timestamp NOT NULL,
	"end_date" timestamp NOT NULL,
	"status" text DEFAULT 'OPEN' NOT NULL,
	"usage_json" text DEFAULT '{}' NOT NULL,
	"total_cost" numeric(12, 4) DEFAULT '0' NOT NULL,
	"invoice_url" text,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "saas_tenants" (
	"tenant_id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"industry" text NOT NULL,
	"tier" text DEFAULT 'FREE' NOT NULL,
	"isolation_level" text DEFAULT 'SHARED' NOT NULL,
	"namespace" text NOT NULL,
	"region" text DEFAULT 'UG' NOT NULL,
	"status" text DEFAULT 'ACTIVE' NOT NULL,
	"data_residency" text DEFAULT 'UGANDA_ONLY' NOT NULL,
	"api_key_hash" text NOT NULL,
	"usage_quota_json" text DEFAULT '{}' NOT NULL,
	"resource_quota_json" text DEFAULT '{}' NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "saas_usage_events" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text NOT NULL,
	"metric" text NOT NULL,
	"units" integer NOT NULL,
	"unit_price" numeric(10, 6) NOT NULL,
	"total_cost" numeric(12, 4) NOT NULL,
	"metadata" text,
	"recorded_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "safety_rail_keys" (
	"id" varchar PRIMARY KEY NOT NULL,
	"agent_type" text NOT NULL,
	"key_hash" text NOT NULL,
	"is_revoked" boolean DEFAULT false NOT NULL,
	"revoked_at" timestamp,
	"revoked_reason" text,
	"expires_at" timestamp NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "safety_violations" (
	"id" varchar PRIMARY KEY NOT NULL,
	"type" text NOT NULL,
	"severity" text NOT NULL,
	"agent_id" text NOT NULL,
	"description" text NOT NULL,
	"evidence" text DEFAULT '{}' NOT NULL,
	"action" text NOT NULL,
	"handled_at" timestamp,
	"detected_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "soc2_controls" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"category" text NOT NULL,
	"control_id" text NOT NULL,
	"title" text NOT NULL,
	"description" text NOT NULL,
	"implementation_status" text DEFAULT 'NOT_IMPLEMENTED' NOT NULL,
	"evidence_required" text DEFAULT '[]' NOT NULL,
	"evidence_collected" text DEFAULT '[]' NOT NULL,
	"testing_frequency" text DEFAULT 'MONTHLY' NOT NULL,
	"last_tested" timestamp,
	"next_test_due" timestamp,
	"risk_level" text DEFAULT 'MEDIUM' NOT NULL,
	"owner" text,
	"notes" text,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "soc2_evidence" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"control_id" varchar NOT NULL,
	"type" text NOT NULL,
	"title" text NOT NULL,
	"description" text NOT NULL,
	"collected_by" text NOT NULL,
	"source" text NOT NULL,
	"content" text,
	"attachment_url" text,
	"is_automated" boolean DEFAULT false NOT NULL,
	"valid_until" timestamp,
	"tenant_id" text,
	"collected_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "supply_chain_hashes" (
	"package_name" varchar PRIMARY KEY NOT NULL,
	"expected_hash" text NOT NULL,
	"algorithm" text DEFAULT 'sha256' NOT NULL,
	"version" text NOT NULL,
	"added_by" text,
	"verified_at" timestamp DEFAULT NOW() NOT NULL,
	"expires_at" timestamp
);
--> statement-breakpoint
CREATE TABLE "supply_chain_policies" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"description" text,
	"rules_json" text DEFAULT '[]' NOT NULL,
	"enforcement_level" text DEFAULT 'WARN' NOT NULL,
	"is_active" boolean DEFAULT true NOT NULL,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "vendor_dna_alerts" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"vendor_id" varchar NOT NULL,
	"alert_type" text NOT NULL,
	"severity" text NOT NULL,
	"description" text NOT NULL,
	"detected_value" text,
	"expected_value" text,
	"status" text DEFAULT 'OPEN' NOT NULL,
	"tenant_id" text,
	"detected_at" timestamp DEFAULT NOW() NOT NULL,
	"resolved_at" timestamp
);
--> statement-breakpoint
CREATE TABLE "vendor_dna_profiles" (
	"id" varchar PRIMARY KEY NOT NULL,
	"vendor_name" text NOT NULL,
	"vendor_url" text NOT NULL,
	"category" text NOT NULL,
	"risk_level" text DEFAULT 'LOW' NOT NULL,
	"baseline_json" text DEFAULT '{}' NOT NULL,
	"current_metrics_json" text DEFAULT '{}' NOT NULL,
	"status" text DEFAULT 'MONITORING' NOT NULL,
	"last_checked_at" timestamp,
	"tenant_id" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "zk_members" (
	"id" varchar PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"member_type" text NOT NULL,
	"public_key" text NOT NULL,
	"reputation_score" integer DEFAULT 80 NOT NULL,
	"contributed_fingerprints" integer DEFAULT 0 NOT NULL,
	"received_alerts" integer DEFAULT 0 NOT NULL,
	"status" text DEFAULT 'ACTIVE' NOT NULL,
	"region" text,
	"joined_at" timestamp DEFAULT NOW() NOT NULL,
	"last_active_at" timestamp
);
--> statement-breakpoint
CREATE TABLE "zk_threat_fingerprints" (
	"id" varchar PRIMARY KEY NOT NULL,
	"contributor_id" varchar NOT NULL,
	"threat_type" text NOT NULL,
	"hash_pattern" text NOT NULL,
	"proof_hash" text NOT NULL,
	"confidence" integer DEFAULT 50 NOT NULL,
	"match_count" integer DEFAULT 0 NOT NULL,
	"is_active" boolean DEFAULT true NOT NULL,
	"expires_at" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "audit_chain_entries" (
	"id" serial PRIMARY KEY NOT NULL,
	"hash" text NOT NULL,
	"previous_hash" text NOT NULL,
	"action" text NOT NULL,
	"user_id" text,
	"resource" text NOT NULL,
	"details" text DEFAULT '' NOT NULL,
	"source_audit_id" text,
	"entry_timestamp" timestamp with time zone,
	"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "cve_feed_entries" (
	"id" serial PRIMARY KEY NOT NULL,
	"cve_id" text NOT NULL,
	"description" text NOT NULL,
	"cvss_score" numeric(4, 1) NOT NULL,
	"severity" text NOT NULL,
	"affected_vendors" text NOT NULL,
	"attack_vector" text NOT NULL,
	"attack_complexity" text NOT NULL,
	"is_exploited" boolean DEFAULT false NOT NULL,
	"mitre_ids" text DEFAULT '[]' NOT NULL,
	"published_at" timestamp NOT NULL,
	"ingested_at" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "cve_feed_entries_cve_id_unique" UNIQUE("cve_id")
);
--> statement-breakpoint
CREATE TABLE "threat_forecast_scores" (
	"id" serial PRIMARY KEY NOT NULL,
	"institution_id" integer NOT NULL,
	"institution_name" text NOT NULL,
	"composite_score" numeric(5, 2) NOT NULL,
	"cve_score" numeric(5, 2) NOT NULL,
	"dark_web_score" numeric(5, 2) NOT NULL,
	"anomaly_score" numeric(5, 2) NOT NULL,
	"attack_coverage_score" numeric(5, 2) NOT NULL,
	"risk_tier" text NOT NULL,
	"is_premium" boolean DEFAULT true NOT NULL,
	"scored_at" timestamp DEFAULT now() NOT NULL,
	"next_update_at" timestamp NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "threat_forecast_signals" (
	"id" serial PRIMARY KEY NOT NULL,
	"institution_id" integer NOT NULL,
	"source" text NOT NULL,
	"signal_type" text NOT NULL,
	"severity" text NOT NULL,
	"title" text NOT NULL,
	"summary" text NOT NULL,
	"raw_indicators" text DEFAULT '[]' NOT NULL,
	"is_confirmed" boolean DEFAULT false NOT NULL,
	"is_acknowledged" boolean DEFAULT false NOT NULL,
	"detected_at" timestamp DEFAULT now() NOT NULL,
	"expires_at" timestamp
);
--> statement-breakpoint
CREATE TABLE "transaction_anomaly_records" (
	"id" serial PRIMARY KEY NOT NULL,
	"institution_id" integer NOT NULL,
	"window_start" timestamp NOT NULL,
	"window_end" timestamp NOT NULL,
	"metric_name" text NOT NULL,
	"observed_value" numeric(14, 2) NOT NULL,
	"mean_value" numeric(14, 2) NOT NULL,
	"std_dev" numeric(14, 2) NOT NULL,
	"z_score" numeric(6, 3) NOT NULL,
	"spc_rule" text NOT NULL,
	"is_outside_control" boolean DEFAULT false NOT NULL,
	"severity" text NOT NULL,
	"detected_at" timestamp DEFAULT now() NOT NULL,
	"resolved_at" timestamp
);
--> statement-breakpoint
CREATE TABLE "audit_chain_verifications" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"valid" integer NOT NULL,
	"total_entries" integer NOT NULL,
	"broken_at" integer,
	"last_hash" text NOT NULL,
	"duration_ms" integer NOT NULL,
	"triggered_by" text NOT NULL,
	"proof_json" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "backup_restore_tests" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"tables_checked" integer NOT NULL,
	"tables_matched" integer NOT NULL,
	"total_rows_copied" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"results_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "breach_drill_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"scenario" text NOT NULL,
	"total_duration_ms" integer NOT NULL,
	"steps_completed" integer NOT NULL,
	"total_steps" integer NOT NULL,
	"within_72h" integer NOT NULL,
	"step_timings_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "load_test_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"scenario" text NOT NULL,
	"concurrency" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"total_requests" integer NOT NULL,
	"success_count" integer NOT NULL,
	"error_count" integer NOT NULL,
	"throughput_per_sec" real NOT NULL,
	"latency_avg_ms" real NOT NULL,
	"latency_min_ms" real NOT NULL,
	"latency_max_ms" real NOT NULL,
	"latency_p50_ms" real NOT NULL,
	"latency_p95_ms" real NOT NULL,
	"latency_p99_ms" real NOT NULL,
	"cpu_load_avg" real,
	"memory_rss_mb" real,
	"triggered_by" text NOT NULL,
	"notes" text,
	"started_at" timestamp DEFAULT NOW() NOT NULL,
	"finished_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "rbac_audit_log" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"user_id" varchar NOT NULL,
	"tenant_id" varchar,
	"action" text NOT NULL,
	"from_role" text,
	"to_role" text,
	"performed_by" varchar NOT NULL,
	"reason" text,
	"ip_address" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "security_test_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"test_type" text NOT NULL,
	"passed" integer NOT NULL,
	"total_checks" integer NOT NULL,
	"failed_checks" integer NOT NULL,
	"summary" text NOT NULL,
	"details_json" text NOT NULL,
	"duration_ms" integer NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "user_tenant_roles" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"user_id" varchar NOT NULL,
	"tenant_id" varchar NOT NULL,
	"role" text NOT NULL,
	"granted_by" varchar,
	"granted_at" timestamp DEFAULT NOW() NOT NULL,
	"revoked_at" timestamp,
	"is_active" boolean DEFAULT true NOT NULL,
	"is_primary" boolean DEFAULT false NOT NULL,
	"notes" text
);
--> statement-breakpoint
CREATE TABLE "chaos_drill_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"scenario" text NOT NULL,
	"passed" integer NOT NULL,
	"faults_injected" integer NOT NULL,
	"faults_recovered" integer NOT NULL,
	"recovery_ms" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "crypto_rotation_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"steps_completed" integer NOT NULL,
	"total_steps" integer NOT NULL,
	"encryption_working" integer NOT NULL,
	"decryption_working" integer NOT NULL,
	"old_key_retired" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "dsar_drill_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"request_type" text NOT NULL,
	"passed" integer NOT NULL,
	"steps_completed" integer NOT NULL,
	"total_steps" integer NOT NULL,
	"within_30_days" integer NOT NULL,
	"total_duration_ms" integer NOT NULL,
	"step_timings_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "exit_portability_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"tables_exported" integer NOT NULL,
	"total_records" integer NOT NULL,
	"bundle_size_bytes" integer NOT NULL,
	"bundle_sha256" text NOT NULL,
	"within_sla_window" integer NOT NULL,
	"sla_window_seconds" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "pentest_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"total_probes" integer NOT NULL,
	"blocked_probes" integer NOT NULL,
	"failed_probes" integer NOT NULL,
	"high_severity_findings" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "redteam_probe_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"total_probes" integer NOT NULL,
	"blocked_probes" integer NOT NULL,
	"bypassed_probes" integer NOT NULL,
	"score_percent" real NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "slo_conformance_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"endpoints_checked" integer NOT NULL,
	"endpoints_passing" integer NOT NULL,
	"total_requests" integer NOT NULL,
	"error_rate_percent" real NOT NULL,
	"latency_p50_ms" real NOT NULL,
	"latency_p95_ms" real NOT NULL,
	"latency_p99_ms" real NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "sovereignty_test_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"total_checks" integer NOT NULL,
	"failed_checks" integer NOT NULL,
	"records_examined" integer NOT NULL,
	"out_of_bounds_records" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "accessibility_audits" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"pages_scanned" integer NOT NULL,
	"issues_critical" integer NOT NULL,
	"issues_serious" integer NOT NULL,
	"issues_moderate" integer NOT NULL,
	"i18n_coverage_percent" real NOT NULL,
	"languages_covered" text NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "bias_drill_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"buckets_tested" integer NOT NULL,
	"max_fpr_delta" real NOT NULL,
	"threshold" real NOT NULL,
	"total_samples" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "breach_sla_drill_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"breach_id" text NOT NULL,
	"notifications_sent" integer NOT NULL,
	"sla_window_hours" integer NOT NULL,
	"notification_latency_ms" integer NOT NULL,
	"templates_validated" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "business_logic_pentest_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"total_probes" integer NOT NULL,
	"blocked_probes" integer NOT NULL,
	"high_severity_findings" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"findings_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "continuous_schedule_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"schedule_name" text NOT NULL,
	"passed_count" integer NOT NULL,
	"failed_count" integer NOT NULL,
	"total_drills" integer NOT NULL,
	"evidence_pack_sha256" text,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "control_cost_snapshots" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"control_name" text NOT NULL,
	"cpu_millis" integer NOT NULL,
	"storage_bytes" integer NOT NULL,
	"alert_volume" integer NOT NULL,
	"cost_usd_micros" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "failover_demo_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"from_region" text NOT NULL,
	"to_region" text NOT NULL,
	"rto_ms" integer NOT NULL,
	"rpo_ms" integer NOT NULL,
	"rto_budget_ms" integer NOT NULL,
	"rpo_budget_ms" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "model_drift_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"model_name" text NOT NULL,
	"drift_score" real NOT NULL,
	"threshold" real NOT NULL,
	"baseline_mean" real NOT NULL,
	"current_mean" real NOT NULL,
	"samples_scored" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "pia_documents" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"feature_name" text NOT NULL,
	"risk_level" text NOT NULL,
	"encrypted_fields" integer NOT NULL,
	"retention_days" integer NOT NULL,
	"legal_basis" text NOT NULL,
	"content_markdown" text NOT NULL,
	"sha256" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "regulator_inbox_messages" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"thread_id" text NOT NULL,
	"from_role" text NOT NULL,
	"from_user" text NOT NULL,
	"subject" text NOT NULL,
	"body" text NOT NULL,
	"evidence_links" text,
	"status" text DEFAULT 'open' NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "restore_drill_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"rows_restored" integer NOT NULL,
	"expected_rows" integer NOT NULL,
	"canary_found" integer NOT NULL,
	"rto_ms" integer NOT NULL,
	"rto_budget_ms" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "runbook_executions" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"runbook_name" text NOT NULL,
	"status" text NOT NULL,
	"steps_completed" integer NOT NULL,
	"total_steps" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"timeline_json" text NOT NULL,
	"signature" text NOT NULL,
	"operator" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"completed_at" timestamp
);
--> statement-breakpoint
CREATE TABLE "tamper_demo_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"detected" integer NOT NULL,
	"tampered_row_id" text NOT NULL,
	"detection_method" text NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "ai_appeals" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"transaction_ref" text NOT NULL,
	"customer_ref" text NOT NULL,
	"original_decision" text NOT NULL,
	"original_reason" text NOT NULL,
	"appeal_reason" text NOT NULL,
	"status" text DEFAULT 'pending' NOT NULL,
	"reviewer_id" text,
	"reviewer_notes" text,
	"sla_deadline" timestamp NOT NULL,
	"decided_at" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "build_manifests" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"git_commit" text NOT NULL,
	"git_branch" text NOT NULL,
	"node_version" text NOT NULL,
	"dependency_count" integer NOT NULL,
	"dependency_hash_json" text NOT NULL,
	"manifest_sha256" text NOT NULL,
	"signature" text NOT NULL,
	"captured_by" text NOT NULL,
	"captured_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "consent_ledger" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"customer_ref" text NOT NULL,
	"purpose" text NOT NULL,
	"scope" text NOT NULL,
	"granted" integer NOT NULL,
	"source" text NOT NULL,
	"evidence_links" text,
	"granted_at" timestamp DEFAULT NOW() NOT NULL,
	"revoked_at" timestamp
);
--> statement-breakpoint
CREATE TABLE "erasure_cascade_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"synthetic_customer_ref" text NOT NULL,
	"tables_scanned" integer NOT NULL,
	"rows_deleted" integer NOT NULL,
	"residual_rows_found" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "load_drill_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"scenario_name" text NOT NULL,
	"target_tps" integer NOT NULL,
	"achieved_tps" real NOT NULL,
	"total_requests" integer NOT NULL,
	"error_count" integer NOT NULL,
	"error_rate" real NOT NULL,
	"p50_latency_ms" real NOT NULL,
	"p95_latency_ms" real NOT NULL,
	"p99_latency_ms" real NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "model_cards" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"model_name" text NOT NULL,
	"model_version" text NOT NULL,
	"intended_use" text NOT NULL,
	"training_data_summary" text NOT NULL,
	"performance_metrics_json" text NOT NULL,
	"fairness_metrics_json" text NOT NULL,
	"known_limitations" text NOT NULL,
	"owner_team" text NOT NULL,
	"last_retrain_at" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "ntp_drift_checks" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"passed" integer NOT NULL,
	"ntp_source" text NOT NULL,
	"server_epoch_ms" bigint NOT NULL,
	"ntp_epoch_ms" bigint NOT NULL,
	"drift_ms" integer NOT NULL,
	"threshold_ms" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "pentest_reports" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"vendor_name" text NOT NULL,
	"report_title" text NOT NULL,
	"scope" text NOT NULL,
	"findings_critical" integer DEFAULT 0 NOT NULL,
	"findings_high" integer DEFAULT 0 NOT NULL,
	"findings_medium" integer DEFAULT 0 NOT NULL,
	"report_date" text NOT NULL,
	"file_name" text NOT NULL,
	"file_sha256" text NOT NULL,
	"file_size_bytes" integer NOT NULL,
	"signature" text NOT NULL,
	"uploaded_by" text NOT NULL,
	"uploaded_at" timestamp DEFAULT NOW() NOT NULL,
	"notes" text
);
--> statement-breakpoint
CREATE TABLE "quarterly_attestations" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"year" integer NOT NULL,
	"quarter" integer NOT NULL,
	"total_drills_run" integer NOT NULL,
	"drills_passed" integer NOT NULL,
	"drills_failed" integer NOT NULL,
	"incident_count" integer NOT NULL,
	"evidence_pack_hash" text NOT NULL,
	"content_md" text NOT NULL,
	"signature" text NOT NULL,
	"generated_by" text NOT NULL,
	"generated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "sub_processors" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"vendor_name" text NOT NULL,
	"service_category" text NOT NULL,
	"data_categories_accessed" text NOT NULL,
	"region" text NOT NULL,
	"contract_start_date" text NOT NULL,
	"contract_end_date" text,
	"pdpo_status" text NOT NULL,
	"dpa_signed_at" text,
	"last_review_at" text,
	"notes" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "breach_notification_drills" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"scenario" text NOT NULL,
	"channels_tested" text NOT NULL,
	"recipient_count" integer DEFAULT 0 NOT NULL,
	"delivered_count" integer DEFAULT 0 NOT NULL,
	"failed_count" integer DEFAULT 0 NOT NULL,
	"avg_latency_ms" integer DEFAULT 0 NOT NULL,
	"pdpo_sla_minutes" integer DEFAULT 4320 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" text,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "cross_border_transfers" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"source_country" text DEFAULT 'UG' NOT NULL,
	"destination_country" text NOT NULL,
	"destination_vendor" text NOT NULL,
	"data_categories" text NOT NULL,
	"legal_basis" text NOT NULL,
	"encryption_method" text NOT NULL,
	"retention_days" integer NOT NULL,
	"bytes_transferred" bigint DEFAULT 0 NOT NULL,
	"record_count" integer DEFAULT 0 NOT NULL,
	"pdpo_section29_compliant" integer DEFAULT 1 NOT NULL,
	"notes" text,
	"logged_by" text NOT NULL,
	"transferred_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "service_credits" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text NOT NULL,
	"breach_id" text,
	"reason" text NOT NULL,
	"amount_usd_micros" bigint NOT NULL,
	"status" text DEFAULT 'issued' NOT NULL,
	"issued_by" text NOT NULL,
	"issued_at" timestamp DEFAULT now() NOT NULL,
	"applied_at" timestamp
);
--> statement-breakpoint
CREATE TABLE "sla_breach_records" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" text NOT NULL,
	"slo_name" text NOT NULL,
	"slo_target" text NOT NULL,
	"actual_value" text NOT NULL,
	"breach_severity" text NOT NULL,
	"breach_started_at" timestamp NOT NULL,
	"breach_ended_at" timestamp,
	"duration_minutes" integer DEFAULT 0 NOT NULL,
	"credit_percent" integer DEFAULT 0 NOT NULL,
	"credit_amount_usd_micros" bigint DEFAULT 0 NOT NULL,
	"credit_issued" integer DEFAULT 0 NOT NULL,
	"details_json" text,
	"detected_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "aml_typologies" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"typology_code" text NOT NULL,
	"name" text NOT NULL,
	"category" text NOT NULL,
	"source" text NOT NULL,
	"description" text NOT NULL,
	"detection_rule" text NOT NULL,
	"coverage_status" text DEFAULT 'covered' NOT NULL,
	"last_tested_at" timestamp,
	"last_test_verdict" text,
	"synthetic_positives" integer DEFAULT 0 NOT NULL,
	"synthetic_detected" integer DEFAULT 0 NOT NULL,
	"notes" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "aml_typologies_typology_code_unique" UNIQUE("typology_code")
);
--> statement-breakpoint
CREATE TABLE "compliance_scores" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"total_score" integer NOT NULL,
	"drills_total" integer NOT NULL,
	"drills_passed" integer NOT NULL,
	"drills_failed" integer NOT NULL,
	"drills_missing" integer DEFAULT 0 NOT NULL,
	"breakdown_json" text NOT NULL,
	"trend_direction" text DEFAULT 'flat' NOT NULL,
	"computed_by" text NOT NULL,
	"computed_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "decision_explanations" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"transaction_ref" text NOT NULL,
	"customer_ref" text NOT NULL,
	"decision" text NOT NULL,
	"reason_code" text NOT NULL,
	"plain_english_explanation" text NOT NULL,
	"contributing_factors_json" text NOT NULL,
	"model_card_id" text,
	"appeal_link" text NOT NULL,
	"request_source_ip" text,
	"generated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "momo_fraud_tests" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"scenario_code" text NOT NULL,
	"scenario_name" text NOT NULL,
	"provider" text NOT NULL,
	"synthetic_txns_count" integer NOT NULL,
	"true_positives" integer NOT NULL,
	"false_negatives" integer NOT NULL,
	"false_positives" integer NOT NULL,
	"precision_pct" integer NOT NULL,
	"recall_pct" integer NOT NULL,
	"passed" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"details_json" text NOT NULL,
	"triggered_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "regulator_challenges" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"submitted_by" text NOT NULL,
	"scenario_json" text NOT NULL,
	"decision" text NOT NULL,
	"confidence_score" integer NOT NULL,
	"contributing_features_json" text NOT NULL,
	"model_used" text NOT NULL,
	"model_card_id" text,
	"plain_english_explanation" text NOT NULL,
	"appeal_eligible" integer DEFAULT 1 NOT NULL,
	"latency_ms" integer NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "sar_filings" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"sar_ref" text NOT NULL,
	"customer_ref" text NOT NULL,
	"suspicion_type" text NOT NULL,
	"amount_ugx_micros" bigint DEFAULT 0 NOT NULL,
	"drafted_at" timestamp DEFAULT NOW() NOT NULL,
	"filed_at" timestamp,
	"acknowledged_at" timestamp,
	"sla_hours" integer DEFAULT 72 NOT NULL,
	"within_sla" integer DEFAULT 0 NOT NULL,
	"fia_confirmation_ref" text,
	"status" text DEFAULT 'draft' NOT NULL,
	"filed_by" text,
	"notes" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "sar_filings_sar_ref_unique" UNIQUE("sar_ref")
);
--> statement-breakpoint
CREATE TABLE "vdp_reports" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"reporter_handle" text,
	"reporter_email_hash" text,
	"report_title" text NOT NULL,
	"report_summary" text NOT NULL,
	"severity" text DEFAULT 'unknown' NOT NULL,
	"affected_component" text,
	"status" text DEFAULT 'received' NOT NULL,
	"sla_triage_hours" integer DEFAULT 72 NOT NULL,
	"sla_fix_hours" integer DEFAULT 2160 NOT NULL,
	"triaged_at" timestamp,
	"triage_notes" text,
	"triaged_by" text,
	"resolved_at" timestamp,
	"resolution_notes" text,
	"resolved_by" text,
	"public_acknowledged" integer DEFAULT 0 NOT NULL,
	"ip_address" text,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "bou_regulatory_reports" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"report_code" text NOT NULL,
	"period_start" timestamp NOT NULL,
	"period_end" timestamp NOT NULL,
	"payload_json" text NOT NULL,
	"signed_hash_hex" text NOT NULL,
	"status" text DEFAULT 'draft' NOT NULL,
	"generated_at" timestamp DEFAULT NOW() NOT NULL,
	"generated_by" text NOT NULL,
	"submitted_at" timestamp,
	"submitted_ref" text
);
--> statement-breakpoint
CREATE TABLE "bug_bounty_rewards" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"vdp_report_id" varchar NOT NULL,
	"tier" text NOT NULL,
	"ugx_amount" bigint NOT NULL,
	"awarded_at" timestamp DEFAULT NOW() NOT NULL,
	"awarded_by" text NOT NULL,
	"hall_of_fame_handle" text,
	"public_note" text
);
--> statement-breakpoint
CREATE TABLE "code_provenance_records" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"deployment_ref" text NOT NULL,
	"git_sha" text NOT NULL,
	"build_manifest_hash_hex" text NOT NULL,
	"sbom_hash_hex" text NOT NULL,
	"signed_manifest_hex" text NOT NULL,
	"approvers_json" text NOT NULL,
	"environment" text NOT NULL,
	"deployed_at" timestamp DEFAULT NOW() NOT NULL,
	"deployed_by" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "customer_complaints" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"complaint_ref" text NOT NULL,
	"customer_ref" text NOT NULL,
	"category" text NOT NULL,
	"description" text NOT NULL,
	"sla_hours" integer DEFAULT 72 NOT NULL,
	"resolution" text,
	"resolved_at" timestamp,
	"within_sla" integer,
	"escalated" integer DEFAULT 0 NOT NULL,
	"opened_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "customer_complaints_complaint_ref_unique" UNIQUE("complaint_ref")
);
--> statement-breakpoint
CREATE TABLE "dr_failover_drills" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" text NOT NULL,
	"region_from" text NOT NULL,
	"region_to" text NOT NULL,
	"rpo_seconds" integer NOT NULL,
	"rto_seconds" integer NOT NULL,
	"dns_switch_seconds" integer NOT NULL,
	"health_checks_passed" integer NOT NULL,
	"total_checks" integer NOT NULL,
	"verdict" text NOT NULL,
	"evidence_hash_hex" text NOT NULL,
	"ran_at" timestamp DEFAULT NOW() NOT NULL,
	"ran_by" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "fee_disclosures" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"product_code" text NOT NULL,
	"product_name" text NOT NULL,
	"fee_json" text NOT NULL,
	"effective_from" timestamp NOT NULL,
	"last_updated_at" timestamp DEFAULT NOW() NOT NULL,
	"last_updated_by" text NOT NULL,
	CONSTRAINT "fee_disclosures_product_code_unique" UNIQUE("product_code")
);
--> statement-breakpoint
CREATE TABLE "insider_threat_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"scenario_code" text NOT NULL,
	"scenario_name" text NOT NULL,
	"total_actions" integer NOT NULL,
	"detected_actions" integer NOT NULL,
	"false_negatives" integer NOT NULL,
	"recall_pct" integer NOT NULL,
	"alert_latency_ms" integer NOT NULL,
	"passed" integer NOT NULL,
	"details_json" text NOT NULL,
	"ran_at" timestamp DEFAULT NOW() NOT NULL,
	"ran_by" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "mock_supervisory_exams" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"exam_ref" text NOT NULL,
	"exam_type" text NOT NULL,
	"duration_days" integer NOT NULL,
	"document_requests_total" integer NOT NULL,
	"document_requests_answered" integer NOT NULL,
	"walkthroughs_total" integer NOT NULL,
	"walkthroughs_completed" integer NOT NULL,
	"samples_total" integer NOT NULL,
	"samples_provided" integer NOT NULL,
	"findings_count" integer NOT NULL,
	"readiness_score" integer NOT NULL,
	"details_json" text NOT NULL,
	"ran_at" timestamp DEFAULT NOW() NOT NULL,
	"ran_by" text NOT NULL,
	CONSTRAINT "mock_supervisory_exams_exam_ref_unique" UNIQUE("exam_ref")
);
--> statement-breakpoint
CREATE TABLE "open_banking_consents" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"consent_ref" text NOT NULL,
	"customer_ref" text NOT NULL,
	"tpp_name" text NOT NULL,
	"data_categories" text[] NOT NULL,
	"scopes" text[] NOT NULL,
	"granted_at" timestamp DEFAULT NOW() NOT NULL,
	"expires_at" timestamp NOT NULL,
	"revoked_at" timestamp,
	"status" text DEFAULT 'active' NOT NULL,
	CONSTRAINT "open_banking_consents_consent_ref_unique" UNIQUE("consent_ref")
);
--> statement-breakpoint
CREATE TABLE "privacy_deletion_drills" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" text NOT NULL,
	"retention_policy_code" text NOT NULL,
	"records_targeted" integer NOT NULL,
	"records_deleted" integer NOT NULL,
	"deletion_proof_hash_hex" text NOT NULL,
	"duration_ms" integer NOT NULL,
	"ran_at" timestamp DEFAULT NOW() NOT NULL,
	"ran_by" text NOT NULL,
	CONSTRAINT "privacy_deletion_drills_drill_ref_unique" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "regulator_observer_credentials" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"regulator_name" text NOT NULL,
	"agency_code" text NOT NULL,
	"scopes" text[] NOT NULL,
	"token_hash" text NOT NULL,
	"expires_at" timestamp NOT NULL,
	"created_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"last_used_at" timestamp,
	"revoked_at" timestamp
);
--> statement-breakpoint
CREATE TABLE "regulator_observer_replays" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"credential_id" varchar NOT NULL,
	"resource_type" text NOT NULL,
	"resource_ref" text NOT NULL,
	"examiner_note" text,
	"ip_address" text,
	"viewed_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "sanctions_lists" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"list_code" text NOT NULL,
	"source" text NOT NULL,
	"version" text NOT NULL,
	"list_hash_hex" text NOT NULL,
	"record_count" integer NOT NULL,
	"refreshed_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "sanctions_screening_tests" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"lists_checked_json" text NOT NULL,
	"total_synthetic_targets" integer NOT NULL,
	"true_positives" integer NOT NULL,
	"false_negatives" integer NOT NULL,
	"recall_pct" integer NOT NULL,
	"passed" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"ran_at" timestamp DEFAULT NOW() NOT NULL,
	"ran_by" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "stress_test_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"scenario_code" text NOT NULL,
	"scenario_name" text NOT NULL,
	"parameters_json" text NOT NULL,
	"impact_score" integer NOT NULL,
	"capital_impact_pct" integer NOT NULL,
	"liquidity_impact_pct" integer NOT NULL,
	"rto_ms" integer NOT NULL,
	"verdict" text NOT NULL,
	"evidence_hash_hex" text NOT NULL,
	"ran_at" timestamp DEFAULT NOW() NOT NULL,
	"ran_by" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "swift_integrity_checks" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"message_ref" text NOT NULL,
	"message_type" text NOT NULL,
	"bic_sender" text NOT NULL,
	"bic_receiver" text NOT NULL,
	"amount" bigint NOT NULL,
	"currency" text NOT NULL,
	"message_hash_hex" text NOT NULL,
	"signature_valid" integer NOT NULL,
	"cbpr_compliant" integer NOT NULL,
	"fx_threshold_breached" integer NOT NULL,
	"notes" text,
	"checked_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "auditor_access_logs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"credential_id" varchar NOT NULL,
	"resource_type" text NOT NULL,
	"resource_ref" text NOT NULL,
	"ip_address" text,
	"accessed_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "auditor_credentials" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"firm_name" text NOT NULL,
	"auditor_email" text NOT NULL,
	"scopes" text[] NOT NULL,
	"token_hash" text NOT NULL,
	"expires_at" timestamp NOT NULL,
	"created_by" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"last_used_at" timestamp,
	"revoked_at" timestamp
);
--> statement-breakpoint
CREATE TABLE "board_reports" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"report_ref" text NOT NULL,
	"quarter_code" text NOT NULL,
	"total_incidents" integer NOT NULL,
	"critical_incidents" integer NOT NULL,
	"ai_decisions_overridden" integer NOT NULL,
	"regulator_interactions" integer NOT NULL,
	"uptime_pct_micros" integer NOT NULL,
	"payload_json" text NOT NULL,
	"signed_hash_hex" text NOT NULL,
	"generated_at" timestamp DEFAULT NOW() NOT NULL,
	"generated_by" text NOT NULL,
	CONSTRAINT "board_reports_report_ref_unique" UNIQUE("report_ref")
);
--> statement-breakpoint
CREATE TABLE "ctr_filings" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"ctr_ref" text NOT NULL,
	"customer_ref" text NOT NULL,
	"txn_type" text NOT NULL,
	"amount_ugx" bigint NOT NULL,
	"threshold_ugx" bigint DEFAULT 20000000 NOT NULL,
	"branch_code" text NOT NULL,
	"txn_at" timestamp NOT NULL,
	"filed_at" timestamp,
	"filed_by" text,
	"fia_confirmation_ref" text,
	"sla_hours" integer DEFAULT 168 NOT NULL,
	"within_sla" integer DEFAULT 1 NOT NULL,
	"status" text DEFAULT 'pending' NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "ctr_filings_ctr_ref_unique" UNIQUE("ctr_ref")
);
--> statement-breakpoint
CREATE TABLE "nps_settlement_windows" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"window_ref" text NOT NULL,
	"window_date" timestamp NOT NULL,
	"expected_settlement_sec" integer NOT NULL,
	"actual_settlement_sec" integer NOT NULL,
	"total_txn_count" integer NOT NULL,
	"total_amount_ugx" bigint NOT NULL,
	"within_sla" integer NOT NULL,
	"bou_ref_section" text NOT NULL,
	"captured_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "nps_settlement_windows_window_ref_unique" UNIQUE("window_ref")
);
--> statement-breakpoint
CREATE TABLE "os_vuln_scans" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"scan_ref" text NOT NULL,
	"image_ref" text NOT NULL,
	"total_packages" integer NOT NULL,
	"vulns_critical" integer DEFAULT 0 NOT NULL,
	"vulns_high" integer DEFAULT 0 NOT NULL,
	"vulns_medium" integer DEFAULT 0 NOT NULL,
	"vulns_low" integer DEFAULT 0 NOT NULL,
	"top_cve_json" text NOT NULL,
	"passed" integer NOT NULL,
	"ran_at" timestamp DEFAULT NOW() NOT NULL,
	"ran_by" text NOT NULL,
	CONSTRAINT "os_vuln_scans_scan_ref_unique" UNIQUE("scan_ref")
);
--> statement-breakpoint
CREATE TABLE "performance_budgets" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"budget_ref" text NOT NULL,
	"page_route" text NOT NULL,
	"lcp_ms" integer NOT NULL,
	"inp_ms" integer NOT NULL,
	"cls_score" integer NOT NULL,
	"wcag_violations" integer NOT NULL,
	"wcag_level" text NOT NULL,
	"passed" integer NOT NULL,
	"ran_at" timestamp DEFAULT NOW() NOT NULL,
	"ran_by" text NOT NULL,
	CONSTRAINT "performance_budgets_budget_ref_unique" UNIQUE("budget_ref")
);
--> statement-breakpoint
CREATE TABLE "phishing_campaigns" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"campaign_code" text NOT NULL,
	"campaign_name" text NOT NULL,
	"target_group" text NOT NULL,
	"template_type" text NOT NULL,
	"total_targets" integer NOT NULL,
	"delivered" integer DEFAULT 0 NOT NULL,
	"opened" integer DEFAULT 0 NOT NULL,
	"clicked" integer DEFAULT 0 NOT NULL,
	"reported" integer DEFAULT 0 NOT NULL,
	"click_rate_pct" integer DEFAULT 0 NOT NULL,
	"report_rate_pct" integer DEFAULT 0 NOT NULL,
	"training_assigned" integer DEFAULT 0 NOT NULL,
	"ran_at" timestamp DEFAULT NOW() NOT NULL,
	"ran_by" text NOT NULL,
	CONSTRAINT "phishing_campaigns_campaign_code_unique" UNIQUE("campaign_code")
);
--> statement-breakpoint
CREATE TABLE "ransomware_drills" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" text NOT NULL,
	"scenario_code" text NOT NULL,
	"ransom_demand_ugx" bigint NOT NULL,
	"refusal_logged" integer DEFAULT 1 NOT NULL,
	"vault_recovery_attempted" integer DEFAULT 0 NOT NULL,
	"vault_recovery_success" integer DEFAULT 0 NOT NULL,
	"recovery_rpo_min" integer NOT NULL,
	"recovery_rto_min" integer NOT NULL,
	"evidence_hash_hex" text NOT NULL,
	"verdict" text NOT NULL,
	"ran_at" timestamp DEFAULT NOW() NOT NULL,
	"ran_by" text NOT NULL,
	CONSTRAINT "ransomware_drills_drill_ref_unique" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "regulator_push_deliveries" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"endpoint_id" varchar NOT NULL,
	"alert_code" text NOT NULL,
	"severity" text NOT NULL,
	"payload_json" text NOT NULL,
	"signature_hex" text NOT NULL,
	"attempts" integer DEFAULT 0 NOT NULL,
	"status" text DEFAULT 'queued' NOT NULL,
	"last_error" text,
	"delivered_at" timestamp,
	"created_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "regulator_push_endpoints" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"endpoint_code" text NOT NULL,
	"agency_code" text NOT NULL,
	"webhook_url" text NOT NULL,
	"signing_secret_hash" text NOT NULL,
	"enabled" integer DEFAULT 1 NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	"created_by" text NOT NULL,
	CONSTRAINT "regulator_push_endpoints_endpoint_code_unique" UNIQUE("endpoint_code")
);
--> statement-breakpoint
CREATE TABLE "segmentation_tests" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"test_ref" text NOT NULL,
	"source_segment" text NOT NULL,
	"target_segment" text NOT NULL,
	"expected_reachable" integer NOT NULL,
	"actual_reachable" integer NOT NULL,
	"passed" integer NOT NULL,
	"evidence_json" text NOT NULL,
	"ran_at" timestamp DEFAULT NOW() NOT NULL,
	"ran_by" text NOT NULL,
	CONSTRAINT "segmentation_tests_test_ref_unique" UNIQUE("test_ref")
);
--> statement-breakpoint
CREATE TABLE "synthetic_canary_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"probe_code" text NOT NULL,
	"txn_latency_ms" integer NOT NULL,
	"kyt_latency_ms" integer NOT NULL,
	"ai_scoring_latency_ms" integer NOT NULL,
	"audit_write_latency_ms" integer NOT NULL,
	"total_latency_ms" integer NOT NULL,
	"passed" integer NOT NULL,
	"failure_reason" text,
	"ran_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "tabletop_exercises" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"exercise_ref" text NOT NULL,
	"scenario_code" text NOT NULL,
	"scenario_name" text NOT NULL,
	"participants_json" text NOT NULL,
	"detection_score" integer NOT NULL,
	"response_score" integer NOT NULL,
	"recovery_score" integer NOT NULL,
	"communication_score" integer NOT NULL,
	"overall_score" integer NOT NULL,
	"outcomes_json" text NOT NULL,
	"facilitator" text NOT NULL,
	"conducted_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "tabletop_exercises_exercise_ref_unique" UNIQUE("exercise_ref")
);
--> statement-breakpoint
CREATE TABLE "trust_dashboard_snapshots" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"snapshot_ref" text NOT NULL,
	"uptime_pct" integer NOT NULL,
	"mean_breach_response_min" integer NOT NULL,
	"ai_fairness_score" integer NOT NULL,
	"sanctions_hit_rate_pct" integer NOT NULL,
	"customer_complaints_resolved" integer NOT NULL,
	"captured_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "trust_dashboard_snapshots_snapshot_ref_unique" UNIQUE("snapshot_ref")
);
--> statement-breakpoint
CREATE TABLE "ubo_registrations" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"ubo_ref" text NOT NULL,
	"corporate_customer_ref" text NOT NULL,
	"corporate_name" text NOT NULL,
	"owner_name" text NOT NULL,
	"owner_national_id" text NOT NULL,
	"owner_nationality" text NOT NULL,
	"ownership_pct" integer NOT NULL,
	"control_type" text NOT NULL,
	"pep_status" integer DEFAULT 0 NOT NULL,
	"sanctions_status" integer DEFAULT 0 NOT NULL,
	"verified_at" timestamp,
	"registered_at" timestamp DEFAULT NOW() NOT NULL,
	"registered_by" text NOT NULL,
	"tenant_id" text,
	"erasure_state" "ubo_erasure_state" DEFAULT 'ACTIVE' NOT NULL,
	"superseded_at" timestamp,
	"superseded_by" text,
	"erasure_matured_at" timestamp,
	"erasure_trigger" "ubo_erasure_trigger",
	"erasure_audit_ref" text,
	"individual_erasure_pending" text,
	"owner_national_id_hmac" text,
	CONSTRAINT "ubo_registrations_ubo_ref_unique" UNIQUE("ubo_ref")
);
--> statement-breakpoint
CREATE TABLE "decision_replays" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"replay_ref" text NOT NULL,
	"original_decision_ref" text NOT NULL,
	"decision_type" text NOT NULL,
	"original_score" integer NOT NULL,
	"replay_score" integer NOT NULL,
	"score_delta_micros" integer NOT NULL,
	"reproducible" integer NOT NULL,
	"model_version" text NOT NULL,
	"inputs_json" text NOT NULL,
	"outputs_json" text NOT NULL,
	"ran_by" text NOT NULL,
	"ran_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "decision_replays_replay_ref_unique" UNIQUE("replay_ref")
);
--> statement-breakpoint
CREATE TABLE "demo_pack_generations" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"pack_ref" text NOT NULL,
	"modules_included" integer NOT NULL,
	"modules_passed" integer NOT NULL,
	"modules_failed" integer NOT NULL,
	"total_evidence_count" integer NOT NULL,
	"payload_json" text NOT NULL,
	"payload_hash" text NOT NULL,
	"signature_hex" text NOT NULL,
	"generated_by" text NOT NULL,
	"generated_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "demo_pack_generations_pack_ref_unique" UNIQUE("pack_ref")
);
--> statement-breakpoint
CREATE TABLE "dr_drill_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" text NOT NULL,
	"scenario_code" text NOT NULL,
	"primary_region" text NOT NULL,
	"failover_region" text NOT NULL,
	"detection_time_sec" integer NOT NULL,
	"failover_time_sec" integer NOT NULL,
	"rpo_min" integer NOT NULL,
	"rto_min" integer NOT NULL,
	"failback_time_sec" integer NOT NULL,
	"data_loss_records" integer DEFAULT 0 NOT NULL,
	"passed" integer NOT NULL,
	"evidence_hash" text NOT NULL,
	"ran_by" text NOT NULL,
	"ran_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "dr_drill_runs_drill_ref_unique" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "e2e_test_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"run_ref" text NOT NULL,
	"scenario_code" text NOT NULL,
	"scenario_name" text NOT NULL,
	"total_steps" integer NOT NULL,
	"passed_steps" integer NOT NULL,
	"failed_steps" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"passed" integer NOT NULL,
	"steps_json" text NOT NULL,
	"evidence_hash" text NOT NULL,
	"ran_by" text NOT NULL,
	"ran_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "e2e_test_runs_run_ref_unique" UNIQUE("run_ref")
);
--> statement-breakpoint
CREATE TABLE "i18n_translations" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"translation_key" text NOT NULL,
	"locale" text NOT NULL,
	"value" text NOT NULL,
	"category" text DEFAULT 'ui' NOT NULL,
	"updated_at" timestamp DEFAULT NOW() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "metrics_snapshots" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"snapshot_ref" text NOT NULL,
	"uptime_sec" integer NOT NULL,
	"total_requests" bigint NOT NULL,
	"error_rate_pct_micros" integer NOT NULL,
	"p95_latency_ms" integer NOT NULL,
	"ai_decisions_total" bigint NOT NULL,
	"threat_events_total" bigint NOT NULL,
	"captured_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "metrics_snapshots_snapshot_ref_unique" UNIQUE("snapshot_ref")
);
--> statement-breakpoint
CREATE TABLE "momo_sandbox_txns" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"txn_ref" text NOT NULL,
	"provider" text NOT NULL,
	"txn_type" text NOT NULL,
	"msisdn" text NOT NULL,
	"amount_ugx" bigint NOT NULL,
	"status" text NOT NULL,
	"provider_ref" text NOT NULL,
	"risk_score" integer NOT NULL,
	"flagged" integer DEFAULT 0 NOT NULL,
	"response_json" text NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "momo_sandbox_txns_txn_ref_unique" UNIQUE("txn_ref")
);
--> statement-breakpoint
CREATE TABLE "ombudsman_complaints" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"complaint_ref" text NOT NULL,
	"customer_name" text NOT NULL,
	"customer_contact" text NOT NULL,
	"channel" text NOT NULL,
	"category" text NOT NULL,
	"description" text NOT NULL,
	"severity" text DEFAULT 'MEDIUM' NOT NULL,
	"status" text DEFAULT 'open' NOT NULL,
	"sla_hours" integer DEFAULT 72 NOT NULL,
	"resolved_at" timestamp,
	"resolved_by" text,
	"resolution" text,
	"escalated_to_ombudsman" integer DEFAULT 0 NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "ombudsman_complaints_complaint_ref_unique" UNIQUE("complaint_ref")
);
--> statement-breakpoint
CREATE TABLE "regulator_onboarding_sessions" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"session_ref" text NOT NULL,
	"regulator_agency" text NOT NULL,
	"examiner_name" text NOT NULL,
	"examiner_email" text NOT NULL,
	"step1_account_created" integer DEFAULT 0 NOT NULL,
	"step2_auditor_token_issued" integer DEFAULT 0 NOT NULL,
	"step3_drill_scheduled" integer DEFAULT 0 NOT NULL,
	"step4_demo_pack_reviewed" integer DEFAULT 0 NOT NULL,
	"step5_certificate_issued" integer DEFAULT 0 NOT NULL,
	"certificate_ref" text,
	"certificate_hash" text,
	"started_by" text NOT NULL,
	"started_at" timestamp DEFAULT NOW() NOT NULL,
	"completed_at" timestamp,
	CONSTRAINT "regulator_onboarding_sessions_session_ref_unique" UNIQUE("session_ref")
);
--> statement-breakpoint
CREATE TABLE "security_scans" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"scan_ref" text NOT NULL,
	"scan_type" text NOT NULL,
	"target_url" text NOT NULL,
	"grade_letter" text NOT NULL,
	"score_of_100" integer NOT NULL,
	"high_findings" integer DEFAULT 0 NOT NULL,
	"medium_findings" integer DEFAULT 0 NOT NULL,
	"low_findings" integer DEFAULT 0 NOT NULL,
	"findings_json" text NOT NULL,
	"ran_by" text NOT NULL,
	"ran_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "security_scans_scan_ref_unique" UNIQUE("scan_ref")
);
--> statement-breakpoint
CREATE TABLE "slsa_attestations" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"attestation_ref" text NOT NULL,
	"build_id" text NOT NULL,
	"git_commit_sha" text NOT NULL,
	"builder_id" text NOT NULL,
	"build_type" text NOT NULL,
	"slsa_level" integer NOT NULL,
	"subject_name" text NOT NULL,
	"subject_digest_sha256" text NOT NULL,
	"predicate_json" text NOT NULL,
	"signature_hex" text NOT NULL,
	"verified" integer DEFAULT 1 NOT NULL,
	"created_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "slsa_attestations_attestation_ref_unique" UNIQUE("attestation_ref")
);
--> statement-breakpoint
CREATE TABLE "threat_intel_iocs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"ioc_id" text NOT NULL,
	"ioc_type" text NOT NULL,
	"ioc_value" text NOT NULL,
	"threat_type" text NOT NULL,
	"confidence" integer NOT NULL,
	"severity" text NOT NULL,
	"feed_source" text NOT NULL,
	"valid_from" timestamp NOT NULL,
	"valid_until" timestamp,
	"stix_object_json" text NOT NULL,
	"ingested_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "threat_intel_iocs_ioc_id_unique" UNIQUE("ioc_id")
);
--> statement-breakpoint
CREATE TABLE "wave8_load_test_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"run_ref" text NOT NULL,
	"target_endpoint" text NOT NULL,
	"concurrency" integer NOT NULL,
	"duration_sec" integer NOT NULL,
	"total_requests" integer NOT NULL,
	"success_count" integer NOT NULL,
	"error_count" integer NOT NULL,
	"p50_latency_ms" integer NOT NULL,
	"p95_latency_ms" integer NOT NULL,
	"p99_latency_ms" integer NOT NULL,
	"max_latency_ms" integer NOT NULL,
	"throughput_rps" integer NOT NULL,
	"passed" integer NOT NULL,
	"slo_p95_ms" integer DEFAULT 200 NOT NULL,
	"ran_by" text NOT NULL,
	"ran_at" timestamp DEFAULT NOW() NOT NULL,
	CONSTRAINT "wave8_load_test_runs_run_ref_unique" UNIQUE("run_ref")
);
--> statement-breakpoint
CREATE TABLE "cross_pillar_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"run_ref" varchar NOT NULL,
	"modules_total" integer NOT NULL,
	"modules_passed" integer NOT NULL,
	"modules_failed" integer NOT NULL,
	"results_json" jsonb NOT NULL,
	"evidence_hash" varchar NOT NULL,
	"signature_hex" varchar NOT NULL,
	"ran_by" varchar NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "cross_pillar_runs_run_ref_unique" UNIQUE("run_ref")
);
--> statement-breakpoint
CREATE TABLE "dpia_documents" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"dpia_ref" varchar NOT NULL,
	"system_name" varchar NOT NULL,
	"processor" varchar NOT NULL,
	"controller" varchar NOT NULL,
	"data_categories_json" jsonb NOT NULL,
	"lawful_basis" varchar NOT NULL,
	"risks_json" jsonb NOT NULL,
	"mitigations_json" jsonb NOT NULL,
	"residual_risk_score" integer NOT NULL,
	"payload_hash" varchar NOT NULL,
	"generated_by" varchar NOT NULL,
	"generated_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "dpia_documents_dpia_ref_unique" UNIQUE("dpia_ref")
);
--> statement-breakpoint
CREATE TABLE "examiner_tokens" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"token_hash" varchar NOT NULL,
	"examiner_name" varchar NOT NULL,
	"examiner_email" varchar NOT NULL,
	"scopes_json" jsonb NOT NULL,
	"issued_by" varchar NOT NULL,
	"issued_at" timestamp with time zone DEFAULT now() NOT NULL,
	"expires_at" timestamp with time zone NOT NULL,
	"revoked_at" timestamp with time zone,
	"last_used_at" timestamp with time zone,
	"use_count" integer DEFAULT 0 NOT NULL,
	CONSTRAINT "examiner_tokens_token_hash_unique" UNIQUE("token_hash")
);
--> statement-breakpoint
CREATE TABLE "negative_path_scans" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"scan_ref" varchar NOT NULL,
	"scan_type" varchar NOT NULL,
	"targets_tested" integer NOT NULL,
	"vulns_high" integer NOT NULL,
	"vulns_medium" integer NOT NULL,
	"vulns_low" integer NOT NULL,
	"grade_letter" varchar NOT NULL,
	"score_of_100" integer NOT NULL,
	"findings_json" jsonb NOT NULL,
	"ran_by" varchar NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "negative_path_scans_scan_ref_unique" UNIQUE("scan_ref")
);
--> statement-breakpoint
CREATE TABLE "openapi_contract_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"run_ref" varchar NOT NULL,
	"total_endpoints" integer NOT NULL,
	"endpoints_tested" integer NOT NULL,
	"endpoints_passed" integer NOT NULL,
	"endpoints_failed" integer NOT NULL,
	"drift_findings_json" jsonb NOT NULL,
	"passed" integer NOT NULL,
	"ran_by" varchar NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "openapi_contract_runs_run_ref_unique" UNIQUE("run_ref")
);
--> statement-breakpoint
CREATE TABLE "rbac_matrix_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"run_ref" varchar NOT NULL,
	"total_combos" integer NOT NULL,
	"combos_passed" integer NOT NULL,
	"combos_failed" integer NOT NULL,
	"findings_json" jsonb NOT NULL,
	"passed" integer NOT NULL,
	"ran_by" varchar NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "rbac_matrix_runs_run_ref_unique" UNIQUE("run_ref")
);
--> statement-breakpoint
CREATE TABLE "readiness_scores" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"score_ref" varchar NOT NULL,
	"score_of_100" integer NOT NULL,
	"modules_evaluated" integer NOT NULL,
	"modules_passing" integer NOT NULL,
	"breakdown_json" jsonb NOT NULL,
	"captured_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "readiness_scores_score_ref_unique" UNIQUE("score_ref")
);
--> statement-breakpoint
CREATE TABLE "regulator_simulations" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"sim_ref" varchar NOT NULL,
	"scenario_code" varchar NOT NULL,
	"scenario_name" varchar NOT NULL,
	"steps_json" jsonb NOT NULL,
	"expected_outcomes_json" jsonb NOT NULL,
	"actual_outcomes_json" jsonb NOT NULL,
	"passed" integer NOT NULL,
	"evidence_hash" varchar NOT NULL,
	"duration_ms" integer NOT NULL,
	"ran_by" varchar NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "regulator_simulations_sim_ref_unique" UNIQUE("sim_ref")
);
--> statement-breakpoint
CREATE TABLE "sbom_exports" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"export_ref" varchar NOT NULL,
	"format" varchar NOT NULL,
	"components_count" integer NOT NULL,
	"vulnerabilities_count" integer NOT NULL,
	"payload_hash" varchar NOT NULL,
	"payload_json" text NOT NULL,
	"exported_by" varchar NOT NULL,
	"exported_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "sbom_exports_export_ref_unique" UNIQUE("export_ref")
);
--> statement-breakpoint
CREATE TABLE "status_incidents" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"incident_ref" varchar NOT NULL,
	"title" varchar NOT NULL,
	"severity" varchar NOT NULL,
	"status" varchar NOT NULL,
	"affected_components_json" jsonb NOT NULL,
	"public_message" text NOT NULL,
	"started_at" timestamp with time zone DEFAULT now() NOT NULL,
	"resolved_at" timestamp with time zone,
	"created_by" varchar NOT NULL,
	CONSTRAINT "status_incidents_incident_ref_unique" UNIQUE("incident_ref")
);
--> statement-breakpoint
CREATE TABLE "tenant_export_bundles" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"bundle_ref" varchar NOT NULL,
	"tenant_id" varchar NOT NULL,
	"record_counts_json" jsonb NOT NULL,
	"encrypted_payload_b64" text NOT NULL,
	"payload_hash" varchar NOT NULL,
	"signature_hex" varchar NOT NULL,
	"generated_by" varchar NOT NULL,
	"generated_at" timestamp with time zone DEFAULT now() NOT NULL,
	"expires_at" timestamp with time zone NOT NULL,
	CONSTRAINT "tenant_export_bundles_bundle_ref_unique" UNIQUE("bundle_ref")
);
--> statement-breakpoint
CREATE TABLE "wcag_audits" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"audit_ref" varchar NOT NULL,
	"route_path" varchar NOT NULL,
	"wcag_level" varchar NOT NULL,
	"violations_count" integer NOT NULL,
	"passes_count" integer NOT NULL,
	"incomplete_count" integer NOT NULL,
	"score_of_100" integer NOT NULL,
	"findings_json" jsonb NOT NULL,
	"ran_by" varchar NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "wcag_audits_audit_ref_unique" UNIQUE("audit_ref")
);
--> statement-breakpoint
CREATE TABLE "attestation_uploads" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"upload_ref" varchar(64) NOT NULL,
	"attestation_type" varchar(64) NOT NULL,
	"issuer_name" varchar(256) NOT NULL,
	"scope" text NOT NULL,
	"issued_at" timestamp with time zone NOT NULL,
	"expires_at" timestamp with time zone NOT NULL,
	"file_hash_sha256" varchar(128) NOT NULL,
	"file_size_bytes" integer DEFAULT 0 NOT NULL,
	"file_base64" text NOT NULL,
	"status" varchar(16) DEFAULT 'ACTIVE' NOT NULL,
	"uploaded_by" varchar(128) NOT NULL,
	"uploaded_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "attestation_uploads_upload_ref_unique" UNIQUE("upload_ref")
);
--> statement-breakpoint
CREATE TABLE "backup_restore_drills" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" varchar(64) NOT NULL,
	"backup_ref" varchar(64) NOT NULL,
	"restore_duration_ms" integer DEFAULT 0 NOT NULL,
	"rpo_minutes" integer DEFAULT 0 NOT NULL,
	"rto_minutes" integer DEFAULT 0 NOT NULL,
	"rows_verified" integer DEFAULT 0 NOT NULL,
	"hash_match" integer DEFAULT 0 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"evidence_hash" varchar(128) NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"ran_by" varchar(128) NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "backup_restore_drills_drill_ref_unique" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "bias_audit_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"audit_ref" varchar(64) NOT NULL,
	"model_key" varchar(128) NOT NULL,
	"protected_attribute" varchar(64) NOT NULL,
	"sample_size" integer DEFAULT 0 NOT NULL,
	"demographic_parity" real DEFAULT 0 NOT NULL,
	"equal_opportunity" real DEFAULT 0 NOT NULL,
	"disparate_impact_ratio" real DEFAULT 0 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"grade" varchar(4) DEFAULT 'F' NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"ran_by" varchar(128) NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "bias_audit_runs_audit_ref_unique" UNIQUE("audit_ref")
);
--> statement-breakpoint
CREATE TABLE "chaos_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"run_ref" varchar(64) NOT NULL,
	"scenario" varchar(64) NOT NULL,
	"duration_ms" integer DEFAULT 0 NOT NULL,
	"recovery_ms" integer DEFAULT 0 NOT NULL,
	"resilience_score" integer DEFAULT 0 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"ran_by" varchar(128) NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "chaos_runs_run_ref_unique" UNIQUE("run_ref")
);
--> statement-breakpoint
CREATE TABLE "consent_ledger_v2" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"entry_ref" varchar(64) NOT NULL,
	"customer_ref" varchar(128) NOT NULL,
	"consent_type" varchar(64) NOT NULL,
	"action" varchar(16) NOT NULL,
	"scope" text NOT NULL,
	"lawful_basis" varchar(64) NOT NULL,
	"captured_by" varchar(128) NOT NULL,
	"prev_hash" varchar(128) NOT NULL,
	"entry_hash" varchar(128) NOT NULL,
	"captured_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "consent_ledger_v2_entry_ref_unique" UNIQUE("entry_ref")
);
--> statement-breakpoint
CREATE TABLE "custom_reports" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"report_key" varchar(128) NOT NULL,
	"report_name" varchar(256) NOT NULL,
	"description" text DEFAULT '' NOT NULL,
	"data_source" varchar(64) NOT NULL,
	"fields_json" jsonb DEFAULT '[]' NOT NULL,
	"filters_json" jsonb DEFAULT '{}' NOT NULL,
	"schedule_cron" varchar(64),
	"last_run_at" timestamp with time zone,
	"last_row_count" integer DEFAULT 0 NOT NULL,
	"created_by" varchar(128) NOT NULL,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "custom_reports_report_key_unique" UNIQUE("report_key")
);
--> statement-breakpoint
CREATE TABLE "fuzz_test_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"run_ref" varchar(64) NOT NULL,
	"endpoints_tested" integer DEFAULT 0 NOT NULL,
	"payloads_total" integer DEFAULT 0 NOT NULL,
	"crashes_500" integer DEFAULT 0 NOT NULL,
	"unhandled_errors" integer DEFAULT 0 NOT NULL,
	"accepted_malformed" integer DEFAULT 0 NOT NULL,
	"score_of_100" integer DEFAULT 0 NOT NULL,
	"findings_json" jsonb DEFAULT '[]' NOT NULL,
	"ran_by" varchar(128) NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "fuzz_test_runs_run_ref_unique" UNIQUE("run_ref")
);
--> statement-breakpoint
CREATE TABLE "key_rotation_drills" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" varchar(64) NOT NULL,
	"key_type" varchar(32) NOT NULL,
	"old_key_id" varchar(64) NOT NULL,
	"new_key_id" varchar(64) NOT NULL,
	"rotation_duration_ms" integer DEFAULT 0 NOT NULL,
	"zero_downtime" integer DEFAULT 1 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"evidence_hash" varchar(128) NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"ran_by" varchar(128) NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "key_rotation_drills_drill_ref_unique" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "kri_metrics" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"metric_key" varchar(128) NOT NULL,
	"metric_name" varchar(256) NOT NULL,
	"category" varchar(64) NOT NULL,
	"current_value" real DEFAULT 0 NOT NULL,
	"threshold_green" real DEFAULT 0 NOT NULL,
	"threshold_amber" real DEFAULT 0 NOT NULL,
	"threshold_red" real DEFAULT 0 NOT NULL,
	"unit" varchar(32) DEFAULT '' NOT NULL,
	"status" varchar(16) DEFAULT 'GREEN' NOT NULL,
	"trend" varchar(16) DEFAULT 'STABLE' NOT NULL,
	"captured_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "model_cards_v2" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"model_key" varchar(128) NOT NULL,
	"model_name" varchar(256) NOT NULL,
	"model_version" varchar(64) NOT NULL,
	"model_type" varchar(64) NOT NULL,
	"vendor" varchar(128) NOT NULL,
	"purpose" text NOT NULL,
	"training_data" text NOT NULL,
	"performance_metrics_json" jsonb DEFAULT '{}' NOT NULL,
	"limitations_json" jsonb DEFAULT '[]' NOT NULL,
	"ethics_considerations_json" jsonb DEFAULT '[]' NOT NULL,
	"drift_signals" text DEFAULT '' NOT NULL,
	"owner_email" varchar(256) NOT NULL,
	"reviewed_by" varchar(128),
	"reviewed_at" timestamp with time zone,
	"published_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "model_cards_v2_model_key_unique" UNIQUE("model_key")
);
--> statement-breakpoint
CREATE TABLE "model_rollback_drills" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" varchar(64) NOT NULL,
	"model_key" varchar(128) NOT NULL,
	"from_version" varchar(64) NOT NULL,
	"to_version" varchar(64) NOT NULL,
	"rollback_duration_ms" integer DEFAULT 0 NOT NULL,
	"sla_minutes" integer DEFAULT 15 NOT NULL,
	"within_sla" integer DEFAULT 0 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"evidence_hash" varchar(128) NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"ran_by" varchar(128) NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "model_rollback_drills_drill_ref_unique" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "owasp_api_scans" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"scan_ref" varchar(64) NOT NULL,
	"total_checks" integer DEFAULT 0 NOT NULL,
	"passed_checks" integer DEFAULT 0 NOT NULL,
	"failed_checks" integer DEFAULT 0 NOT NULL,
	"high_count" integer DEFAULT 0 NOT NULL,
	"medium_count" integer DEFAULT 0 NOT NULL,
	"low_count" integer DEFAULT 0 NOT NULL,
	"score_of_100" integer DEFAULT 0 NOT NULL,
	"grade" varchar(4) DEFAULT 'F' NOT NULL,
	"findings_json" jsonb DEFAULT '[]' NOT NULL,
	"ran_by" varchar(128) NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "owasp_api_scans_scan_ref_unique" UNIQUE("scan_ref")
);
--> statement-breakpoint
CREATE TABLE "pdf_certificates" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"cert_ref" varchar(64) NOT NULL,
	"cert_type" varchar(64) NOT NULL,
	"subject" varchar(256) NOT NULL,
	"issued_to" varchar(256) NOT NULL,
	"payload_hash" varchar(128) NOT NULL,
	"signature_hex" varchar(256) NOT NULL,
	"pdf_bytes" integer DEFAULT 0 NOT NULL,
	"pdf_base64" text NOT NULL,
	"generated_by" varchar(128) NOT NULL,
	"generated_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "pdf_certificates_cert_ref_unique" UNIQUE("cert_ref")
);
--> statement-breakpoint
CREATE TABLE "vendor_risk_register" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"vendor_key" varchar(128) NOT NULL,
	"vendor_name" varchar(256) NOT NULL,
	"category" varchar(64) NOT NULL,
	"contact_email" varchar(256) NOT NULL,
	"risk_score" integer DEFAULT 0 NOT NULL,
	"risk_tier" varchar(16) DEFAULT 'LOW' NOT NULL,
	"contract_end_date" timestamp with time zone,
	"last_reviewed_at" timestamp with time zone,
	"next_review_due_at" timestamp with time zone,
	"certifications_json" jsonb DEFAULT '[]' NOT NULL,
	"notes" text DEFAULT '' NOT NULL,
	"active" integer DEFAULT 1 NOT NULL,
	"added_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "vendor_risk_register_vendor_key_unique" UNIQUE("vendor_key")
);
--> statement-breakpoint
CREATE TABLE "canary_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"run_ref" varchar(64) NOT NULL,
	"trigger" varchar(16) DEFAULT 'scheduled' NOT NULL,
	"scenario_count" integer DEFAULT 0 NOT NULL,
	"passed_count" integer DEFAULT 0 NOT NULL,
	"failed_count" integer DEFAULT 0 NOT NULL,
	"p50_ms" integer DEFAULT 0 NOT NULL,
	"p95_ms" integer DEFAULT 0 NOT NULL,
	"p99_ms" integer DEFAULT 0 NOT NULL,
	"baseline_p95_ms" integer DEFAULT 0 NOT NULL,
	"drift_ratio" real DEFAULT 1 NOT NULL,
	"alert_severity" varchar(16) DEFAULT 'none' NOT NULL,
	"score_of_100" integer DEFAULT 0 NOT NULL,
	"grade" varchar(4) DEFAULT 'F' NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"ran_by" varchar(128) NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "canary_runs_run_ref_unique" UNIQUE("run_ref")
);
--> statement-breakpoint
CREATE TABLE "dr_drill_results" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" varchar(64) NOT NULL,
	"drill_type" varchar(32) DEFAULT 'scheduled' NOT NULL,
	"trigger_at" timestamp with time zone NOT NULL,
	"failover_at" timestamp with time zone NOT NULL,
	"first_write_at" timestamp with time zone NOT NULL,
	"full_sync_at" timestamp with time zone NOT NULL,
	"rto_seconds" integer DEFAULT 0 NOT NULL,
	"rpo_seconds" integer DEFAULT 0 NOT NULL,
	"rto_target_seconds" integer DEFAULT 300 NOT NULL,
	"rpo_target_seconds" integer DEFAULT 60 NOT NULL,
	"rto_met" integer DEFAULT 0 NOT NULL,
	"rpo_met" integer DEFAULT 0 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"evidence_hash" varchar(128) NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"ran_by" varchar(128) NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "dr_drill_results_drill_ref_unique" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "forensic_bundles" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"bundle_ref" varchar(64) NOT NULL,
	"threat_event_id" varchar(128) NOT NULL,
	"bundle_size_bytes" integer DEFAULT 0 NOT NULL,
	"item_count" integer DEFAULT 0 NOT NULL,
	"manifest_hash" varchar(128) NOT NULL,
	"signature_hex" varchar(256) NOT NULL,
	"bundle_zip_b64" text NOT NULL,
	"manifest_json" jsonb DEFAULT '{}' NOT NULL,
	"generated_by" varchar(128) NOT NULL,
	"generated_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "forensic_bundles_bundle_ref_unique" UNIQUE("bundle_ref")
);
--> statement-breakpoint
CREATE TABLE "key_inventory" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"key_id" varchar(96) NOT NULL,
	"key_type" varchar(32) NOT NULL,
	"algorithm" varchar(64) NOT NULL,
	"bit_length" integer DEFAULT 0 NOT NULL,
	"owner_email" varchar(192) NOT NULL,
	"status" varchar(16) DEFAULT 'active' NOT NULL,
	"storage_location" varchar(64) DEFAULT 'env' NOT NULL,
	"rotation_interval_days" integer DEFAULT 90 NOT NULL,
	"last_rotated_at" timestamp with time zone,
	"next_rotation_due_at" timestamp with time zone,
	"post_quantum" integer DEFAULT 0 NOT NULL,
	"notes_json" jsonb DEFAULT '{}' NOT NULL,
	"created_by" varchar(128) NOT NULL,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "key_inventory_key_id_unique" UNIQUE("key_id")
);
--> statement-breakpoint
CREATE TABLE "pdpo_breach_drills" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" varchar(64) NOT NULL,
	"synthetic_breach_at" timestamp with time zone NOT NULL,
	"detected_at_ts" timestamp with time zone NOT NULL,
	"triaged_at" timestamp with time zone NOT NULL,
	"notification_drafted_at" timestamp with time zone NOT NULL,
	"notification_delivered_at" timestamp with time zone NOT NULL,
	"total_seconds" integer DEFAULT 0 NOT NULL,
	"threshold_seconds" integer DEFAULT 259200 NOT NULL,
	"within_threshold" integer DEFAULT 0 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"recipients_json" jsonb DEFAULT '[]' NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"ran_by" varchar(128) NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "pdpo_breach_drills_drill_ref_unique" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "prompt_injection_corpus" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"corpus_key" varchar(96) NOT NULL,
	"category" varchar(48) NOT NULL,
	"severity" varchar(16) DEFAULT 'medium' NOT NULL,
	"payload" text NOT NULL,
	"expected_behavior" text NOT NULL,
	"active" integer DEFAULT 1 NOT NULL,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "prompt_injection_corpus_corpus_key_unique" UNIQUE("corpus_key")
);
--> statement-breakpoint
CREATE TABLE "prompt_injection_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"run_ref" varchar(64) NOT NULL,
	"total_cases" integer DEFAULT 0 NOT NULL,
	"defended_count" integer DEFAULT 0 NOT NULL,
	"bypassed_count" integer DEFAULT 0 NOT NULL,
	"error_count" integer DEFAULT 0 NOT NULL,
	"defense_rate_pct" real DEFAULT 0 NOT NULL,
	"score_of_100" integer DEFAULT 0 NOT NULL,
	"grade" varchar(4) DEFAULT 'F' NOT NULL,
	"by_category_json" jsonb DEFAULT '{}' NOT NULL,
	"bypasses_json" jsonb DEFAULT '[]' NOT NULL,
	"ran_by" varchar(128) NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "prompt_injection_runs_run_ref_unique" UNIQUE("run_ref")
);
--> statement-breakpoint
CREATE TABLE "residency_attestations" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"attestation_ref" varchar(64) NOT NULL,
	"period_month" varchar(7) NOT NULL,
	"jurisdiction" varchar(32) DEFAULT 'UG' NOT NULL,
	"edge_node_count" integer DEFAULT 0 NOT NULL,
	"total_requests" integer DEFAULT 0 NOT NULL,
	"in_jurisdiction_requests" integer DEFAULT 0 NOT NULL,
	"out_of_jurisdiction_requests" integer DEFAULT 0 NOT NULL,
	"pii_bytes_processed" integer DEFAULT 0 NOT NULL,
	"pii_bytes_egressed" integer DEFAULT 0 NOT NULL,
	"compliance_pct" real DEFAULT 100 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"manifest_hash" varchar(128) NOT NULL,
	"signature_hex" varchar(256) NOT NULL,
	"manifest_json" jsonb DEFAULT '{}' NOT NULL,
	"generated_by" varchar(128) NOT NULL,
	"generated_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "residency_attestations_attestation_ref_unique" UNIQUE("attestation_ref")
);
--> statement-breakpoint
CREATE TABLE "sla_breaches" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"breach_ref" varchar(64) NOT NULL,
	"metric_key" varchar(96) NOT NULL,
	"observed_ms" integer NOT NULL,
	"threshold_ms" integer NOT NULL,
	"exceed_ratio" real DEFAULT 1 NOT NULL,
	"duration_seconds" integer DEFAULT 0 NOT NULL,
	"severity" varchar(16) DEFAULT 'warning' NOT NULL,
	"notified" integer DEFAULT 0 NOT NULL,
	"resolved" integer DEFAULT 0 NOT NULL,
	"resolved_at" timestamp with time zone,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"detected_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "sla_breaches_breach_ref_unique" UNIQUE("breach_ref")
);
--> statement-breakpoint
CREATE TABLE "sla_thresholds" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"metric_key" varchar(96) NOT NULL,
	"display_name" varchar(192) NOT NULL,
	"threshold_ms" integer NOT NULL,
	"window_seconds" integer DEFAULT 180 NOT NULL,
	"enabled" integer DEFAULT 1 NOT NULL,
	"notify_on_breach" integer DEFAULT 1 NOT NULL,
	"updated_by" varchar(128) NOT NULL,
	"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "sla_thresholds_metric_key_unique" UNIQUE("metric_key")
);
--> statement-breakpoint
CREATE TABLE "traffic_shadow_captures" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"capture_ref" varchar(64) NOT NULL,
	"method" varchar(8) NOT NULL,
	"path_template" varchar(256) NOT NULL,
	"request_body_hash" varchar(128) NOT NULL,
	"response_status" integer NOT NULL,
	"response_hash" varchar(128) NOT NULL,
	"response_duration_ms" integer DEFAULT 0 NOT NULL,
	"redacted_body_json" jsonb DEFAULT '{}' NOT NULL,
	"captured_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "traffic_shadow_captures_capture_ref_unique" UNIQUE("capture_ref")
);
--> statement-breakpoint
CREATE TABLE "traffic_shadow_replays" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"replay_ref" varchar(64) NOT NULL,
	"captures_replayed" integer DEFAULT 0 NOT NULL,
	"match_count" integer DEFAULT 0 NOT NULL,
	"diff_count" integer DEFAULT 0 NOT NULL,
	"error_count" integer DEFAULT 0 NOT NULL,
	"match_rate_pct" real DEFAULT 0 NOT NULL,
	"score_of_100" integer DEFAULT 0 NOT NULL,
	"grade" varchar(4) DEFAULT 'F' NOT NULL,
	"diffs_json" jsonb DEFAULT '[]' NOT NULL,
	"ran_by" varchar(128) NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "traffic_shadow_replays_replay_ref_unique" UNIQUE("replay_ref")
);
--> statement-breakpoint
CREATE TABLE "pilot_master_scores" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"score_ref" varchar(64) NOT NULL,
	"generated_by" varchar(128) NOT NULL,
	"composite_score" integer DEFAULT 0 NOT NULL,
	"grade" varchar(4) DEFAULT 'F' NOT NULL,
	"wave_scores_json" jsonb DEFAULT '{}' NOT NULL,
	"pillar_breakdown_json" jsonb DEFAULT '[]' NOT NULL,
	"payload_hash" varchar(128) NOT NULL,
	"signature_hex" varchar(256) NOT NULL,
	"generated_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "pilot_master_scores_score_ref_key" UNIQUE("score_ref")
);
--> statement-breakpoint
CREATE TABLE "pilot_smoke_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"run_ref" varchar(64) NOT NULL,
	"triggered_by" varchar(128) NOT NULL,
	"duration_ms" integer DEFAULT 0 NOT NULL,
	"pillar_count" integer DEFAULT 0 NOT NULL,
	"passed_count" integer DEFAULT 0 NOT NULL,
	"failed_count" integer DEFAULT 0 NOT NULL,
	"composite_score" integer DEFAULT 0 NOT NULL,
	"grade" varchar(4) DEFAULT 'F' NOT NULL,
	"go_no_go" varchar(8) DEFAULT 'NO-GO' NOT NULL,
	"pillars_json" jsonb DEFAULT '[]' NOT NULL,
	"errors_json" jsonb DEFAULT '[]' NOT NULL,
	"ran_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "pilot_smoke_runs_run_ref_key" UNIQUE("run_ref")
);
--> statement-breakpoint
CREATE TABLE "adversarial_example_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"run_ref" varchar(64) NOT NULL,
	"model_ref" varchar(96) DEFAULT 'kyt-v1' NOT NULL,
	"attack_kind" varchar(32) NOT NULL,
	"samples" integer DEFAULT 0 NOT NULL,
	"successful_attacks" integer DEFAULT 0 NOT NULL,
	"robust_accuracy_pct" real DEFAULT 0 NOT NULL,
	"clean_accuracy_pct" real DEFAULT 0 NOT NULL,
	"mean_perturbation_l2" real DEFAULT 0 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"triggered_by" varchar(128) NOT NULL,
	"triggered_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "adversarial_example_runs_run_ref_key" UNIQUE("run_ref")
);
--> statement-breakpoint
CREATE TABLE "breakglass_drills" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" varchar(64) NOT NULL,
	"primary_officer" varchar(128) NOT NULL,
	"approver_officer" varchar(128) NOT NULL,
	"reason" varchar(255) NOT NULL,
	"ticket_ref" varchar(64) NOT NULL,
	"granted_at" timestamp with time zone NOT NULL,
	"expires_at" timestamp with time zone NOT NULL,
	"auto_expired" integer DEFAULT 0 NOT NULL,
	"alert_sent" integer DEFAULT 0 NOT NULL,
	"dual_control_ok" integer DEFAULT 0 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"triggered_by" varchar(128) NOT NULL,
	"triggered_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "breakglass_drills_drill_ref_key" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "consent_events" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"event_ref" varchar(64) NOT NULL,
	"customer_ref" varchar(128) NOT NULL,
	"purpose" varchar(96) NOT NULL,
	"scope" varchar(192) NOT NULL,
	"action" varchar(32) NOT NULL,
	"channel" varchar(32) DEFAULT 'portal' NOT NULL,
	"evidence_hash" varchar(128) NOT NULL,
	"ip_address" varchar(64),
	"captured_by" varchar(128) NOT NULL,
	"captured_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "consent_events_event_ref_key" UNIQUE("event_ref")
);
--> statement-breakpoint
CREATE TABLE "db_failover_drills" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" varchar(64) NOT NULL,
	"primary_region" varchar(32) DEFAULT 'UG-CENTRAL' NOT NULL,
	"failover_region" varchar(32) DEFAULT 'UG-EAST' NOT NULL,
	"rto_seconds" integer DEFAULT 0 NOT NULL,
	"rpo_seconds" integer DEFAULT 0 NOT NULL,
	"rto_target_seconds" integer DEFAULT 60 NOT NULL,
	"rpo_target_seconds" integer DEFAULT 5 NOT NULL,
	"inflight_txns_lost" integer DEFAULT 0 NOT NULL,
	"inflight_txns_replayed" integer DEFAULT 0 NOT NULL,
	"receipt_hash" varchar(128) NOT NULL,
	"signature_hex" varchar(256) NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" jsonb DEFAULT '{}'::jsonb NOT NULL,
	"triggered_by" varchar(128) NOT NULL,
	"triggered_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "db_failover_drills_drill_ref_key" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "eol_feed_cache" (
	"component_key" varchar(96) PRIMARY KEY NOT NULL,
	"eol_date" varchar(32),
	"upstream_signal" varchar(32) NOT NULL,
	"source" varchar(32) NOT NULL,
	"fetched_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "eol_inventory_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"run_ref" varchar(64) NOT NULL,
	"components_scanned" integer DEFAULT 0 NOT NULL,
	"eol_count" integer DEFAULT 0 NOT NULL,
	"near_eol_count" integer DEFAULT 0 NOT NULL,
	"unknown_count" integer DEFAULT 0 NOT NULL,
	"worst_eol_days_overdue" integer DEFAULT 0 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"triggered_by" varchar(128) NOT NULL,
	"triggered_at" timestamp with time zone DEFAULT now() NOT NULL,
	"feed_status" varchar(32) DEFAULT 'fresh' NOT NULL,
	"no_eol_announced_count" integer DEFAULT 0 NOT NULL,
	"not_covered_count" integer DEFAULT 0 NOT NULL,
	"current_count" integer DEFAULT 0 NOT NULL,
	CONSTRAINT "eol_inventory_runs_run_ref_key" UNIQUE("run_ref")
);
--> statement-breakpoint
CREATE TABLE "erasure_drills" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" varchar(64) NOT NULL,
	"customer_ref" varchar(128) NOT NULL,
	"scopes_attempted" integer DEFAULT 0 NOT NULL,
	"scopes_purged" integer DEFAULT 0 NOT NULL,
	"scopes_failed" integer DEFAULT 0 NOT NULL,
	"primary_purged" integer DEFAULT 0 NOT NULL,
	"replica_purged" integer DEFAULT 0 NOT NULL,
	"backup_purged" integer DEFAULT 0 NOT NULL,
	"archive_purged" integer DEFAULT 0 NOT NULL,
	"logs_redacted" integer DEFAULT 0 NOT NULL,
	"receipt_hash" varchar(128) NOT NULL,
	"signature_hex" varchar(256) NOT NULL,
	"duration_ms" integer DEFAULT 0 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"triggered_by" varchar(128) NOT NULL,
	"triggered_at" timestamp with time zone DEFAULT now() NOT NULL,
	"tables_scanned" integer DEFAULT 0 NOT NULL,
	"real_rows_erased" integer DEFAULT 0 NOT NULL,
	"legally_retained_rows" integer DEFAULT 0 NOT NULL,
	"cache_invalidation_status" varchar(96) DEFAULT '' NOT NULL,
	"cache_invalidation_verified_at" timestamp with time zone DEFAULT now() NOT NULL,
	"prior_erasure_found" integer DEFAULT 0 NOT NULL,
	CONSTRAINT "erasure_drills_drill_ref_key" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "ir_drill_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" varchar(64) NOT NULL,
	"scenario" varchar(96) NOT NULL,
	"phases_completed" integer DEFAULT 0 NOT NULL,
	"detect_ms" integer DEFAULT 0 NOT NULL,
	"contain_ms" integer DEFAULT 0 NOT NULL,
	"eradicate_ms" integer DEFAULT 0 NOT NULL,
	"recover_ms" integer DEFAULT 0 NOT NULL,
	"pir_ms" integer DEFAULT 0 NOT NULL,
	"total_ms" integer DEFAULT 0 NOT NULL,
	"pir_artifact_hash" varchar(128) NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"incident_ref" varchar(64),
	"per_phase_errors" jsonb DEFAULT '[]' NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"triggered_by" varchar(128) NOT NULL,
	"triggered_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "ir_drill_runs_drill_ref_key" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "model_card_audits" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"audit_ref" varchar(64) NOT NULL,
	"model_ref" varchar(96) NOT NULL,
	"model_version" varchar(32) DEFAULT 'v1' NOT NULL,
	"segments_evaluated" integer DEFAULT 0 NOT NULL,
	"max_disparity_ratio" real DEFAULT 1 NOT NULL,
	"demographic_parity_pct" real DEFAULT 0 NOT NULL,
	"equal_opportunity_pct" real DEFAULT 0 NOT NULL,
	"model_card_hash" varchar(128) NOT NULL,
	"signature_hex" varchar(256) NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"triggered_by" varchar(128) NOT NULL,
	"triggered_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "model_card_audits_audit_ref_key" UNIQUE("audit_ref")
);
--> statement-breakpoint
CREATE TABLE "mttr_records" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"record_ref" varchar(64) NOT NULL,
	"threat_class" varchar(64) NOT NULL,
	"occurred_at" timestamp with time zone NOT NULL,
	"detected_at" timestamp with time zone NOT NULL,
	"contained_at" timestamp with time zone NOT NULL,
	"recovered_at" timestamp with time zone,
	"mttd_seconds" integer DEFAULT 0 NOT NULL,
	"mttr_seconds" integer DEFAULT 0 NOT NULL,
	"severity" varchar(16) DEFAULT 'medium' NOT NULL,
	"notes" text,
	"recorded_by" varchar(128) NOT NULL,
	"recorded_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "mttr_records_record_ref_key" UNIQUE("record_ref")
);
--> statement-breakpoint
CREATE TABLE "network_partition_drills" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" varchar(64) NOT NULL,
	"partition_type" varchar(32) DEFAULT 'split-brain' NOT NULL,
	"affected_zones" integer DEFAULT 0 NOT NULL,
	"total_zones" integer DEFAULT 0 NOT NULL,
	"quorum_maintained" integer DEFAULT 0 NOT NULL,
	"detect_ms" integer DEFAULT 0 NOT NULL,
	"recover_ms" integer DEFAULT 0 NOT NULL,
	"stale_reads_blocked" integer DEFAULT 0 NOT NULL,
	"receipt_hash" varchar(128) NOT NULL,
	"signature_hex" varchar(256) NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" jsonb DEFAULT '{}'::jsonb NOT NULL,
	"triggered_by" varchar(128) NOT NULL,
	"triggered_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "network_partition_drills_drill_ref_key" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "queue_backpressure_drills" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" varchar(64) NOT NULL,
	"queue_name" varchar(96) DEFAULT 'threat-events' NOT NULL,
	"injected_rate_per_sec" integer DEFAULT 0 NOT NULL,
	"consumer_rate_per_sec" integer DEFAULT 0 NOT NULL,
	"peak_depth" integer DEFAULT 0 NOT NULL,
	"shed_count" integer DEFAULT 0 NOT NULL,
	"deadletter_count" integer DEFAULT 0 NOT NULL,
	"duration_ms" integer DEFAULT 0 NOT NULL,
	"receipt_hash" varchar(128) NOT NULL,
	"signature_hex" varchar(256) NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" jsonb DEFAULT '{}'::jsonb NOT NULL,
	"triggered_by" varchar(128) NOT NULL,
	"triggered_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "queue_backpressure_drills_drill_ref_key" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "sanctions_screening_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"run_ref" varchar(64) NOT NULL,
	"lists_checked" integer DEFAULT 0 NOT NULL,
	"stale_lists_count" integer DEFAULT 0 NOT NULL,
	"stale_lists_threshold_hrs" integer DEFAULT 24 NOT NULL,
	"sample_size" integer DEFAULT 0 NOT NULL,
	"p50_ms" integer DEFAULT 0 NOT NULL,
	"p95_ms" integer DEFAULT 0 NOT NULL,
	"p99_ms" integer DEFAULT 0 NOT NULL,
	"hits_count" integer DEFAULT 0 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"triggered_by" varchar(128) NOT NULL,
	"triggered_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "sanctions_screening_runs_run_ref_key" UNIQUE("run_ref")
);
--> statement-breakpoint
CREATE TABLE "sbom_attestations" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"attestation_ref" varchar(64) NOT NULL,
	"build_ref" varchar(96) NOT NULL,
	"component_count" integer DEFAULT 0 NOT NULL,
	"slsa_level" integer DEFAULT 0 NOT NULL,
	"builder_id" varchar(192) NOT NULL,
	"source_uri" varchar(255) NOT NULL,
	"source_digest" varchar(128) NOT NULL,
	"sbom_hash" varchar(128) NOT NULL,
	"signature_hex" varchar(256) NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"generated_by" varchar(128) NOT NULL,
	"generated_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "sbom_attestations_attestation_ref_key" UNIQUE("attestation_ref")
);
--> statement-breakpoint
CREATE TABLE "segmentation_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"run_ref" varchar(64) NOT NULL,
	"pairs_tested" integer DEFAULT 0 NOT NULL,
	"expected_reachable" integer DEFAULT 0 NOT NULL,
	"expected_blocked" integer DEFAULT 0 NOT NULL,
	"unexpected_reachable" integer DEFAULT 0 NOT NULL,
	"unexpected_blocked" integer DEFAULT 0 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"triggered_by" varchar(128) NOT NULL,
	"triggered_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "segmentation_runs_run_ref_key" UNIQUE("run_ref")
);
--> statement-breakpoint
CREATE TABLE "sod_rules" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"rule_key" varchar(96) NOT NULL,
	"description" varchar(255) NOT NULL,
	"forbidden_pair" jsonb NOT NULL,
	"severity" varchar(16) DEFAULT 'high' NOT NULL,
	"enabled" integer DEFAULT 1 NOT NULL,
	"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "sod_rules_rule_key_key" UNIQUE("rule_key")
);
--> statement-breakpoint
CREATE TABLE "sod_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"run_ref" varchar(64) NOT NULL,
	"rules_evaluated" integer DEFAULT 0 NOT NULL,
	"users_scanned" integer DEFAULT 0 NOT NULL,
	"violations_found" integer DEFAULT 0 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" jsonb DEFAULT '{}' NOT NULL,
	"triggered_by" varchar(128) NOT NULL,
	"triggered_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "sod_runs_run_ref_key" UNIQUE("run_ref")
);
--> statement-breakpoint
CREATE TABLE "vendor_attestations" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"attestation_ref" varchar(64) NOT NULL,
	"vendor_ref" varchar(64) NOT NULL,
	"attestation_type" varchar(64) NOT NULL,
	"valid_from" timestamp with time zone NOT NULL,
	"valid_until" timestamp with time zone NOT NULL,
	"evidence_hash" varchar(128) NOT NULL,
	"signature_hex" varchar(256) NOT NULL,
	"attester_ref" varchar(128) NOT NULL,
	"uploaded_by" varchar(128) NOT NULL,
	"uploaded_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "vendor_attestations_attestation_ref_key" UNIQUE("attestation_ref")
);
--> statement-breakpoint
CREATE TABLE "vendor_register" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"vendor_ref" varchar(64) NOT NULL,
	"vendor_name" varchar(192) NOT NULL,
	"service_category" varchar(64) NOT NULL,
	"criticality" varchar(16) DEFAULT 'medium' NOT NULL,
	"country" varchar(64) DEFAULT 'UG' NOT NULL,
	"contract_start" timestamp with time zone,
	"contract_end" timestamp with time zone,
	"exit_clause_documented" integer DEFAULT 0 NOT NULL,
	"active" integer DEFAULT 1 NOT NULL,
	"registered_by" varchar(128) NOT NULL,
	"registered_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "vendor_register_vendor_ref_key" UNIQUE("vendor_ref")
);
--> statement-breakpoint
CREATE TABLE "wave13_expected_findings" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"module_name" varchar(64) NOT NULL,
	"rationale" text NOT NULL,
	"rationale_pointer" varchar(64) NOT NULL,
	"bou_narrative_ref" varchar(128),
	"acknowledged_by" varchar(128) NOT NULL,
	"acknowledged_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "wave13_expected_findings_module_name_key" UNIQUE("module_name")
);
--> statement-breakpoint
CREATE TABLE "wave13_smoke_runs" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"smoke_ref" varchar(64) NOT NULL,
	"modules_attempted" integer DEFAULT 0 NOT NULL,
	"modules_passed" integer DEFAULT 0 NOT NULL,
	"modules_failed" integer DEFAULT 0 NOT NULL,
	"modules_errored" integer DEFAULT 0 NOT NULL,
	"duration_ms" integer DEFAULT 0 NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"bundle_hash" varchar(128) NOT NULL,
	"signature_hex" varchar(256) NOT NULL,
	"details_json" jsonb DEFAULT '{}'::jsonb NOT NULL,
	"signed_payload" text,
	"triggered_by" varchar(128) NOT NULL,
	"triggered_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "wave13_smoke_runs_smoke_ref_key" UNIQUE("smoke_ref")
);
--> statement-breakpoint
CREATE TABLE "xborder_transfers" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"transfer_ref" varchar(64) NOT NULL,
	"source_region" varchar(64) DEFAULT 'UG' NOT NULL,
	"dest_region" varchar(64) NOT NULL,
	"dest_vendor" varchar(192) NOT NULL,
	"data_category" varchar(64) NOT NULL,
	"bytes_transferred" integer DEFAULT 0 NOT NULL,
	"record_count" integer DEFAULT 0 NOT NULL,
	"legal_basis" varchar(64) NOT NULL,
	"approval_ref" varchar(96),
	"approved_by" varchar(128),
	"notes" text,
	"logged_by" varchar(128) NOT NULL,
	"logged_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "xborder_transfers_transfer_ref_key" UNIQUE("transfer_ref")
);
--> statement-breakpoint
CREATE TABLE "audit_tamper_drills" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" varchar(64) NOT NULL,
	"rows_scanned" integer DEFAULT 0 NOT NULL,
	"live_chain_valid" integer DEFAULT 0 NOT NULL,
	"live_broken_at" integer,
	"tamper_detected" integer DEFAULT 0 NOT NULL,
	"duration_ms" integer DEFAULT 0 NOT NULL,
	"receipt_hash" varchar(128) NOT NULL,
	"signature_hex" varchar(256) NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" jsonb DEFAULT '{}'::jsonb NOT NULL,
	"triggered_by" varchar(128) NOT NULL,
	"triggered_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "audit_tamper_drills_drill_ref_key" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "bundle_verifications" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"verify_ref" varchar(64) NOT NULL,
	"payload_sha256" varchar(128) NOT NULL,
	"provided_sig" varchar(256) NOT NULL,
	"expected_sig" varchar(256) NOT NULL,
	"valid" integer DEFAULT 0 NOT NULL,
	"payload_bytes" integer DEFAULT 0 NOT NULL,
	"ip_hash" varchar(128),
	"user_agent" text,
	"verified_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "bundle_verifications_verify_ref_key" UNIQUE("verify_ref")
);
--> statement-breakpoint
CREATE TABLE "degradation_drills" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" varchar(64) NOT NULL,
	"scenarios_run" integer DEFAULT 0 NOT NULL,
	"scenarios_passed" integer DEFAULT 0 NOT NULL,
	"stale_sanctions_passed" integer DEFAULT 0 NOT NULL,
	"ai_down_passed" integer DEFAULT 0 NOT NULL,
	"db_readonly_passed" integer DEFAULT 0 NOT NULL,
	"duration_ms" integer DEFAULT 0 NOT NULL,
	"receipt_hash" varchar(128) NOT NULL,
	"signature_hex" varchar(256) NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" jsonb DEFAULT '{}'::jsonb NOT NULL,
	"triggered_by" varchar(128) NOT NULL,
	"triggered_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "degradation_drills_drill_ref_key" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "tenant_isolation_drills" (
	"id" varchar PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"drill_ref" varchar(64) NOT NULL,
	"tenants_tested" integer DEFAULT 0 NOT NULL,
	"endpoints_tested" integer DEFAULT 0 NOT NULL,
	"probes_run" integer DEFAULT 0 NOT NULL,
	"leaks_found" integer DEFAULT 0 NOT NULL,
	"duration_ms" integer DEFAULT 0 NOT NULL,
	"receipt_hash" varchar(128) NOT NULL,
	"signature_hex" varchar(256) NOT NULL,
	"passed" integer DEFAULT 0 NOT NULL,
	"details_json" jsonb DEFAULT '{}'::jsonb NOT NULL,
	"triggered_by" varchar(128) NOT NULL,
	"triggered_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "tenant_isolation_drills_drill_ref_key" UNIQUE("drill_ref")
);
--> statement-breakpoint
CREATE TABLE "backup_restore_tierb_drills" (
	"id" serial PRIMARY KEY NOT NULL,
	"drill_ref" text NOT NULL,
	"scratch_schema" text NOT NULL,
	"tables_checked" integer NOT NULL,
	"rows_before" integer NOT NULL,
	"rows_after" integer NOT NULL,
	"row_mismatch_count" integer NOT NULL,
	"per_table_json" jsonb,
	"duration_ms" integer NOT NULL,
	"receipt_hash" text NOT NULL,
	"signature_hex" text NOT NULL,
	"passed" integer NOT NULL,
	"details_json" jsonb,
	"triggered_by" text NOT NULL,
	"triggered_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "key_rotation_tierb_drills" (
	"id" serial PRIMARY KEY NOT NULL,
	"drill_ref" text NOT NULL,
	"old_key_fingerprint" text NOT NULL,
	"new_key_fingerprint" text NOT NULL,
	"old_key_still_verifies" integer NOT NULL,
	"new_key_signs_and_verifies" integer NOT NULL,
	"cross_key_forge_blocked" integer NOT NULL,
	"duration_ms" integer NOT NULL,
	"receipt_hash" text NOT NULL,
	"signature_hex" text NOT NULL,
	"passed" integer NOT NULL,
	"details_json" jsonb,
	"triggered_by" text NOT NULL,
	"triggered_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "pii_egress_drills" (
	"id" serial PRIMARY KEY NOT NULL,
	"drill_ref" text NOT NULL,
	"canaries_planted" integer NOT NULL,
	"channels_scanned" integer NOT NULL,
	"leaks_found" integer NOT NULL,
	"per_channel_json" jsonb,
	"duration_ms" integer NOT NULL,
	"receipt_hash" text NOT NULL,
	"signature_hex" text NOT NULL,
	"passed" integer NOT NULL,
	"details_json" jsonb,
	"triggered_by" text NOT NULL,
	"triggered_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "rate_limit_drills" (
	"id" serial PRIMARY KEY NOT NULL,
	"drill_ref" text NOT NULL,
	"endpoint" text NOT NULL,
	"requests_sent" integer NOT NULL,
	"successes" integer NOT NULL,
	"rate_limited" integer NOT NULL,
	"errors" integer NOT NULL,
	"rate_limit_engaged_at" integer,
	"duration_ms" integer NOT NULL,
	"receipt_hash" text NOT NULL,
	"signature_hex" text NOT NULL,
	"passed" integer NOT NULL,
	"details_json" jsonb,
	"triggered_by" text NOT NULL,
	"triggered_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "reproducibility_drills" (
	"id" serial PRIMARY KEY NOT NULL,
	"drill_ref" text NOT NULL,
	"iterations" integer NOT NULL,
	"unique_scores" integer NOT NULL,
	"scores_json" jsonb,
	"fixture_ref" text NOT NULL,
	"duration_ms" integer NOT NULL,
	"receipt_hash" text NOT NULL,
	"signature_hex" text NOT NULL,
	"passed" integer NOT NULL,
	"details_json" jsonb,
	"triggered_by" text NOT NULL,
	"triggered_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "time_sync_drills" (
	"id" serial PRIMARY KEY NOT NULL,
	"drill_ref" text NOT NULL,
	"source" text NOT NULL,
	"drift_ms" integer NOT NULL,
	"threshold_ms" integer NOT NULL,
	"authoritative_iso" text,
	"local_iso" text,
	"duration_ms" integer NOT NULL,
	"receipt_hash" text NOT NULL,
	"signature_hex" text NOT NULL,
	"passed" integer NOT NULL,
	"details_json" jsonb,
	"triggered_by" text NOT NULL,
	"triggered_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "decision_scoring_outputs" (
	"id" serial PRIMARY KEY NOT NULL,
	"tenant_id" text NOT NULL,
	"decision_id" text NOT NULL,
	"scoring_path" text NOT NULL,
	"model_identifier" text NOT NULL,
	"risk_score" integer NOT NULL,
	"confidence" real,
	"reasoning_text" text NOT NULL,
	"factors_json" text NOT NULL,
	"audit_chain_entry_id" integer,
	"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "active_sessions" ADD CONSTRAINT "active_sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "ai_threat_scores" ADD CONSTRAINT "ai_threat_scores_threat_event_id_threat_events_id_fk" FOREIGN KEY ("threat_event_id") REFERENCES "public"."threat_events"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "ai_thresholds" ADD CONSTRAINT "ai_thresholds_updated_by_users_id_fk" FOREIGN KEY ("updated_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "api_keys" ADD CONSTRAINT "api_keys_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "audit_logs" ADD CONSTRAINT "audit_logs_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "backup_records" ADD CONSTRAINT "backup_records_initiated_by_users_id_fk" FOREIGN KEY ("initiated_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "change_approvals" ADD CONSTRAINT "change_approvals_change_request_id_change_requests_id_fk" FOREIGN KEY ("change_request_id") REFERENCES "public"."change_requests"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "compliance_check_results" ADD CONSTRAINT "ccres_run_fk" FOREIGN KEY ("tenant_id","run_id") REFERENCES "public"."compliance_check_runs"("tenant_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "compliance_reports" ADD CONSTRAINT "compliance_reports_generated_by_users_id_fk" FOREIGN KEY ("generated_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "export_jobs" ADD CONSTRAINT "export_jobs_requested_by_users_id_fk" FOREIGN KEY ("requested_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "geo_violations" ADD CONSTRAINT "geo_violations_policy_id_geo_policies_id_fk" FOREIGN KEY ("policy_id") REFERENCES "public"."geo_policies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "ip_policies" ADD CONSTRAINT "ip_policies_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "messages" ADD CONSTRAINT "messages_conversation_id_conversations_id_fk" FOREIGN KEY ("conversation_id") REFERENCES "public"."conversations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "rate_limit_events" ADD CONSTRAINT "rate_limit_events_policy_id_rate_limit_policies_id_fk" FOREIGN KEY ("policy_id") REFERENCES "public"."rate_limit_policies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "threat_events" ADD CONSTRAINT "threat_events_neutralized_by_users_id_fk" FOREIGN KEY ("neutralized_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "vulnerability_findings" ADD CONSTRAINT "vulnerability_findings_component_id_sbom_components_id_fk" FOREIGN KEY ("component_id") REFERENCES "public"."sbom_components"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "webhook_configs" ADD CONSTRAINT "webhook_configs_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "webhook_logs" ADD CONSTRAINT "webhook_logs_webhook_id_webhook_configs_id_fk" FOREIGN KEY ("webhook_id") REFERENCES "public"."webhook_configs"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "fincrime_case_events" ADD CONSTRAINT "fce_case_id_fk" FOREIGN KEY ("tenant_id","case_id") REFERENCES "public"."fincrime_cases"("tenant_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "fincrime_case_evidence" ADD CONSTRAINT "fcev_case_fk" FOREIGN KEY ("tenant_id","case_id") REFERENCES "public"."fincrime_cases"("tenant_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "fincrime_str_approvals" ADD CONSTRAINT "fsa_report_fk" FOREIGN KEY ("tenant_id","str_report_id") REFERENCES "public"."fincrime_str_reports"("tenant_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "fincrime_str_reports" ADD CONSTRAINT "fsr_case_fk" FOREIGN KEY ("tenant_id","case_id") REFERENCES "public"."fincrime_cases"("tenant_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "kyc_decision_approvals" ADD CONSTRAINT "kda_decision_id_fk" FOREIGN KEY ("decision_id") REFERENCES "public"."kyc_decision_outcomes"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "api_usage_metrics_created_at_idx" ON "api_usage_metrics" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX "audit_logs_timestamp_idx" ON "audit_logs" USING btree ("timestamp");--> statement-breakpoint
CREATE INDEX "cicd_pipeline_runs_executed_at_idx" ON "cicd_pipeline_runs" USING btree ("executed_at");--> statement-breakpoint
CREATE INDEX "cicd_pipeline_runs_pipeline_id_idx" ON "cicd_pipeline_runs" USING btree ("pipeline_id");--> statement-breakpoint
CREATE INDEX "ccres_tenant_run_idx" ON "compliance_check_results" USING btree ("tenant_id","run_id");--> statement-breakpoint
CREATE INDEX "report_executions_executed_at_idx" ON "report_executions" USING btree ("executed_at");--> statement-breakpoint
CREATE INDEX "report_executions_schedule_id_idx" ON "report_executions" USING btree ("schedule_id");--> statement-breakpoint
CREATE INDEX "threat_events_timestamp_idx" ON "threat_events" USING btree ("timestamp");--> statement-breakpoint
CREATE INDEX "fce_tenant_case_created_idx" ON "fincrime_case_events" USING btree ("tenant_id","case_id","created_at");--> statement-breakpoint
CREATE INDEX "fcev_tenant_case_idx" ON "fincrime_case_evidence" USING btree ("tenant_id","case_id","created_at");--> statement-breakpoint
CREATE INDEX "fcc_tenant_opened_idx" ON "fincrime_cases" USING btree ("tenant_id","opened_at" DESC NULLS FIRST);--> statement-breakpoint
CREATE INDEX "fcc_tenant_source_idx" ON "fincrime_cases" USING btree ("tenant_id","source_type","source_ref");--> statement-breakpoint
CREATE INDEX "fcc_tenant_state_updated_idx" ON "fincrime_cases" USING btree ("tenant_id","state","updated_at" DESC NULLS FIRST);--> statement-breakpoint
CREATE UNIQUE INDEX "fsa_tenant_report_uniq" ON "fincrime_str_approvals" USING btree ("tenant_id","str_report_id");--> statement-breakpoint
CREATE INDEX "fsr_tenant_case_idx" ON "fincrime_str_reports" USING btree ("tenant_id","case_id");--> statement-breakpoint
CREATE INDEX "fsr_tenant_retention_idx" ON "fincrime_str_reports" USING btree ("tenant_id","retention_until");--> statement-breakpoint
CREATE INDEX "fsr_tenant_status_updated_idx" ON "fincrime_str_reports" USING btree ("tenant_id","status","updated_at" DESC NULLS FIRST);--> statement-breakpoint
CREATE UNIQUE INDEX "kyc_national_id_hmac_unique" ON "kyc_customers" USING btree ("national_id_hmac");--> statement-breakpoint
CREATE UNIQUE INDEX "kda_tenant_decision_unique" ON "kyc_decision_approvals" USING btree ("tenant_id","decision_id");--> statement-breakpoint
CREATE INDEX "dsar_purge_jobs_status_idx" ON "dsar_purge_jobs" USING btree ("status");--> statement-breakpoint
CREATE INDEX "dsar_purge_jobs_enqueued_at_idx" ON "dsar_purge_jobs" USING btree ("enqueued_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "dsar_purge_jobs_dsar_id_idx" ON "dsar_purge_jobs" USING btree ("dsar_id");--> statement-breakpoint
CREATE INDEX "dsar_purge_jobs_drill_ref_idx" ON "dsar_purge_jobs" USING btree ("drill_ref") WHERE drill_ref IS NOT NULL;--> statement-breakpoint
CREATE UNIQUE INDEX "dsar_purge_jobs_in_flight_unique_idx" ON "dsar_purge_jobs" USING btree ("dsar_id") WHERE status IN ('pending', 'running');--> statement-breakpoint
CREATE INDEX "load_test_runs_scenario_err_started_idx" ON "load_test_runs" USING btree ("scenario","error_count","started_at" DESC NULLS LAST);--> statement-breakpoint
CREATE UNIQUE INDEX "utr_primary_per_user" ON "user_tenant_roles" USING btree ("user_id") WHERE is_active = true AND is_primary = true;--> statement-breakpoint
CREATE INDEX "ubo_registrations_erasure_state_idx" ON "ubo_registrations" USING btree ("erasure_state","registered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE UNIQUE INDEX "ubo_owner_national_id_hmac_unique" ON "ubo_registrations" USING btree ("owner_national_id_hmac");--> statement-breakpoint
CREATE INDEX "canary_runs_ran_at_idx" ON "canary_runs" USING btree ("ran_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "dr_drill_results_ran_at_idx" ON "dr_drill_results" USING btree ("ran_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "forensic_bundles_threat_event_idx" ON "forensic_bundles" USING btree ("threat_event_id");--> statement-breakpoint
CREATE INDEX "forensic_bundles_generated_at_idx" ON "forensic_bundles" USING btree ("generated_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "pdpo_breach_drills_ran_at_idx" ON "pdpo_breach_drills" USING btree ("ran_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "prompt_injection_runs_ran_at_idx" ON "prompt_injection_runs" USING btree ("ran_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "residency_attestations_period_idx" ON "residency_attestations" USING btree ("period_month");--> statement-breakpoint
CREATE INDEX "residency_attestations_generated_at_idx" ON "residency_attestations" USING btree ("generated_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "sla_breaches_detected_at_idx" ON "sla_breaches" USING btree ("detected_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "sla_breaches_metric_key_idx" ON "sla_breaches" USING btree ("metric_key");--> statement-breakpoint
CREATE INDEX "traffic_shadow_captures_captured_at_idx" ON "traffic_shadow_captures" USING btree ("captured_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "traffic_shadow_replays_ran_at_idx" ON "traffic_shadow_replays" USING btree ("ran_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "pilot_master_scores_generated_at_idx" ON "pilot_master_scores" USING btree ("generated_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "pilot_smoke_runs_ran_at_idx" ON "pilot_smoke_runs" USING btree ("ran_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "adversarial_example_runs_triggered_at_idx" ON "adversarial_example_runs" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "breakglass_drills_triggered_at_idx" ON "breakglass_drills" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "consent_events_customer_idx" ON "consent_events" USING btree ("customer_ref");--> statement-breakpoint
CREATE INDEX "consent_events_captured_at_idx" ON "consent_events" USING btree ("captured_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "db_failover_drills_triggered_at_idx" ON "db_failover_drills" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "eol_feed_cache_fetched_at_idx" ON "eol_feed_cache" USING btree ("fetched_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "eol_inventory_runs_triggered_at_idx" ON "eol_inventory_runs" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "erasure_drills_triggered_at_idx" ON "erasure_drills" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "ir_drill_runs_triggered_at_idx" ON "ir_drill_runs" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "model_card_audits_triggered_at_idx" ON "model_card_audits" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "mttr_records_recorded_at_idx" ON "mttr_records" USING btree ("recorded_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "mttr_records_threat_class_idx" ON "mttr_records" USING btree ("threat_class");--> statement-breakpoint
CREATE INDEX "network_partition_drills_triggered_at_idx" ON "network_partition_drills" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "queue_backpressure_drills_triggered_at_idx" ON "queue_backpressure_drills" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "sanctions_screening_triggered_at_idx" ON "sanctions_screening_runs" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "sbom_attestations_generated_at_idx" ON "sbom_attestations" USING btree ("generated_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "segmentation_runs_triggered_at_idx" ON "segmentation_runs" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "sod_runs_triggered_at_idx" ON "sod_runs" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "vendor_attestations_vendor_idx" ON "vendor_attestations" USING btree ("vendor_ref");--> statement-breakpoint
CREATE INDEX "vendor_attestations_uploaded_at_idx" ON "vendor_attestations" USING btree ("uploaded_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "vendor_register_registered_at_idx" ON "vendor_register" USING btree ("registered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "vendor_register_vendor_name_idx" ON "vendor_register" USING btree ("vendor_name");--> statement-breakpoint
CREATE INDEX "wave13_expected_findings_module_name_idx" ON "wave13_expected_findings" USING btree ("module_name");--> statement-breakpoint
CREATE INDEX "wave13_smoke_runs_triggered_at_idx" ON "wave13_smoke_runs" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "xborder_transfers_logged_at_idx" ON "xborder_transfers" USING btree ("logged_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "xborder_transfers_dest_region_idx" ON "xborder_transfers" USING btree ("dest_region");--> statement-breakpoint
CREATE INDEX "audit_tamper_drills_triggered_at_idx" ON "audit_tamper_drills" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "bundle_verifications_verified_at_idx" ON "bundle_verifications" USING btree ("verified_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "degradation_drills_triggered_at_idx" ON "degradation_drills" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "tenant_isolation_drills_triggered_at_idx" ON "tenant_isolation_drills" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "backup_restore_tierb_drills_at_desc_idx" ON "backup_restore_tierb_drills" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "key_rotation_tierb_drills_at_desc_idx" ON "key_rotation_tierb_drills" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "pii_egress_drills_at_desc_idx" ON "pii_egress_drills" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "rate_limit_drills_at_desc_idx" ON "rate_limit_drills" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "reproducibility_drills_at_desc_idx" ON "reproducibility_drills" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "time_sync_drills_at_desc_idx" ON "time_sync_drills" USING btree ("triggered_at" DESC NULLS LAST);--> statement-breakpoint
CREATE UNIQUE INDEX "dso_tenant_decision_unique" ON "decision_scoring_outputs" USING btree ("tenant_id","decision_id");