ATS-Doku/data/database.py

45 lines
1.1 KiB
Python

import sqlite3
DB_NAME = "ats_doku.db"
def initialize_db():
connection = sqlite3.connect(DB_NAME)
cursor = connection.cursor()
# --- Tabelle 1: Die Liste für dein Dropdown ---
cursor.execute('''
CREATE TABLE IF NOT EXISTS ats (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE,
code TEXT UNIQUE
)
''')
# --- Tabelle 2: Das Logbuch (jetzt mit Ort) ---
cursor.execute('''
CREATE TABLE IF NOT EXISTS einsaetze (
id INTEGER PRIMARY KEY AUTOINCREMENT,
location TEXT,
name TEXT,
date TEXT,
time INTEGER,
etype TEXT,
device TEXT
)
''')
# Optional: Ein paar Test-ats anlegen, falls die Tabelle leer ist
cursor.execute("SELECT count(*) FROM ats")
if cursor.fetchone()[0] == 0:
ats_liste = [("Tim Grubmüller",), ("Phil Langer",), ("Max Hämmerle",)]
cursor.executemany("INSERT INTO ats (name) VALUES (?)", ats_liste)
connection.commit()
connection.close()