chore: Änderungen commited
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
65
utils/update_db.py
Normal file
65
utils/update_db.py
Normal file
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import sqlite3
|
||||
import sys
|
||||
|
||||
# Bestimme den absoluten Pfad zur Datenbank
|
||||
basedir = os.path.abspath(os.path.dirname(__file__))
|
||||
db_path = os.path.join(basedir, 'database', 'systades.db')
|
||||
|
||||
def update_user_table():
|
||||
"""Aktualisiert die User-Tabelle mit den fehlenden Spalten"""
|
||||
|
||||
# Überprüfe, ob die Datenbankdatei existiert
|
||||
if not os.path.exists(db_path):
|
||||
print(f"Datenbank nicht gefunden unter: {db_path}")
|
||||
return False
|
||||
|
||||
# Verbindung zur Datenbank herstellen
|
||||
try:
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Überprüfe, ob die neuen Spalten bereits existieren
|
||||
cursor.execute("PRAGMA table_info(user)")
|
||||
columns = [info[1] for info in cursor.fetchall()]
|
||||
|
||||
# Neue Spalten, die hinzugefügt werden müssen
|
||||
new_columns = {
|
||||
'bio': 'TEXT',
|
||||
'location': 'VARCHAR(100)',
|
||||
'website': 'VARCHAR(200)',
|
||||
'avatar': 'VARCHAR(200)',
|
||||
'last_login': 'DATETIME'
|
||||
}
|
||||
|
||||
# Spalten hinzufügen, die noch nicht existieren
|
||||
for col_name, col_type in new_columns.items():
|
||||
if col_name not in columns:
|
||||
print(f"Füge Spalte '{col_name}' zur User-Tabelle hinzu...")
|
||||
cursor.execute(f"ALTER TABLE user ADD COLUMN {col_name} {col_type}")
|
||||
|
||||
# Änderungen speichern
|
||||
conn.commit()
|
||||
print("User-Tabelle erfolgreich aktualisiert!")
|
||||
return True
|
||||
|
||||
except sqlite3.Error as e:
|
||||
print(f"Fehler bei der Datenbankaktualisierung: {e}")
|
||||
return False
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Führe die Aktualisierung durch
|
||||
success = update_user_table()
|
||||
|
||||
if success:
|
||||
print("Die Datenbank wurde erfolgreich aktualisiert.")
|
||||
sys.exit(0)
|
||||
else:
|
||||
print("Es gab ein Problem bei der Datenbankaktualisierung.")
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user