fix what would have been a really bad time with the db

This commit is contained in:
Micha Albert 2024-08-15 17:57:02 +00:00
parent 7e0ad4d1e2
commit 36e70429de
2 changed files with 43 additions and 2 deletions

View file

@ -0,0 +1,41 @@
/*
Warnings:
- You are about to drop the column `active` on the `Stream` table. All the data in the column will be lost.
- You are about to drop the column `focused` on the `Stream` table. All the data in the column will be lost.
- The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `slackId` on the `User` table. All the data in the column will be lost.
- Added the required column `user_id` to the `Stream` table without a default value. This is not possible if the table is not empty.
- The required column `id` was added to the `User` table with a prisma-level default value. This is not possible if the table is not empty. Please add this column as optional, then populate it before making it required.
- Added the required column `slack_id` to the `User` 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_Stream" (
"id" TEXT NOT NULL PRIMARY KEY,
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"is_live" BOOLEAN NOT NULL DEFAULT false,
"is_focused" BOOLEAN NOT NULL DEFAULT false,
"key" TEXT NOT NULL,
"user_id" TEXT NOT NULL,
CONSTRAINT "Stream_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Stream" ("id", "key") SELECT "id", "key" FROM "Stream";
DROP TABLE "Stream";
ALTER TABLE "new_Stream" RENAME TO "Stream";
CREATE UNIQUE INDEX "Stream_key_key" ON "Stream"("key");
CREATE UNIQUE INDEX "Stream_user_id_key" ON "Stream"("user_id");
CREATE TABLE "new_User" (
"id" TEXT NOT NULL PRIMARY KEY,
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"slack_id" TEXT NOT NULL,
"name" TEXT NOT NULL
);
INSERT INTO "new_User" ("name") SELECT "name" FROM "User";
DROP TABLE "User";
ALTER TABLE "new_User" RENAME TO "User";
CREATE UNIQUE INDEX "User_slack_id_key" ON "User"("slack_id");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

View file

@ -1,7 +1,7 @@
generator client { generator client {
provider = "prisma-client-py" provider = "prisma-client-py"
interface = "asyncio" interface = "asyncio"
recursive_type_depth = 5 recursive_type_depth = "5"
} }
datasource db { datasource db {
@ -23,6 +23,6 @@ model Stream {
is_live Boolean @default(false) is_live Boolean @default(false)
is_focused Boolean @default(false) is_focused Boolean @default(false)
key String @unique @default(uuid()) key String @unique @default(uuid())
user User @relation(fields: [user_id], references: [id])
user_id String @unique user_id String @unique
user User @relation(fields: [user_id], references: [id])
} }