Spaces:
No application file
No application file
File size: 1,891 Bytes
86cbe3c a0eb181 86cbe3c a0eb181 86cbe3c a0eb181 86cbe3c a0eb181 86cbe3c a0eb181 86cbe3c a0eb181 86cbe3c a0eb181 86cbe3c a0eb181 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 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())
|