-- AlterTable
ALTER TABLE "GuildSettings" ADD COLUMN "timezone" TEXT NOT NULL DEFAULT 'Europe/Berlin';

-- CreateTable
CREATE TABLE "DashboardAccessRule" (
    "id" TEXT NOT NULL,
    "guildId" TEXT NOT NULL,
    "roleId" TEXT NOT NULL,
    "modules" JSONB NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "DashboardAuditLog" (
    "id" TEXT NOT NULL,
    "guildId" TEXT,
    "actorUserId" TEXT NOT NULL,
    "action" TEXT NOT NULL,
    "path" TEXT,
    "before" JSONB,
    "after" JSONB,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE INDEX "DashboardAccessRule_guildId_idx" ON "DashboardAccessRule"("guildId");

-- CreateIndex
CREATE UNIQUE INDEX "DashboardAccessRule_guildId_roleId_key" ON "DashboardAccessRule"("guildId", "roleId");

-- CreateIndex
CREATE INDEX "DashboardAuditLog_guildId_createdAt_idx" ON "DashboardAuditLog"("guildId", "createdAt");

-- CreateIndex
CREATE INDEX "DashboardAuditLog_actorUserId_createdAt_idx" ON "DashboardAuditLog"("actorUserId", "createdAt");

-- AddForeignKey
ALTER TABLE "DashboardAccessRule" ADD CONSTRAINT "DashboardAccessRule_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "DashboardAuditLog" ADD CONSTRAINT "DashboardAuditLog_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild"("id") ON DELETE CASCADE ON UPDATE CASCADE;
