forked from MLakshmi-191203/Dynamic_etl_framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema_validation.py
More file actions
37 lines (25 loc) · 843 Bytes
/
Copy pathschema_validation.py
File metadata and controls
37 lines (25 loc) · 843 Bytes
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
# schema_validation.py
from schema_engine import (
get_existing_metadata,
detect_schema_changes,
insert_metadata
)
def validate_or_capture_schema(conn, config, source_schema):
print("🔎 Checking schema for:", config["source_table"])
existing_meta = get_existing_metadata(
conn,
config["source_system"],
config["source_table"]
)
actions = detect_schema_changes(source_schema, existing_meta)
# 🟢 FIRST RUN
if not existing_meta:
print("🆕 First run → capturing metadata")
insert_metadata(conn, config, actions)
print("✅ Metadata stored")
return
# 🔴 NEXT RUN
if actions:
print("❌ Schema change detected:", actions)
raise Exception(f"Schema mismatch: {actions}")
print("✅ Schema validation passed")