50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Simple script to check if Neo4j migration has been completed
|
|
Returns exit code 0 if data exists, 1 if migration is needed
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
from neo4j import GraphDatabase
|
|
|
|
def check_migration_status():
|
|
"""Check if Neo4j has any price tier data (namespaced or non-namespaced)"""
|
|
try:
|
|
# Connect to Neo4j
|
|
uri = os.getenv('NEO4J_URI', 'bolt://localhost:7687')
|
|
user = os.getenv('NEO4J_USER', 'neo4j')
|
|
password = os.getenv('NEO4J_PASSWORD', 'password')
|
|
|
|
driver = GraphDatabase.driver(uri, auth=(user, password))
|
|
|
|
with driver.session() as session:
|
|
# Check for non-namespaced PriceTier nodes
|
|
result1 = session.run('MATCH (p:PriceTier) RETURN count(p) as count')
|
|
non_namespaced = result1.single()['count']
|
|
|
|
# Check for TSS namespaced PriceTier nodes
|
|
result2 = session.run('MATCH (p:PriceTier:TSS) RETURN count(p) as count')
|
|
tss_count = result2.single()['count']
|
|
|
|
total = non_namespaced + tss_count
|
|
|
|
print(f'Found {total} price tiers ({non_namespaced} non-namespaced, {tss_count} TSS)')
|
|
|
|
# Return 0 if data exists (migration complete), 1 if no data (migration needed)
|
|
if total > 0:
|
|
print('Migration appears to be complete')
|
|
return 0
|
|
else:
|
|
print('No data found - migration needed')
|
|
return 1
|
|
|
|
driver.close()
|
|
|
|
except Exception as e:
|
|
print(f'Error checking migration status: {e}')
|
|
return 1
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(check_migration_status())
|