-- CreateTable
CREATE TABLE "RehearsalParticipation" (
    "id" TEXT NOT NULL,
    "rehearsalId" TEXT NOT NULL,
    "engagementWeekId" TEXT NOT NULL,
    "bandTrackId" TEXT NOT NULL,
    "overrideMusicianId" TEXT,
    "isTrainingRow" BOOLEAN NOT NULL DEFAULT false,
    "parentTrackId" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "RehearsalParticipation_pkey" PRIMARY KEY ("id")
);

-- Indexes
CREATE INDEX "RehearsalParticipation_rehearsalId_idx" ON "RehearsalParticipation"("rehearsalId");
CREATE INDEX "RehearsalParticipation_engagementWeekId_idx" ON "RehearsalParticipation"("engagementWeekId");
CREATE INDEX "RehearsalParticipation_bandTrackId_idx" ON "RehearsalParticipation"("bandTrackId");
CREATE INDEX "RehearsalParticipation_overrideMusicianId_idx" ON "RehearsalParticipation"("overrideMusicianId");

-- Foreign Keys
ALTER TABLE "RehearsalParticipation"
  ADD CONSTRAINT "RehearsalParticipation_rehearsalId_fkey" FOREIGN KEY ("rehearsalId") REFERENCES "Rehearsal"("id") ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE "RehearsalParticipation"
  ADD CONSTRAINT "RehearsalParticipation_engagementWeekId_fkey" FOREIGN KEY ("engagementWeekId") REFERENCES "EngagementWeek"("id") ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE "RehearsalParticipation"
  ADD CONSTRAINT "RehearsalParticipation_bandTrackId_fkey" FOREIGN KEY ("bandTrackId") REFERENCES "BandTrack"("id") ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE "RehearsalParticipation"
  ADD CONSTRAINT "RehearsalParticipation_overrideMusicianId_fkey" FOREIGN KEY ("overrideMusicianId") REFERENCES "Musician"("id") ON DELETE SET NULL ON UPDATE CASCADE;
