Some checks failed
CD Pipeline / deploy (push) Failing after 59s
- 建立 Gitea Actions CD pipeline (.gitea/workflows/cd.yaml) - 部署模式: rsync Python 檔案至 188 → docker restart (volume mount) - Dockerfile/requirements 變動時自動重建 Docker image - 部署通知: Telegram (開始/成功/失敗) - 健康檢查: https://mo.wooo.work/health (最多 5 次重試) - 同步最新 CLAUDE.md / ADR-008 / memory (2026-04-19) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
69 lines
2.8 KiB
Python
69 lines
2.8 KiB
Python
import os
|
||
import sys
|
||
import time
|
||
from sqlalchemy import create_engine, inspect, text
|
||
|
||
# 設定專案路徑
|
||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||
sys.path.insert(0, BASE_DIR)
|
||
|
||
def inspect_sales_data():
|
||
table_name = 'realtime_sales_monthly'
|
||
|
||
# 確保路徑與 app.py / clear_sales_table.py 一致
|
||
db_path = os.path.join(BASE_DIR, 'data', 'momo_database.db')
|
||
print(f"🔍 正在檢查資料庫檔案: {db_path}")
|
||
|
||
if os.path.exists(db_path):
|
||
mtime = time.ctime(os.path.getmtime(db_path))
|
||
size = os.path.getsize(db_path)
|
||
print(f"📂 檔案狀態: 存在 | 大小: {size} bytes | 最後修改: {mtime}")
|
||
|
||
if not os.path.exists(db_path):
|
||
print("❌ 資料庫檔案不存在!請確認路徑是否正確。")
|
||
return
|
||
|
||
# V-Fix: 直接建立 engine,不透過 DatabaseManager 以避免觸發自動修復邏輯 (寫入操作)
|
||
engine = create_engine(f'sqlite:///{db_path}')
|
||
|
||
try:
|
||
inspector = inspect(engine)
|
||
|
||
# 1. 檢查表格是否存在
|
||
if not inspector.has_table(table_name):
|
||
print(f"✅ 資料表 '{table_name}' 不存在 (確認已從資料庫中移除)。")
|
||
print("👉 如果您在網頁上還看得到資料,請務必【重啟 app.py】以清除記憶體快取。")
|
||
return
|
||
|
||
print(f"⚠️ 資料表 '{table_name}' 仍然存在於資料庫中!")
|
||
|
||
# 2. 檢查資料筆數
|
||
with engine.connect() as conn:
|
||
count = conn.execute(text(f"SELECT COUNT(*) FROM {table_name}")).scalar()
|
||
print(f"📊 目前資料筆數: {count}")
|
||
|
||
if count > 0:
|
||
print("\n--- 前 5 筆資料預覽 ---")
|
||
try:
|
||
result = conn.execute(text(f"SELECT * FROM {table_name} LIMIT 5"))
|
||
keys = list(result.keys())
|
||
print(f"欄位: {keys}")
|
||
for row in result:
|
||
print(row)
|
||
|
||
# 特別檢查 '狀態' 欄位 (如果存在)
|
||
if '狀態' in keys:
|
||
print("\n--- '狀態' 欄位值範例 (確認是否為文字) ---")
|
||
status_sample = conn.execute(text(f"SELECT DISTINCT \"狀態\" FROM {table_name} LIMIT 10")).fetchall()
|
||
print([r[0] for r in status_sample])
|
||
except Exception as e:
|
||
print(f"❌ 讀取資料失敗: {e}")
|
||
else:
|
||
print("ℹ️ 資料表存在但無資料 (空表)。")
|
||
|
||
except Exception as e:
|
||
print(f"❌ 資料庫連接或查詢失敗: {e}")
|
||
print("👉 請確認 app.py 是否已關閉 (可能鎖定了資料庫檔案)")
|
||
|
||
if __name__ == "__main__":
|
||
inspect_sales_data() |