diff --git a/lib/db/initDB.ts b/lib/db/initDB.ts index 29cf570..cf14eec 100644 --- a/lib/db/initDB.ts +++ b/lib/db/initDB.ts @@ -2,21 +2,17 @@ import { prisma } from "@/lib/db/prisma" import argon2 from 'argon2' export async function initDB() { - // const count = await prisma.user.count() - // - // if (count === 0) { - // await prisma.user.create({ - // data: { - // email: process.env.ADMIN_EMAIL!, - // username: 'admin', - // password: await argon2.hash(process.env.ADMIN_PASSWORD!), - // role: 'admin', - // firstname: 'Admin' - // } - // }) - // console.log('Admin-User angelegt.') - // } - console.log("Start der DB"); - const count = await prisma.user.count(); - console.log(count); + const count = await prisma.user.count() + + if (count === 0) { + await prisma.user.create({ + data: { + username: process.env.ADMIN_USERNAME!, + password: await argon2.hash(process.env.ADMIN_PASSWORD!), + role: 'admin', + name: 'Admin' + } + }) + console.log('Admin-User angelegt.') + } } diff --git a/lib/db/managing.ts b/lib/db/managing.ts index abd7db4..175e3cd 100644 --- a/lib/db/managing.ts +++ b/lib/db/managing.ts @@ -1,26 +1,6 @@ import { prisma } from "@/lib/db/prisma"; -db.exec(` - CREATE TABLE IF NOT EXISTS songs ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - title TEXT NOT NULL - ); - CREATE TABLE IF NOT EXISTS songbooks ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name TEXT NOT NULL, - language TEXT - ); - CREATE TABLE IF NOT EXISTS songbook_songs ( - songbook_id INTEGER, - song_id INTEGER, - song_number TEXT, - PRIMARY KEY (songbook_id, song_id), - FOREIGN KEY (songbook_id) REFERENCES songbooks(id) ON DELETE CASCADE, - FOREIGN KEY (song_id) REFERENCES songs(id) ON DELETE CASCADE - ); -`) - export async function getSongs() { try { const songs = db.prepare(`