-- CreateEnum CREATE TYPE "NotificationDeliveryStatus" AS ENUM ('pending', 'success', 'failed'); -- AlterTable ALTER TABLE "employees" ADD COLUMN "notification_push_enabled" BOOLEAN NOT NULL DEFAULT true; -- CreateTable CREATE TABLE "notification_deliveries" ( "id" UUID NOT NULL, "notification_id" UUID NOT NULL, "channel_id" UUID NOT NULL, "status" "NotificationDeliveryStatus" NOT NULL, "attempt_no" INTEGER NOT NULL, "result_code" VARCHAR(64), "error_message" TEXT, "response_body" JSONB, "attempted_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT "notification_deliveries_pkey" PRIMARY KEY ("id") ); -- AddForeignKey ALTER TABLE "notification_deliveries" ADD CONSTRAINT "notification_deliveries_notification_id_fkey" FOREIGN KEY ("notification_id") REFERENCES "notifications"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "notification_deliveries" ADD CONSTRAINT "notification_deliveries_channel_id_fkey" FOREIGN KEY ("channel_id") REFERENCES "notification_channels"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- CreateIndex CREATE INDEX "idx_notification_deliveries_notification_attempted" ON "notification_deliveries"("notification_id", "attempted_at"); -- CreateIndex CREATE INDEX "idx_notification_deliveries_channel_attempted" ON "notification_deliveries"("channel_id", "attempted_at"); -- CreateIndex CREATE INDEX "idx_notification_deliveries_status_attempted" ON "notification_deliveries"("status", "attempted_at");