-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_schema_generation.py
More file actions
56 lines (43 loc) · 1.8 KB
/
Copy pathtest_schema_generation.py
File metadata and controls
56 lines (43 loc) · 1.8 KB
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
53
54
55
56
#!/usr/bin/env python3
"""
Test script to validate schema generation before full migration
"""
from couchdb_converter.couchdb_schema_analyzer import CouchDBSchemaAnalyzer
from couchdb_converter.couchdb2mysql import CouchDBSQLBuilder
import json
def test_schema_generation():
print("Testing CouchDB Schema Generation")
print("=" * 50)
# Initialize analyzer
analyzer = CouchDBSchemaAnalyzer('http://admin:root@localhost:5984', 'nosql2sql_test')
# Analyze documents
print("Step 1: Analyzing documents...")
if not analyzer.analyze_documents():
print("❌ Document analysis failed")
return
print("✅ Document analysis successful")
# Generate schema recommendations
print("\nStep 2: Generating schema recommendations...")
schema = analyzer.generate_schema_recommendations()
print(f"✅ Generated schema with {len(schema['tables'])} tables:")
for table_name in schema['tables'].keys():
print(f" - {table_name}")
# Test SQL generation
print("\nStep 3: Testing SQL generation...")
try:
sql_builder = CouchDBSQLBuilder(schema)
create_statements = sql_builder.generate_all_create_statements()
print(f"✅ Generated {len(create_statements)} CREATE statements")
print("\nStep 4: Showing generated SQL:")
for i, sql in enumerate(create_statements):
table_name = sql.split()[5].strip('`')
print(f"\n--- Table {i+1}: {table_name} ---")
print(sql)
except Exception as e:
print(f"❌ SQL generation failed: {e}")
import traceback
traceback.print_exc()
return
print("\n✅ All tests passed! Schema generation is working correctly.")
if __name__ == "__main__":
test_schema_generation()