Spaces:
No application file
No application file
| import os | |
| import sys | |
| import logging | |
| import asyncio | |
| # The script runs inside the 'mcp' container where the WORKDIR is '/app'. | |
| # The 'core' module is at '/app/core'. We need to add '/app' to the Python path. | |
| sys.path.insert(0, '/app') | |
| from core.discovery import discover_all_schemas | |
| from core.graph import import_schema, close_graph_driver | |
| logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | |
| logger = logging.getLogger(__name__) | |
| async def main(): | |
| """ | |
| Main asynchronous function to run the full schema discovery and ingestion process. | |
| """ | |
| logger.info("Starting schema ingestion process...") | |
| try: | |
| # Step 1: Discover schemas from all connected SQLite databases | |
| logger.info("Discovering schemas from all databases...") | |
| all_schemas = await discover_all_schemas() | |
| if not all_schemas: | |
| logger.warning("No schemas were discovered. Ingestion cannot proceed.") | |
| return | |
| logger.info(f"Discovered {len(all_schemas)} schemas. Now ingesting into Neo4j...") | |
| # Step 2: Import each discovered schema into Neo4j | |
| for schema_data in all_schemas: | |
| try: | |
| import_schema(schema_data) | |
| logger.info(f"Successfully ingested schema for: {schema_data['database_name']}") | |
| except Exception as e: | |
| logger.error(f"Failed to ingest schema for {schema_data['database_name']}: {e}", exc_info=True) | |
| logger.info("Schema ingestion process completed successfully.") | |
| except Exception as e: | |
| logger.critical(f"A critical error occurred during the ingestion process: {e}", exc_info=True) | |
| finally: | |
| # Step 3: Ensure all connections are closed | |
| close_graph_driver() | |
| logger.info("Neo4j connection closed.") | |
| if __name__ == "__main__": | |
| asyncio.run(main()) | |