Files
nanocode/new-media-platform/website-new/backend/check_old_news.py
T
Ubuntu 32b43f85bd a
2026-07-03 16:58:28 +08:00

41 lines
1.8 KiB
Python

from sqlalchemy import create_engine, text
engine = create_engine('sqlite:///cms.db')
with engine.connect() as conn:
# 老表数量
print("=== 老数据量 ===")
for row in conn.execute(text("SELECT COUNT(*) FROM news_categories")):
print(f"news_categories: {row[0]} 条")
for row in conn.execute(text("SELECT COUNT(*) FROM news_posts")):
print(f"news_posts: {row[0]} 条")
# 新表数量
print("\n=== 新数据量 ===")
for row in conn.execute(text("SELECT COUNT(*) FROM columns")):
print(f"columns: {row[0]} 条")
for row in conn.execute(text("SELECT COUNT(*) FROM articles")):
print(f"articles: {row[0]} 条")
# 老表中 cover_image 有值的数量(即有图片的文章)
print("\n=== 老 news_posts 图片情况 ===")
for row in conn.execute(text("SELECT COUNT(*) FROM news_posts WHERE cover_image IS NOT NULL AND cover_image != ''")):
print(f"有封面图的文章: {row[0]} 条")
# 新表中 cover_image 有值的数量
print("\n=== 新 articles 图片情况 ===")
for row in conn.execute(text("SELECT COUNT(*) FROM articles WHERE cover_image IS NOT NULL AND cover_image != ''")):
print(f"有封面图的文章: {row[0]} 条")
# 抽样对比图片路径是否一致
print("\n=== 图片路径抽样对比(前5条)===")
old_imgs = [r[0] for r in conn.execute(text(
"SELECT cover_image FROM news_posts WHERE cover_image IS NOT NULL AND cover_image != '' LIMIT 5"
))]
new_imgs = [r[0] for r in conn.execute(text(
"SELECT cover_image FROM articles WHERE cover_image IS NOT NULL AND cover_image != '' LIMIT 5"
))]
print("老 cover_image:")
for p in old_imgs: print(f" {p}")
print("新 cover_image:")
for p in new_imgs: print(f" {p}")