recommend/prisma/migrations/20240530165230_a/migration.sql
2024-05-30 12:22:44 -05:00

58 lines
2.4 KiB
SQL

/*
Warnings:
- Added the required column `user_id` to the `Transition` table without a default value. This is not possible if the table is not empty.
*/
-- CreateTable
CREATE TABLE "Beatmap" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"difficulty" TEXT NOT NULL
);
-- CreateTable
CREATE TABLE "BeatmapSet" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"artist" TEXT NOT NULL,
"artistUnicode" TEXT NOT NULL,
"title" TEXT NOT NULL,
"titleUnicode" TEXT NOT NULL,
"genre" INTEGER NOT NULL,
"language" INTEGER NOT NULL
);
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Transition" (
"before_id" INTEGER NOT NULL,
"after_id" INTEGER NOT NULL,
"user_id" INTEGER NOT NULL,
"ms_between" BIGINT NOT NULL,
PRIMARY KEY ("before_id", "after_id"),
CONSTRAINT "Transition_before_id_fkey" FOREIGN KEY ("before_id") REFERENCES "Score" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Transition_after_id_fkey" FOREIGN KEY ("after_id") REFERENCES "Score" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Transition" ("after_id", "before_id", "ms_between") SELECT "after_id", "before_id", "ms_between" FROM "Transition";
DROP TABLE "Transition";
ALTER TABLE "new_Transition" RENAME TO "Transition";
CREATE TABLE "new_Score" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"accuracy" REAL NOT NULL,
"best_id" BIGINT,
"created_at" DATETIME NOT NULL,
"score_id" BIGINT,
"score" INTEGER NOT NULL,
"beatmap_id" INTEGER NOT NULL,
"beatmapset_id" INTEGER NOT NULL,
"user_id" INTEGER NOT NULL,
CONSTRAINT "Score_beatmap_id_fkey" FOREIGN KEY ("beatmap_id") REFERENCES "Beatmap" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Score_beatmapset_id_fkey" FOREIGN KEY ("beatmapset_id") REFERENCES "BeatmapSet" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Score" ("accuracy", "beatmap_id", "beatmapset_id", "best_id", "created_at", "id", "score", "score_id", "user_id") SELECT "accuracy", "beatmap_id", "beatmapset_id", "best_id", "created_at", "id", "score", "score_id", "user_id" FROM "Score";
DROP TABLE "Score";
ALTER TABLE "new_Score" RENAME TO "Score";
CREATE UNIQUE INDEX "Score_user_id_beatmap_id_created_at_score_key" ON "Score"("user_id", "beatmap_id", "created_at", "score");
PRAGMA foreign_key_check("Transition");
PRAGMA foreign_key_check("Score");
PRAGMA foreign_keys=ON;