Files
ewoooc/tests/test_pg_sync.py
ogt 0099543c05
Some checks failed
CD Pipeline / deploy (push) Failing after 5m18s
fix(security): 全域健檢 — 40 項安全/Bug/品質修復
🔴 Critical
- auto_heal_service: 補 import re + sqlalchemy.text + 修正 orchestrator 變數名
  + autoheal_playbook→playbooks 表名 + _alert_and_store cooldown 修復
- aider_heal_executor: shell injection 改 shell=False + list 參數
- docker-compose: DISABLE_LOGIN 改 env var + 移除密碼 fallback + POSTGRES_HOST 修正
- app.py: /api/backup /api/run_task 等 6 個管理 API 加 @login_required
- config.py + pg_sync + e2e_test: 移除 wooo_pg_2026 hardcoded 密碼 fallback
- pg_backup.sh: 移除 TELEGRAM_TOKEN= 中間變數,直接用 $TELEGRAM_BOT_TOKEN
- migration 014: trigger_pattern→match_pattern + 補 error_type NOT NULL 欄位

🟡 High
- telegram_bot_service: str(e) 改通用訊息 + session try/finally + 移除 pa:/pr: 舊 callback
- run_scheduler: ElephantAlpha thread 死亡監控 + 自動重啟 + Telegram 告警
  + agent_context 03:30 TTL 定時清理任務
- openclaw_learning_service: build_rag_context 兩路徑加 .limit(200)
- hooks: commit-quality + momo-prod-guard 空 catch 改 stderr+exit(1)
- scripts/code_review: auto_yes 預設改 false
- db_backup_service: PGPASSWORD 透過 env dict 傳遞

📦 Migrations
- 013_autoheal: 修正建表順序 playbooks→incidents(外鍵前向引用)
- 018_add_missing_indexes: heal_logs/incidents 外鍵索引 + cleanup_expired_agent_context()

🟢 Infrastructure
- requirements.txt: 加版本下界 Flask>=2.3 SQLAlchemy>=1.4 等
- cd.yaml: 新增 run_scheduler.py + run_telegram_bot.py 監聽路徑
- .gitignore: insert_playbook_local.py 加入忽略

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 01:12:23 +08:00

66 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""測試完整 76 欄位同步"""
import os
import sqlite3
import psycopg2
# 取得所有欄位
sqlite_conn = sqlite3.connect("data/momo_database.db")
cursor = sqlite_conn.cursor()
cursor.execute("PRAGMA table_info(realtime_sales_monthly)")
col_info = cursor.fetchall()
columns = [c[1] for c in col_info]
print(f"{len(columns)} 個欄位")
# 檢查特殊字元
special_chars = []
for i, col in enumerate(columns):
if "%" in col or "(" in col or ")" in col:
special_chars.append((i, col))
print(f"\n包含特殊字元的欄位: {len(special_chars)}")
for i, col in special_chars:
print(f" {i}: {col}")
# 測試完整 76 欄位同步
print("\n測試完整欄位同步...")
cursor.execute("SELECT * FROM realtime_sales_monthly LIMIT 10")
rows = cursor.fetchall()
pg_conn = psycopg2.connect(
host="localhost", port="5432",
user="momo", password=os.environ.get("POSTGRES_PASSWORD"),
database="momo_analytics"
)
pg_cursor = pg_conn.cursor()
# 建立表格
pg_cursor.execute("DROP TABLE IF EXISTS test_full76 CASCADE")
cols_def = ", ".join([f'"{c}" TEXT' for c in columns])
pg_cursor.execute(f"CREATE TABLE test_full76 (id SERIAL PRIMARY KEY, {cols_def})")
pg_conn.commit()
print("表建立成功")
# 插入資料
cols_sql = ", ".join([f'"{c}"' for c in columns])
placeholders = ", ".join(["%s"] * len(columns))
sql = f"INSERT INTO test_full76 ({cols_sql}) VALUES ({placeholders})"
success_count = 0
for i, row in enumerate(rows):
try:
pg_cursor.execute(sql, tuple(row))
success_count += 1
except Exception as e:
print(f"{i} 筆失敗: {e}")
pg_conn.rollback()
pg_conn.commit()
print(f"成功插入: {success_count}/{len(rows)}")
pg_cursor.execute("DROP TABLE test_full76 CASCADE")
pg_conn.commit()
pg_conn.close()
sqlite_conn.close()