Mazenbs commited on
Commit
24684f0
·
verified ·
1 Parent(s): e2befa1

Update supabase_utils.py

Browse files
Files changed (1) hide show
  1. supabase_utils.py +21 -19
supabase_utils.py CHANGED
@@ -82,25 +82,27 @@ def save_law_to_supabase(law_json):
82
  section_id = res_sec.data[0]["id"]
83
 
84
  # إدراج المواد
85
- for art in sec.get("articles", []):
86
- article_number = int(art.get("number")) if art.get("number") else None
87
- article_content = art.get("text", "")
88
- article_tables = art.get("tables", [])
 
89
 
90
- # UPSERT المواد بناءً على chapter_id و article_number
91
- res_art = (
92
- supabase.table("articles")
93
- .upsert(
94
- {
95
- "chapter_id": section_id,
96
- "article_number": article_number,
97
- "content": article_content or "",
98
- "tables": article_tables or [],
99
- },
100
- on_conflict=["chapter_id", "article_number"], # المفتاح الفريد للمواد
101
- )
102
- .execute()
103
- )
104
- article_id = res_art.data[0]["id"]
 
105
 
106
  print(f"✔ تم حفظ/تحديث جميع الأقسام والمواد والجداول للقانون: {title}")
 
82
  section_id = res_sec.data[0]["id"]
83
 
84
  # إدراج المواد
85
+ # إدراج المواد
86
+ for art in sec.get("articles", []):
87
+ article_number = int(art.get("number")) if art.get("number") else None
88
+ article_content = art.get("text", "")
89
+ article_tables = art.get("tables", [])
90
 
91
+ # UPSERT المواد بناءً على chapter_id و article_number مع id_law
92
+ res_art = (
93
+ supabase.table("articles")
94
+ .upsert(
95
+ {
96
+ "chapter_id": section_id,
97
+ "id_law": law_id, # ربط المادة بالقانون مباشرة
98
+ "article_number": article_number,
99
+ "content": article_content or "",
100
+ "tables": article_tables or [],
101
+ },
102
+ on_conflict=["chapter_id", "id_law", "article_number"], # المفتاح الفريد المركب للمواد
103
+ )
104
+ .execute()
105
+ )
106
+ article_id = res_art.data[0]["id"]
107
 
108
  print(f"✔ تم حفظ/تحديث جميع الأقسام والمواد والجداول للقانون: {title}")