/*
  Warnings:

  - You are about to drop the column `triggered_by` on the `personas` table. All the data in the column will be lost.
  - Added the required column `source` to the `personas` table without a default value. This is not possible if the table is not empty.

*/
-- DropForeignKey
ALTER TABLE "patient_profiles" DROP CONSTRAINT "patient_profiles_patient_id_fkey";

-- DropForeignKey
ALTER TABLE "plan_reasons" DROP CONSTRAINT "plan_reasons_plan_id_fkey";

-- DropIndex
DROP INDEX "patient_facts_transaction_ids_gin";

-- DropIndex
DROP INDEX "plan_reasons_evidence_gin_idx";

-- AlterTable
ALTER TABLE "hosts" RENAME CONSTRAINT "platforms_pkey" TO "hosts_pkey";

-- AlterTable
ALTER TABLE "personas" DROP COLUMN "triggered_by",
ADD COLUMN     "source" TEXT NOT NULL;

-- AlterTable
ALTER TABLE "plan_reasons" ALTER COLUMN "id" DROP DEFAULT,
ALTER COLUMN "evidence_fact_ids" DROP DEFAULT;

-- RenameForeignKey
ALTER TABLE "agent_invocations" RENAME CONSTRAINT "agent_invocations_platform_id_fkey" TO "agent_invocations_host_id_fkey";

-- RenameForeignKey
ALTER TABLE "followup_plans" RENAME CONSTRAINT "followup_plans_platform_id_fkey" TO "followup_plans_host_id_fkey";

-- RenameForeignKey
ALTER TABLE "patient_facts" RENAME CONSTRAINT "patient_facts_platform_id_fkey" TO "patient_facts_host_id_fkey";

-- RenameForeignKey
ALTER TABLE "patient_transactions" RENAME CONSTRAINT "patient_transactions_platform_id_fkey" TO "patient_transactions_host_id_fkey";

-- RenameForeignKey
ALTER TABLE "patients" RENAME CONSTRAINT "patients_platform_id_fkey" TO "patients_host_id_fkey";

-- RenameForeignKey
ALTER TABLE "persona_recompute_logs" RENAME CONSTRAINT "persona_recompute_logs_platform_id_fkey" TO "persona_recompute_logs_host_id_fkey";

-- RenameForeignKey
ALTER TABLE "personas" RENAME CONSTRAINT "personas_platform_id_fkey" TO "personas_host_id_fkey";

-- RenameForeignKey
ALTER TABLE "plan_executions" RENAME CONSTRAINT "plan_executions_platform_id_fkey" TO "plan_executions_host_id_fkey";

-- RenameForeignKey
ALTER TABLE "plan_generation_logs" RENAME CONSTRAINT "plan_generation_logs_platform_id_fkey" TO "plan_generation_logs_host_id_fkey";

-- RenameForeignKey
ALTER TABLE "plan_scripts" RENAME CONSTRAINT "plan_scripts_platform_id_fkey" TO "plan_scripts_host_id_fkey";

-- RenameForeignKey
ALTER TABLE "plan_summaries" RENAME CONSTRAINT "plan_summaries_platform_id_fkey" TO "plan_summaries_host_id_fkey";

-- RenameForeignKey
ALTER TABLE "sync_logs" RENAME CONSTRAINT "sync_logs_platform_id_fkey" TO "sync_logs_host_id_fkey";

-- AddForeignKey
ALTER TABLE "patient_profiles" ADD CONSTRAINT "patient_profiles_patient_id_fkey" FOREIGN KEY ("patient_id") REFERENCES "patients"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "plan_reasons" ADD CONSTRAINT "plan_reasons_plan_id_fkey" FOREIGN KEY ("plan_id") REFERENCES "followup_plans"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- RenameIndex
ALTER INDEX "agent_invocations_platform_id_tenant_id_idx" RENAME TO "agent_invocations_host_id_tenant_id_idx";

-- RenameIndex
ALTER INDEX "followup_plans_platform_id_tenant_id_idx" RENAME TO "followup_plans_host_id_tenant_id_idx";

-- RenameIndex
ALTER INDEX "followup_plans_platform_id_tenant_id_patient_id_version_key" RENAME TO "followup_plans_host_id_tenant_id_patient_id_version_key";

-- RenameIndex
ALTER INDEX "followup_plans_platform_id_tenant_id_target_clinic_id_idx" RENAME TO "followup_plans_host_id_tenant_id_target_clinic_id_idx";

-- RenameIndex
ALTER INDEX "platforms_app_id_key" RENAME TO "hosts_app_id_key";

-- RenameIndex
ALTER INDEX "platforms_name_key" RENAME TO "hosts_name_key";

-- RenameIndex
ALTER INDEX "patient_facts_platform_id_tenant_id_idx" RENAME TO "patient_facts_host_id_tenant_id_idx";

-- RenameIndex
ALTER INDEX "patient_facts_platform_id_tenant_id_subject_id_version_key" RENAME TO "patient_facts_host_id_tenant_id_subject_id_version_key";

-- RenameIndex
ALTER INDEX "patient_transactions_platform_id_tenant_id_clinic_id_idx" RENAME TO "patient_transactions_host_id_tenant_id_clinic_id_idx";

-- RenameIndex
ALTER INDEX "patients_platform_id_tenant_id_external_id_key" RENAME TO "patients_host_id_tenant_id_external_id_key";

-- RenameIndex
ALTER INDEX "patients_platform_id_tenant_id_idx" RENAME TO "patients_host_id_tenant_id_idx";

-- RenameIndex
ALTER INDEX "persona_recompute_logs_platform_id_tenant_id_idx" RENAME TO "persona_recompute_logs_host_id_tenant_id_idx";

-- RenameIndex
ALTER INDEX "personas_platform_id_tenant_id_idx" RENAME TO "personas_host_id_tenant_id_idx";

-- RenameIndex
ALTER INDEX "plan_executions_platform_id_tenant_id_executor_clinic_id_idx" RENAME TO "plan_executions_host_id_tenant_id_executor_clinic_id_idx";

-- RenameIndex
ALTER INDEX "plan_generation_logs_platform_id_tenant_id_idx" RENAME TO "plan_generation_logs_host_id_tenant_id_idx";

-- RenameIndex
ALTER INDEX "plan_scripts_platform_id_tenant_id_idx" RENAME TO "plan_scripts_host_id_tenant_id_idx";

-- RenameIndex
ALTER INDEX "plan_summaries_platform_id_tenant_id_idx" RENAME TO "plan_summaries_host_id_tenant_id_idx";

-- RenameIndex
ALTER INDEX "sync_logs_platform_id_tenant_id_resource_idx" RENAME TO "sync_logs_host_id_tenant_id_resource_idx";
