-- DropForeignKey
ALTER TABLE "notifications" DROP CONSTRAINT "notifications_user_id_fkey";

-- DropForeignKey
ALTER TABLE "request" DROP CONSTRAINT "request_nursery_id_fkey";

-- DropForeignKey
ALTER TABLE "service" DROP CONSTRAINT "service_planter_id_fkey";

-- Drop the dependent objects before dropping the primary key
-- This includes dropping indexes and constraints that depend on service_pkey
-- Make sure to adjust this part based on your database structure
-- DROP INDEX "service_request_id_key";
-- ALTER TABLE "request_cost" DROP CONSTRAINT "request_cost_service_id_fkey";
-- ALTER TABLE "planting_media" DROP CONSTRAINT "planting_media_planting_id_fkey";

-- AlterTable
ALTER TABLE "notifications" DROP COLUMN "read",
DROP COLUMN "user_id",
ADD COLUMN     "userId" TEXT;

-- AlterTable
ALTER TABLE "request" DROP COLUMN "nursery_id";

-- AlterTable
ALTER TABLE "service" DROP CONSTRAINT "service_pkey" CASCADE, -- Cascade to drop dependent objects
DROP COLUMN "planter_id",
ADD COLUMN     "arborist_id" TEXT,
ADD COLUMN     "id" SERIAL NOT NULL,
ALTER COLUMN "nursery_id" DROP NOT NULL,
ADD CONSTRAINT "service_pkey" PRIMARY KEY ("id");

-- CreateTable
CREATE TABLE "NotificationUser" (
    "id" SERIAL NOT NULL,
    "notification_id" INTEGER NOT NULL,
    "read" BOOLEAN NOT NULL DEFAULT false,
    "user_id" TEXT NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "service_request_id_key" ON "service"("request_id");

-- AddForeignKey
ALTER TABLE "NotificationUser" ADD CONSTRAINT "NotificationUser_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "NotificationUser" ADD CONSTRAINT "NotificationUser_notification_id_fkey" FOREIGN KEY ("notification_id") REFERENCES "notifications"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "service" ADD CONSTRAINT "service_arborist_id_fkey" FOREIGN KEY ("arborist_id") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "service" ADD CONSTRAINT "service_nursery_id_fkey" FOREIGN KEY ("nursery_id") REFERENCES "nursery"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "service" ADD CONSTRAINT "service_request_id_fkey" FOREIGN KEY ("request_id") REFERENCES "request"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "request_cost" ADD CONSTRAINT "request_cost_service_id_fkey" FOREIGN KEY ("service_id") REFERENCES "service"("request_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "planting_media" ADD CONSTRAINT "planting_media_planting_id_fkey" FOREIGN KEY ("planting_id") REFERENCES "service"("request_id") ON DELETE RESTRICT ON UPDATE CASCADE;
