Big-Link-Man/scripts/check_orphaned_articles.py

47 lines
1.5 KiB
Python

"""
Check for articles assigned to deleted test sites
"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent))
from src.database.session import db_manager
from src.database.repositories import GeneratedContentRepository, SiteDeploymentRepository
def check_orphaned_articles():
"""Check for articles assigned to deleted test sites"""
db_manager.initialize()
session = db_manager.get_session()
content_repo = GeneratedContentRepository(session)
site_repo = SiteDeploymentRepository(session)
deleted_site_ids = [398, 399, 400, 401]
try:
# Query articles assigned to deleted sites
from src.database.models import GeneratedContent
orphaned = session.query(GeneratedContent).filter(
GeneratedContent.site_deployment_id.in_(deleted_site_ids)
).all()
if orphaned:
print(f"Found {len(orphaned)} articles assigned to deleted test sites:")
for article in orphaned:
print(f" Article {article.id}: '{article.title}' -> site_deployment_id={article.site_deployment_id}")
print(f"\nThese articles should be reassigned or deleted.")
else:
print("No orphaned articles found. All good!")
except Exception as e:
print(f"Error: {e}")
import traceback
traceback.print_exc()
finally:
session.close()
if __name__ == "__main__":
check_orphaned_articles()