補強 5.5 自癒安全回看
All checks were successful
CD Pipeline / deploy (push) Successful in 1m11s

This commit is contained in:
OoO
2026-04-29 22:48:24 +08:00
parent 779b27f676
commit 0875dd8fda
10 changed files with 217 additions and 66 deletions

View File

@@ -121,14 +121,14 @@ class AIInsight(Base):
product_sku = Column(String(50))
content = Column(Text, nullable=False)
metadata_json = Column(Text) # JSON extra payload
avg_quality = Column(Float, default=0.0)
status = Column(String(20), default='active') # active / archived
avg_quality = Column(Float, default=0.5)
status = Column(String(20), default='approved') # approved / pending / rejected / archived
decay_exempt = Column(Boolean, default=False)
ai_model = Column(String(50))
feedback_up = Column(Integer, default=0)
feedback_down = Column(Integer, default=0)
confidence = Column(Float, default=1.0)
created_by = Column(String(50))
confidence = Column(Float, default=0.5)
created_by = Column(String(50), default='system')
created_at = Column(DateTime, default=datetime.now)
updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)
# embedding 欄位為 pgvector 型別,透過 raw SQL 寫入,此處不聲明以避免型別衝突

View File

@@ -2,6 +2,7 @@ import os
import re
import threading
from sqlalchemy import create_engine, desc, select, text, literal
from sqlalchemy.engine.url import make_url
from sqlalchemy.orm import sessionmaker
from datetime import datetime
from .models import Base, Category, Product, PriceRecord, MonthlySummaryAnalysis
@@ -112,8 +113,14 @@ class DatabaseManager:
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
db_path = os.path.join(base_dir, 'data', 'momo_database.db')
os.makedirs(os.path.dirname(db_path), exist_ok=True)
self.engine = create_engine(f'sqlite:///{db_path}', echo=False)
if str(db_path).startswith('sqlite://'):
sqlite_db_file = make_url(db_path).database
if sqlite_db_file:
os.makedirs(os.path.dirname(sqlite_db_file), exist_ok=True)
self.engine = create_engine(db_path, echo=False)
else:
os.makedirs(os.path.dirname(db_path), exist_ok=True)
self.engine = create_engine(f'sqlite:///{db_path}', echo=False)
Base.metadata.create_all(self.engine)
self.Session = sessionmaker(bind=self.engine)
self._check_and_fix_schema()