fix: Vermeide Neuinitialisierung der Datenbank bei jedem Start
This commit is contained in:
28
app.py
28
app.py
@@ -51,6 +51,12 @@ def init_db():
|
|||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Prüfe, ob die Tabelle bereits existiert
|
||||||
|
c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='customers'")
|
||||||
|
if c.fetchone() is not None:
|
||||||
|
app.logger.info('Datenbank existiert bereits, überspringe Initialisierung')
|
||||||
|
return
|
||||||
|
|
||||||
# Erstelle die Kunden-Tabelle
|
# Erstelle die Kunden-Tabelle
|
||||||
c.execute('''
|
c.execute('''
|
||||||
CREATE TABLE IF NOT EXISTS customers (
|
CREATE TABLE IF NOT EXISTS customers (
|
||||||
@@ -83,11 +89,29 @@ def init_db():
|
|||||||
# Zusammengesetzter Index für die häufigste Suchkombination
|
# Zusammengesetzter Index für die häufigste Suchkombination
|
||||||
c.execute('CREATE INDEX IF NOT EXISTS idx_customers_search ON customers(name, ort, fachrichtung, tag)')
|
c.execute('CREATE INDEX IF NOT EXISTS idx_customers_search ON customers(name, ort, fachrichtung, tag)')
|
||||||
|
|
||||||
logger.info('Datenbank initialisiert')
|
app.logger.info('Datenbank initialisiert')
|
||||||
|
|
||||||
|
# Importiere die CSV-Daten
|
||||||
|
import_medisoft_data()
|
||||||
|
import_mediconsult_data()
|
||||||
|
app.logger.info('CSV-Daten erfolgreich in die Datenbank importiert')
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'Fehler bei der Datenbankinitialisierung: {str(e)}')
|
app.logger.error(f'Fehler bei der Datenbankinitialisierung: {str(e)}')
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
def import_csv_data():
|
||||||
|
"""Importiert die CSV-Daten in die Datenbank."""
|
||||||
|
try:
|
||||||
|
app.logger.info('Importiere MEDISOFT-Daten...')
|
||||||
|
import_medisoft_data()
|
||||||
|
app.logger.info('Importiere MEDICONSULT-Daten...')
|
||||||
|
import_mediconsult_data()
|
||||||
|
app.logger.info('CSV-Daten erfolgreich in die Datenbank importiert')
|
||||||
|
except Exception as e:
|
||||||
|
app.logger.error(f'Fehler beim CSV-Import: {str(e)}')
|
||||||
|
raise
|
||||||
|
|
||||||
def isIPInSubnet(ip, subnet):
|
def isIPInSubnet(ip, subnet):
|
||||||
"""Überprüft, ob eine IP-Adresse in einem Subnetz liegt."""
|
"""Überprüft, ob eine IP-Adresse in einem Subnetz liegt."""
|
||||||
try:
|
try:
|
||||||
|
Reference in New Issue
Block a user