-- AlterTable
ALTER TABLE "events" ADD COLUMN "slug" VARCHAR(50);

-- Generate unique slugs for existing events
UPDATE "events" SET "slug" = lower(
  substring(md5(random()::text || clock_timestamp()::text) from 1 for 12)
) WHERE "slug" IS NULL;

-- Make slug NOT NULL and add unique constraint
ALTER TABLE "events" ALTER COLUMN "slug" SET NOT NULL;
CREATE UNIQUE INDEX "events_slug_key" ON "events"("slug");
