Database-Layout
Das Datanbankschema wurde an das alte angepasst. !!Hinzugefügt wurde 'User'!!
This commit is contained in:
1 parent
9aa94638d9
commit
4ccd860814
3 files changed
+81
-13
No files matched your search
+1
-10
@@ -1,14 +1,5 @@
|
||||
import Database from "better-sqlite3";
|
||||
import path from "path";
|
||||
import { prisma } from "@/lib/db/prisma";
|
||||
|
||||
const dbPath = path.join(process.cwd(), "songs.db");
|
||||
|
||||
// Verhindert, dass Next.js bei jedem Reload die DB neu öffnet
|
||||
const globalForDb = globalThis as unknown as { db: Database.Database | undefined };
|
||||
|
||||
export const db = globalForDb.db ?? new Database(dbPath);
|
||||
|
||||
if (process.env.NODE_ENV !== "production") globalForDb.db = db;
|
||||
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS songs (
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `email` on the `User` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `firstname` on the `User` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `lastname` on the `User` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- CreateTable
|
||||
CREATE TABLE "Song" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"title" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "SongBook" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"title" TEXT NOT NULL,
|
||||
"language" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "SongBookSongs" (
|
||||
"SongBookId" INTEGER NOT NULL,
|
||||
"SongId" INTEGER NOT NULL,
|
||||
"songNumber" INTEGER NOT NULL,
|
||||
|
||||
PRIMARY KEY ("SongBookId", "SongId"),
|
||||
CONSTRAINT "SongBookSongs_SongId_fkey" FOREIGN KEY ("SongId") REFERENCES "Song" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT "SongBookSongs_SongBookId_fkey" FOREIGN KEY ("SongBookId") REFERENCES "SongBook" ("id") ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- RedefineTables
|
||||
PRAGMA defer_foreign_keys=ON;
|
||||
PRAGMA foreign_keys=OFF;
|
||||
CREATE TABLE "new_User" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"username" TEXT NOT NULL,
|
||||
"password" TEXT NOT NULL,
|
||||
"role" TEXT NOT NULL DEFAULT 'user',
|
||||
"name" TEXT
|
||||
);
|
||||
INSERT INTO "new_User" ("id", "password", "role", "username") SELECT "id", "password", "role", "username" FROM "User";
|
||||
DROP TABLE "User";
|
||||
ALTER TABLE "new_User" RENAME TO "User";
|
||||
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");
|
||||
PRAGMA foreign_keys=ON;
|
||||
PRAGMA defer_foreign_keys=OFF;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Song_title_key" ON "Song"("title");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "SongBook_title_key" ON "SongBook"("title");
|
||||
+26
-3
@@ -14,11 +14,34 @@ datasource db {
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
email String @unique
|
||||
username String @unique
|
||||
password String
|
||||
role String @default("user")
|
||||
firstname String
|
||||
lastname String?
|
||||
name String?
|
||||
}
|
||||
|
||||
model Song {
|
||||
id Int @id @default(autoincrement())
|
||||
title String @unique
|
||||
|
||||
songBookSongs SongBookSongs[]
|
||||
}
|
||||
|
||||
model SongBook {
|
||||
id Int @id @default(autoincrement())
|
||||
title String @unique
|
||||
language String
|
||||
|
||||
songBookSongs SongBookSongs[]
|
||||
}
|
||||
|
||||
model SongBookSongs {
|
||||
SongBookId Int
|
||||
SongId Int
|
||||
songNumber Int
|
||||
|
||||
song Song @relation(fields: [SongId], references: [id], onDelete: Cascade)
|
||||
book SongBook @relation(fields: [SongBookId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@id([SongBookId, SongId])
|
||||
}
|
||||
Reference in new issue
Block a user