Files
Ubuntu 32b43f85bd a
2026-07-03 16:58:28 +08:00

40 lines
1.8 KiB
Python

from sqlalchemy import create_engine, text
for db_name in ['app.db', 'cms.db', 'website.db']:
print(f"\n{'='*60}")
print(f"Database: {db_name}")
print('='*60)
try:
engine = create_engine(f'sqlite:///{db_name}')
with engine.connect() as conn:
tables = [r[0] for r in conn.execute(text("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"))]
print(f"Tables: {tables}")
if 'news_categories' in tables:
print("\n--- news_categories ---")
for row in conn.execute(text("SELECT id, name, slug, sort_order, is_enabled FROM news_categories ORDER BY id")):
print(row)
if 'news_posts' in tables:
print("\n--- news_posts count ---")
for row in conn.execute(text("SELECT COUNT(*) FROM news_posts")):
print(f"Total: {row[0]}")
print("\n--- news_posts sample ---")
for row in conn.execute(text("SELECT id, title, slug, category_id, is_published, view_count FROM news_posts LIMIT 5")):
print(row)
if 'columns' in tables:
print("\n--- columns ---")
for row in conn.execute(text("SELECT id, name, slug, parent_id, sort_order, is_enabled FROM columns ORDER BY id")):
print(row)
if 'articles' in tables:
print("\n--- articles count ---")
for row in conn.execute(text("SELECT COUNT(*) FROM articles")):
print(f"Total: {row[0]}")
print("\n--- articles sample ---")
for row in conn.execute(text("SELECT id, title, slug, column_id, status, view_count FROM articles LIMIT 5")):
print(row)
except Exception as e:
print(f"Error: {e}")