-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_update.py
72 lines (63 loc) · 2.49 KB
/
db_update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import sqlite3
from contextlib import contextmanager
DATABASE_PATH = "flux_logs.db"
@contextmanager
def get_db_connection(db_path=DATABASE_PATH):
conn = sqlite3.connect(db_path)
try:
yield conn
finally:
conn.close()
def column_exists(cursor, table_name, column_name):
cursor.execute(f"PRAGMA table_info({table_name})")
columns = [info[1] for info in cursor.fetchall()]
return column_name in columns
def update_database():
with get_db_connection() as conn:
cursor = conn.cursor()
# Erstellen oder aktualisieren Sie die Tabelle 'pictures'
try:
cursor.execute("""
CREATE TABLE IF NOT EXISTS pictures (
id INTEGER PRIMARY KEY AUTOINCREMENT,
fullpath TEXT,
filename TEXT,
timestamp TEXT,
album_id INTEGER,
category_id INTEGER,
aspect_ratio TEXT,
inference_steps INTEGER,
lora_scale REAL,
strength REAL,
guidance REAL,
quality INTEGER,
FOREIGN KEY (album_id) REFERENCES albums(id),
FOREIGN KEY (category_id) REFERENCES categories(id)
)
""")
print("Tabelle 'pictures' wurde erfolgreich erstellt.")
except sqlite3.OperationalError as e:
print(f"Fehler beim Erstellen der Tabelle 'pictures': {e}")
# Neue Felder zur Tabelle 'pictures' hinzufügen, falls sie noch nicht existieren
new_fields = [
("fullpath", "TEXT"),
("filename", "TEXT"),
("aspect_ratio", "TEXT"),
("inference_steps", "INTEGER"),
("lora_scale", "REAL"),
("strength", "REAL"),
("guidance", "REAL"),
("quality", "INTEGER")
]
for field_name, field_type in new_fields:
if not column_exists(cursor, "pictures", field_name):
try:
cursor.execute(f"ALTER TABLE pictures ADD COLUMN {field_name} {field_type}")
print(f"Feld '{field_name}' wurde erfolgreich hinzugefügt.")
except sqlite3.OperationalError as e:
print(f"Fehler beim Hinzufügen des Feldes '{field_name}': {e}")
else:
print(f"Feld '{field_name}' existiert bereits.")
conn.commit()
if __name__ == "__main__":
update_database()