Build [v1.9.19]

This commit is contained in:
Daniel Bedeleanu
2026-04-14 20:44:01 +03:00
parent fcb187974e
commit 00ee4cf9c5
38 changed files with 2059 additions and 157 deletions

View File

@@ -0,0 +1,51 @@
import sys
import os
# Add parent directory to path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from database import SessionLocal, engine
import models
def init_settings():
db = SessionLocal()
try:
# Default AI Prompt from User Request
default_prompt = """identify and summarise the minimal necessary information for a quick description if item. I need the following output - <field name> : the result from you.
For any field, do not add comments in parenthesis.
Item: in three words type of this item
Type: what type of item is, like "spare parts", "consumables", "patch cords" etc.
Description: description (max 5 words)
Category: category, if any
Connector: connectors
Size: size or length
Color: color if useful
PartNr: part number if any
OCR: identification string for local OCR matching"""
# We will wrap this in a instruction to return JSON for easier parsing while keeping the user's content
final_prompt = f"IMAGE ANALYSIS INSTRUCTIONS:\n{default_prompt}\n\nIMPORTANT: Return ONLY a valid JSON object with the keys: Item, Type, Description, Category, Connector, Size, Color, PartNr, OCR."
existing = db.query(models.SystemSetting).filter(models.SystemSetting.key == "ai_extraction_prompt").first()
if not existing:
db.add(models.SystemSetting(key="ai_extraction_prompt", value=final_prompt))
print("Added default AI prompt setting.")
# Add default backup settings if missing
defaults = {
"backup_retention_count": "10",
"backup_schedule_hour": "3",
"backup_schedule_freq_days": "1"
}
for key, val in defaults.items():
if not db.query(models.SystemSetting).filter(models.SystemSetting.key == key).first():
db.add(models.SystemSetting(key=key, value=val))
print(f"Added default setting: {key}")
db.commit()
finally:
db.close()
if __name__ == "__main__":
init_settings()

View File

@@ -0,0 +1,49 @@
import sqlite3
import os
from ..database import db_path
from ..logger import log
def migrate():
"""
Migration script to upgrade the items table from schema v4 to v5.
Adds columns: description, connector, size, ocr_text.
"""
log.info(f"🚀 Starting database migration on {db_path}...")
if not os.path.exists(db_path):
log.error(f"❌ Database file not found at {db_path}")
return
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
try:
# Check existing columns
cursor.execute("PRAGMA table_info(items)")
columns = [row[1] for row in cursor.fetchall()]
new_columns = [
("description", "VARCHAR"),
("connector", "VARCHAR"),
("size", "VARCHAR"),
("ocr_text", "TEXT")
]
for col_name, col_type in new_columns:
if col_name not in columns:
log.info(f" Adding column '{col_name}' to 'items' table...")
cursor.execute(f"ALTER TABLE items ADD COLUMN {col_name} {col_type}")
else:
log.info(f"✔️ Column '{col_name}' already exists.")
conn.commit()
log.info("✅ Migration completed successfully.")
except Exception as e:
log.error(f"❌ Migration failed: {e}")
conn.rollback()
finally:
conn.close()
if __name__ == "__main__":
migrate()