_check_db.py
886 Bytes
import pymysql
from app.core.config import settings
conn = pymysql.connect(
host=settings.DB_HOST, port=settings.DB_PORT, user=settings.DB_USER,
password=settings.DB_PASSWORD, database=settings.DB_NAME, charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor,
)
with conn.cursor() as cur:
cur.execute("SELECT COUNT(*) as c FROM ods_strategy_info WHERE deleted_flag='N'")
strategy_count = cur.fetchone()['c']
cur.execute("SELECT COUNT(*) as c FROM ods_store_config WHERE deleted_flag='N'")
store_count = cur.fetchone()['c']
cur.execute("SELECT id, title, merchant_id, start_date, end_date, push_flag FROM ods_strategy_info WHERE deleted_flag='N' ORDER BY created_date DESC LIMIT 3")
rows = cur.fetchall()
print(f"strategy_count: {strategy_count}")
print(f"store_count: {store_count}")
for r in rows:
print(r)
conn.close()