migrate_db_phase1.py•1.83 kB
#!/usr/bin/env python3
"""
Database migration script for Phase 1: Documentation & Comments
Adds columns for inline_comments, todo_items, and design_notes
"""
import sqlite3
import sys
from pathlib import Path
def migrate_database(db_path: Path):
"""Add new columns for documentation extraction"""
if not db_path.exists():
print(f"Database not found at {db_path}")
return False
try:
conn = sqlite3.connect(str(db_path))
cursor = conn.cursor()
# Check if columns already exist
cursor.execute("PRAGMA table_info(symbols)")
columns = [col[1] for col in cursor.fetchall()]
new_columns = [
('inline_comments', 'TEXT'),
('todo_items', 'TEXT'),
('design_notes', 'TEXT')
]
for col_name, col_type in new_columns:
if col_name not in columns:
print(f"Adding column: {col_name}")
cursor.execute(f"ALTER TABLE symbols ADD COLUMN {col_name} {col_type}")
else:
print(f"Column {col_name} already exists")
conn.commit()
print("Migration completed successfully")
# Show updated schema
cursor.execute("PRAGMA table_info(symbols)")
print("\nUpdated schema:")
for col in cursor.fetchall():
print(f" {col[1]} ({col[2]})")
conn.close()
return True
except Exception as e:
print(f"Migration failed: {e}")
return False
if __name__ == "__main__":
project_root = Path(__file__).parent.parent
db_path = project_root / ".claude-symbols" / "search.db"
print(f"Migrating database at: {db_path}")
success = migrate_database(db_path)
sys.exit(0 if success else 1)