ALTER TABLE "MediaSource" ADD COLUMN "thumbnailUrl" TEXT;
ALTER TABLE "MediaSource" ADD COLUMN "queuePosition" INTEGER NOT NULL DEFAULT 0;

WITH ordered AS (
  SELECT "id", ROW_NUMBER() OVER (PARTITION BY "roomId" ORDER BY "createdAt" ASC, "id" ASC) AS position
  FROM "MediaSource"
)
UPDATE "MediaSource"
SET "queuePosition" = ordered.position
FROM ordered
WHERE "MediaSource"."id" = ordered."id";
