27 lines
1.4 KiB
MySQL
27 lines
1.4 KiB
MySQL
|
|
-- RedefineTables
|
||
|
|
PRAGMA defer_foreign_keys=ON;
|
||
|
|
PRAGMA foreign_keys=OFF;
|
||
|
|
CREATE TABLE "new_comments" (
|
||
|
|
"id" TEXT NOT NULL PRIMARY KEY,
|
||
|
|
"postId" TEXT NOT NULL,
|
||
|
|
"parentId" TEXT,
|
||
|
|
"depth" INTEGER NOT NULL DEFAULT 0,
|
||
|
|
"authorId" TEXT,
|
||
|
|
"content" TEXT NOT NULL,
|
||
|
|
"isAnonymous" BOOLEAN NOT NULL DEFAULT false,
|
||
|
|
"isSecret" BOOLEAN NOT NULL DEFAULT false,
|
||
|
|
"secretPasswordHash" TEXT,
|
||
|
|
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||
|
|
"updatedAt" DATETIME NOT NULL,
|
||
|
|
CONSTRAINT "comments_postId_fkey" FOREIGN KEY ("postId") REFERENCES "posts" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||
|
|
CONSTRAINT "comments_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "comments" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||
|
|
CONSTRAINT "comments_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users" ("userId") ON DELETE SET NULL ON UPDATE CASCADE
|
||
|
|
);
|
||
|
|
INSERT INTO "new_comments" ("authorId", "content", "createdAt", "id", "isAnonymous", "isSecret", "postId", "secretPasswordHash", "updatedAt") SELECT "authorId", "content", "createdAt", "id", "isAnonymous", "isSecret", "postId", "secretPasswordHash", "updatedAt" FROM "comments";
|
||
|
|
DROP TABLE "comments";
|
||
|
|
ALTER TABLE "new_comments" RENAME TO "comments";
|
||
|
|
CREATE INDEX "comments_postId_createdAt_idx" ON "comments"("postId", "createdAt");
|
||
|
|
CREATE INDEX "comments_parentId_idx" ON "comments"("parentId");
|
||
|
|
PRAGMA foreign_keys=ON;
|
||
|
|
PRAGMA defer_foreign_keys=OFF;
|