#!/usr/bin/env python3
"""
Create Law Library database tables
"""
import sys
import os
sys.path.insert(0, '/var/www/lawbot')

# Import after path is set
from app import app
from models import db, LawLibraryDocument

def create_tables():
    with app.app_context():
        # Create only the new law_library_documents table
        # This won't affect existing tables
        db.create_all()
        
        # Verify table creation
        from sqlalchemy import inspect
        inspector = inspect(db.engine)
        tables = inspector.get_table_names()
        
        if 'law_library_documents' in tables:
            print('✅ Law Library table created successfully!')
            
            # Show table structure
            columns = inspector.get_columns('law_library_documents')
            print(f'\nTable has {len(columns)} columns:')
            for col in columns[:5]:  # Show first 5 columns
                print(f'  - {col["name"]} ({col["type"]})')
            print(f'  ... and {len(columns)-5} more columns')
        else:
            print('❌ Failed to create law_library_documents table')
            print('Available tables:', ', '.join(tables))

if __name__ == '__main__':
    create_tables()