Peter Mutwiri commited on
Commit
d27ec68
·
1 Parent(s): 9ecdd73

refactored insert funtion in mapper

Browse files
Files changed (1) hide show
  1. app/mapper.py +3 -3
app/mapper.py CHANGED
@@ -447,9 +447,9 @@ def canonify_df(org_id: str, source_id: str, hours_window: int = 24) -> tuple[pd
447
  if is_new_schema:
448
  version_id = duck.execute("""
449
  INSERT INTO main.schema_versions (table_name, schema_json, status)
450
- VALUES (?, ?, 'pending') RETURNING version_id
451
- """, (f"{entity_type}_canonical", json.dumps(current_schema))).fetchone()[0]
452
- print(f"[canonify] 📝 Created schema v{version_id} for {entity_type}_canonical")
453
 
454
  # 8b) Ensure table exists with current schema
455
  table_name = ensure_canonical_table(duck, df, entity_type)
 
447
  if is_new_schema:
448
  version_id = duck.execute("""
449
  INSERT INTO main.schema_versions (table_name, schema_json, status)
450
+ VALUES (?, ?, 'pending')
451
+ """, (f"{entity_type}_canonical", json.dumps(current_schema)))
452
+ version_id = duck.execute("SELECT last_insert_rowid()").fetchone()[0]
453
 
454
  # 8b) Ensure table exists with current schema
455
  table_name = ensure_canonical_table(duck, df, entity_type)