ATS-Doku/data/database.py

45 lines
1.1 KiB
Python
Raw Normal View History

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