mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-22 03:49:18 +02:00
Feature AMS Info Card (#570)
* AMS Labels addition to PrintersPage * Added database reinitialization for schema migrations on database restore * Bug fixes and AMS Label persistence updates * Update database.py to resolve PR conflicts * PR Comment Resolution * Resolve conflicts in database.py for PR#570 * Updates to address PR#570 additional comments * Optimize visibility handling for popup component * Improve serial key handling in printers.py Refactor serial key assignment to handle empty AMS serial gracefully. * Implement error handling in serial number mapping Add error handling for serial number mapping. * Add migration to drop old ams_labels table --------- Co-authored-by: MartinNYHC <mz@v8w.de>
This commit is contained in:
co-authored by
MartinNYHC
parent
5ee2ef8dbf
commit
7ba67012f6
@@ -74,6 +74,7 @@ async def init_db():
|
||||
from backend.app.models import ( # noqa: F401
|
||||
active_print_spoolman,
|
||||
ams_history,
|
||||
ams_label,
|
||||
api_key,
|
||||
archive,
|
||||
bug_report,
|
||||
@@ -1361,6 +1362,45 @@ async def run_migrations(conn):
|
||||
except OperationalError:
|
||||
pass # Already applied
|
||||
|
||||
# Migration: Convert ams_labels table from (printer_id, ams_id) key to ams_serial_number key
|
||||
# Labels are now keyed by AMS serial number so they persist when the AMS is moved to another printer.
|
||||
try:
|
||||
await conn.execute(text("DROP TABLE IF EXISTS ams_labels_new"))
|
||||
result = await conn.execute(text("SELECT sql FROM sqlite_master WHERE type='table' AND name='ams_labels'"))
|
||||
row = result.fetchone()
|
||||
if row and "printer_id" in (row[0] or ""):
|
||||
# Old schema: rebuild the table with ams_serial_number as the unique key.
|
||||
# Existing rows get a synthetic serial "p{printer_id}a{ams_id}" so data is preserved.
|
||||
await conn.execute(
|
||||
text("""
|
||||
CREATE TABLE ams_labels_new (
|
||||
id INTEGER PRIMARY KEY,
|
||||
ams_serial_number VARCHAR(50) NOT NULL,
|
||||
ams_id INTEGER,
|
||||
label VARCHAR(100) NOT NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT uq_ams_label_serial UNIQUE (ams_serial_number)
|
||||
)
|
||||
""")
|
||||
)
|
||||
await conn.execute(
|
||||
text("""
|
||||
INSERT INTO ams_labels_new (id, ams_serial_number, ams_id, label, created_at, updated_at)
|
||||
SELECT id,
|
||||
'p' || CAST(printer_id AS TEXT) || 'a' || CAST(ams_id AS TEXT),
|
||||
ams_id,
|
||||
label,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM ams_labels
|
||||
""")
|
||||
)
|
||||
await conn.execute(text("DROP TABLE ams_labels"))
|
||||
await conn.execute(text("ALTER TABLE ams_labels_new RENAME TO ams_labels"))
|
||||
except OperationalError:
|
||||
pass # Already migrated or table does not exist yet
|
||||
|
||||
# Cleanup: Remove obsolete settings keys that are no longer used
|
||||
obsolete_keys = ["slicer_binary_path"]
|
||||
for key in obsolete_keys:
|
||||
|
||||
Reference in New Issue
Block a user