/*
  Warnings:

  - A unique constraint covering the columns `[name]` on the table `partners` will be added. If there are existing duplicate values, this will fail.

*/
-- CreateTable
CREATE TABLE "board_categories" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "name" TEXT NOT NULL,
    "slug" TEXT NOT NULL,
    "sortOrder" INTEGER NOT NULL DEFAULT 0,
    "status" TEXT NOT NULL DEFAULT 'active',
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" DATETIME NOT NULL
);

-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_boards" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "name" TEXT NOT NULL,
    "slug" TEXT NOT NULL,
    "description" TEXT,
    "sortOrder" INTEGER NOT NULL DEFAULT 0,
    "status" TEXT NOT NULL DEFAULT 'active',
    "type" TEXT NOT NULL DEFAULT 'general',
    "requiresApproval" BOOLEAN NOT NULL DEFAULT false,
    "allowAnonymousPost" BOOLEAN NOT NULL DEFAULT false,
    "allowSecretComment" BOOLEAN NOT NULL DEFAULT false,
    "isAdultOnly" BOOLEAN NOT NULL DEFAULT false,
    "requiredTags" JSONB,
    "requiredFields" JSONB,
    "readLevel" TEXT NOT NULL DEFAULT 'public',
    "writeLevel" TEXT NOT NULL DEFAULT 'member',
    "categoryId" TEXT,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" DATETIME NOT NULL,
    CONSTRAINT "boards_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "board_categories" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);
INSERT INTO "new_boards" ("allowAnonymousPost", "allowSecretComment", "createdAt", "description", "id", "isAdultOnly", "name", "readLevel", "requiredFields", "requiredTags", "requiresApproval", "slug", "sortOrder", "status", "type", "updatedAt", "writeLevel") SELECT "allowAnonymousPost", "allowSecretComment", "createdAt", "description", "id", "isAdultOnly", "name", "readLevel", "requiredFields", "requiredTags", "requiresApproval", "slug", "sortOrder", "status", "type", "updatedAt", "writeLevel" FROM "boards";
DROP TABLE "boards";
ALTER TABLE "new_boards" RENAME TO "boards";
CREATE UNIQUE INDEX "boards_slug_key" ON "boards"("slug");
CREATE INDEX "boards_status_sortOrder_idx" ON "boards"("status", "sortOrder");
CREATE INDEX "boards_type_requiresApproval_idx" ON "boards"("type", "requiresApproval");
CREATE INDEX "boards_categoryId_idx" ON "boards"("categoryId");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

-- CreateIndex
CREATE UNIQUE INDEX "board_categories_name_key" ON "board_categories"("name");

-- CreateIndex
CREATE UNIQUE INDEX "board_categories_slug_key" ON "board_categories"("slug");

-- CreateIndex
CREATE INDEX "board_categories_status_sortOrder_idx" ON "board_categories"("status", "sortOrder");

-- CreateIndex
CREATE UNIQUE INDEX "partners_name_key" ON "partners"("name");
