-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_ContentItem" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "modelId" TEXT NOT NULL,
    "modelCode" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "slug" TEXT NOT NULL DEFAULT '',
    "locale" TEXT NOT NULL DEFAULT 'zh-CN',
    "status" TEXT NOT NULL DEFAULT 'draft',
    "data" TEXT NOT NULL,
    "version" INTEGER NOT NULL DEFAULT 1,
    "sortOrder" INTEGER NOT NULL DEFAULT 0,
    "publishedAt" DATETIME,
    "createdBy" TEXT NOT NULL DEFAULT 'system',
    "updatedBy" TEXT NOT NULL DEFAULT 'system',
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" DATETIME NOT NULL,
    CONSTRAINT "ContentItem_modelId_fkey" FOREIGN KEY ("modelId") REFERENCES "ContentModel" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_ContentItem" ("createdAt", "createdBy", "data", "id", "modelCode", "modelId", "publishedAt", "slug", "sortOrder", "status", "title", "updatedAt", "updatedBy", "version") SELECT "createdAt", "createdBy", "data", "id", "modelCode", "modelId", "publishedAt", "slug", "sortOrder", "status", "title", "updatedAt", "updatedBy", "version" FROM "ContentItem";
DROP TABLE "ContentItem";
ALTER TABLE "new_ContentItem" RENAME TO "ContentItem";
CREATE INDEX "ContentItem_modelCode_idx" ON "ContentItem"("modelCode");
CREATE INDEX "ContentItem_status_idx" ON "ContentItem"("status");
CREATE INDEX "ContentItem_locale_idx" ON "ContentItem"("locale");
CREATE UNIQUE INDEX "ContentItem_modelCode_slug_locale_key" ON "ContentItem"("modelCode", "slug", "locale");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;
