30 lines
1.2 KiB
SQL
30 lines
1.2 KiB
SQL
/*
|
|
Warnings:
|
|
|
|
- You are about to drop the column `filePath` on the `PhotoPost` table. All the data in the column will be lost.
|
|
- Added the required column `fileName` to the `PhotoPost` table without a default value. This is not possible if the table is not empty.
|
|
|
|
*/
|
|
-- RedefineTables
|
|
PRAGMA defer_foreign_keys=ON;
|
|
PRAGMA foreign_keys=OFF;
|
|
CREATE TABLE "new_PhotoPost" (
|
|
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"fileName" TEXT NOT NULL,
|
|
"title" TEXT NOT NULL,
|
|
"description" TEXT
|
|
);
|
|
|
|
-- The filename field is the filepath, split by '/', and it's the last part,
|
|
-- so we need to modify the filePath column to fileName
|
|
ALTER TABLE "PhotoPost" ADD COLUMN "fileName" TEXT NOT NULL DEFAULT '';
|
|
UPDATE "PhotoPost" SET "fileName" = SUBSTR("filePath", INSTR("filePath", '/') + 1);
|
|
|
|
INSERT INTO "new_PhotoPost" ("createdAt", "description", "fileName", "id", "title") SELECT "createdAt", "description", "fileName", "id", "title" FROM "PhotoPost";
|
|
|
|
DROP TABLE "PhotoPost";
|
|
ALTER TABLE "new_PhotoPost" RENAME TO "PhotoPost";
|
|
CREATE UNIQUE INDEX "PhotoPost_fileName_key" ON "PhotoPost"("fileName");
|
|
PRAGMA foreign_keys=ON;
|
|
PRAGMA defer_foreign_keys=OFF;
|