diff --git a/mydb.sqlite b/mydb.sqlite index e69de29..5bf3c9e 100644 Binary files a/mydb.sqlite and b/mydb.sqlite differ diff --git a/src/db/index.ts b/src/db/index.ts index a504a3a..cd5f599 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -2,17 +2,35 @@ import fs from 'node:fs'; import path from 'node:path'; import { drizzle } from "drizzle-orm/bun-sqlite"; import { Database } from 'bun:sqlite'; +import { usersTable } from './schema'; // Importiere die Tabelle hier // biome-ignore lint/style/noNonNullAssertion: const dbPath = process.env.DB_FILE_NAME!; const dbDir = path.dirname(dbPath); -// Create directory if it doesn't exist +// Erstelle das Verzeichnis, wenn es noch nicht existiert if (!fs.existsSync(dbDir)) { fs.mkdirSync(dbDir, { recursive: true }); } -// Ensure database file can be created +// Wenn die Datenbankdatei nicht existiert, dann erstelle sie +if (!fs.existsSync(dbPath)) { + fs.writeFileSync(dbPath, ''); // Leere Datei erstellen +} + +// Datenbankverbindung herstellen const client = new Database(dbPath); -export const db = drizzle(client); \ No newline at end of file +// Stelle sicher, dass die Tabelle existiert +client.run(` + CREATE TABLE IF NOT EXISTS users_table ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, + discord_id INTEGER NOT NULL UNIQUE, + join_streak INTEGER, + last_joined_at INTEGER, + took_medication_today INTEGER NOT NULL DEFAULT 0 + ); +`); + +export const db = drizzle(client);