This commit is contained in:
Peter Howell 2025-08-29 23:44:30 +00:00
parent 6030dc04f9
commit d49e0d0c17
1 changed files with 24 additions and 48 deletions

View File

@ -783,23 +783,7 @@ def insert_usefulinfo_record(parsed):
pass pass
print("[usefulinfo][tag-link-failed] summary_id=", summary_id, " tag=", t, " error=", str(ex_tag_link)) print("[usefulinfo][tag-link-failed] summary_id=", summary_id, " tag=", t, " error=", str(ex_tag_link))
# Determine schema variant for events (legacy column vs link table) # Events (standardized: insert into event table, then link in summary_event)
has_event_summary_col = False
has_link_table = True
try:
CUR.execute("SELECT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='useful_info_event' AND column_name='summary_id')")
row = CUR.fetchone()
has_event_summary_col = bool(row[0]) if row else False
except Exception as ex_chk1:
print('[usefulinfo][diag] failed to probe useful_info_event.summary_id:', str(ex_chk1))
try:
CUR.execute("SELECT to_regclass('useful_info_summary_event')")
row = CUR.fetchone()
has_link_table = bool(row and row[0])
except Exception as ex_chk2:
print('[usefulinfo][diag] failed to probe useful_info_summary_event presence:', str(ex_chk2))
# Events
if summary_id and isinstance(events, list): if summary_id and isinstance(events, list):
for idx, e in enumerate(events, start=1): for idx, e in enumerate(events, start=1):
# Diagnostics: validate dt and length # Diagnostics: validate dt and length
@ -857,40 +841,29 @@ def insert_usefulinfo_record(parsed):
try: try:
CUR.execute("SAVEPOINT sp_event") CUR.execute("SAVEPOINT sp_event")
if has_event_summary_col: CUR.execute(
CUR.execute( """
""" INSERT INTO useful_info_event (dt, length, title, description)
INSERT INTO useful_info_event (summary_id, dt, length, title, description) VALUES (%s, %s, %s, %s)
VALUES (%s, %s, %s, %s, %s) RETURNING id
RETURNING id """,
""", (normalized_dt, raw_len, raw_title, raw_desc)
(summary_id, normalized_dt, raw_len, raw_title, raw_desc) )
)
else:
CUR.execute(
"""
INSERT INTO useful_info_event (dt, length, title, description)
VALUES (%s, %s, %s, %s)
RETURNING id
""",
(normalized_dt, raw_len, raw_title, raw_desc)
)
evrow = CUR.fetchone() evrow = CUR.fetchone()
if evrow and evrow[0]: if evrow and evrow[0]:
if has_link_table: try:
CUR.execute("SAVEPOINT sp_evlink")
CUR.execute(
"INSERT INTO useful_info_summary_event (summary_id, event_id) VALUES (%s, %s) ON CONFLICT DO NOTHING",
(summary_id, evrow[0])
)
CUR.execute("RELEASE SAVEPOINT sp_evlink")
except Exception as ex_evlink:
try: try:
CUR.execute("SAVEPOINT sp_evlink") CUR.execute("ROLLBACK TO SAVEPOINT sp_evlink")
CUR.execute( except Exception:
"INSERT INTO useful_info_summary_event (summary_id, event_id) VALUES (%s, %s) ON CONFLICT DO NOTHING", pass
(summary_id, evrow[0]) print("[usefulinfo][event-link-failed] summary_id=", summary_id, " event_id=", evrow[0], " error=", str(ex_evlink))
)
CUR.execute("RELEASE SAVEPOINT sp_evlink")
except Exception as ex_evlink:
try:
CUR.execute("ROLLBACK TO SAVEPOINT sp_evlink")
except Exception:
pass
print("[usefulinfo][event-link-failed] summary_id=", summary_id, " event_id=", evrow[0], " error=", str(ex_evlink))
print(f"[usefulinfo] inserted event id={evrow[0]} (summary_id={summary_id}) dt='{dt_str}' parsed={parsed_ok} iso='{parsed_iso}' all_day={all_day} minutes={computed_minutes} title='{raw_title}'") print(f"[usefulinfo] inserted event id={evrow[0]} (summary_id={summary_id}) dt='{dt_str}' parsed={parsed_ok} iso='{parsed_iso}' all_day={all_day} minutes={computed_minutes} title='{raw_title}'")
else: else:
print(f"[usefulinfo][warn] no event id returned for dt='{dt_str}' title='{raw_title}'") print(f"[usefulinfo][warn] no event id returned for dt='{dt_str}' title='{raw_title}'")
@ -915,6 +888,9 @@ def insert_usefulinfo_record(parsed):
return summary_id return summary_id
## Migration/diagnostic helpers removed per request. Assume a clean schema created by init_usefulinfo_schema.
def export_usefulinfo_events_to_ics(filepath='cache/useful_info_events.ics'): def export_usefulinfo_events_to_ics(filepath='cache/useful_info_events.ics'):
"""Export events from useful info tables to an .ics file. """Export events from useful info tables to an .ics file.
- Attempts to parse dt and length into DTSTART/DTEND. - Attempts to parse dt and length into DTSTART/DTEND.