scripts-query-work-items
#!/usr/bin/env python3 """
title: "Query Work Items" component_type: script version: "1.0.0" audience: contributor status: stable summary: "Query Work Item Hierarchy Database" keywords: ['database', 'items', 'query', 'work'] tokens: ~500 created: 2025-12-22 updated: 2025-12-22 script_name: "query-work-items.py" language: python executable: true usage: "python3 scripts/query-work-items.py [options]" python_version: "3.10+" dependencies: [] modifies_files: false network_access: false requires_auth: false
Query Work Item Hierarchy Database
Quick verification script to query initialized database.
Usage: python3 scripts/query-work-items.py """
import sqlite3 import sys from pathlib import Path
SCRIPT_DIR = Path(file).parent REPO_ROOT = SCRIPT_DIR.parent
ADR-118: Work items are in sessions.db (Tier 3 - session/task data)
sys.path.insert(0, str(SCRIPT_DIR / "core")) try: from paths import SESSIONS_DB DB_PATH = SESSIONS_DB except ImportError: # Fallback for backward compatibility _user_data = Path.home() / "PROJECTS" / ".coditect-data" / "context-storage" if _user_data.exists(): DB_PATH = _user_data / "sessions.db" else: DB_PATH = REPO_ROOT / "context-storage" / "sessions.db"
def main(): conn = sqlite3.connect(DB_PATH) conn.row_factory = sqlite3.Row cursor = conn.cursor()
print("\n" + "=" * 70)
print("Work Item Hierarchy Database - Quick Query")
print("=" * 70 + "\n")
# Query projects
print("PROJECTS:")
print("-" * 70)
cursor.execute("SELECT * FROM projects")
for row in cursor.fetchall():
print(f" {row['id']}: {row['name']}")
print(f" Status: {row['status']}")
print(f" Owner: {row['owner']}")
print()
# Query sub-projects
print("SUB-PROJECTS:")
print("-" * 70)
cursor.execute("SELECT * FROM sub_projects")
for row in cursor.fetchall():
print(f" {row['id']}: {row['name']}")
print(f" Project: {row['project_id']}")
print(f" Path: {row['path']}")
print()
# Query sprints
print("SPRINTS:")
print("-" * 70)
cursor.execute("SELECT * FROM sprints")
for row in cursor.fetchall():
print(f" {row['id']}: {row['name']}")
print(f" Project: {row['project_id']}")
print(f" Goal: {row['goal']}")
print(f" Duration: {row['start_date']} to {row['end_date']}")
print(f" Status: {row['status']}")
print()
# Query work items
print("WORK ITEMS:")
print("-" * 70)
cursor.execute("SELECT * FROM work_items")
rows = cursor.fetchall()
if rows:
for row in rows:
print(f" {row['id']}: {row['title']}")
print(f" Type: {row['type']}")
print(f" Status: {row['status']}")
print()
else:
print(" No work items yet. Use /epic, /feature, /task to create.")
print()
# Query project progress view
print("PROJECT PROGRESS (from view):")
print("-" * 70)
cursor.execute("SELECT * FROM project_progress")
for row in cursor.fetchall():
print(f" {row['project_name']}")
print(f" Status: {row['project_status']}")
print(f" Sub-Projects: {row['sub_project_count']}")
print(f" Epics: {row['epic_count']}, Features: {row['feature_count']}, Tasks: {row['task_count']}")
print(f" Progress: {row['percent_complete']}% complete")
print()
conn.close()
print("=" * 70)
print("Database query complete.")
print("=" * 70 + "\n")
if name == "main": main()