Team Ai
Apppublic

prazy1208/text2sql

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
BACKFILL_SESSIONS.md47 linesDownload Raw Back to docs
1# Backfill session `title` and `client_id`2 3The chat sidebar calls **`GET /sessions?client_id=…`** and only returns rows where **`sessions.client_id`** equals that UUID **and** the session has at least one **`chat_messages`** row. Legacy rows with **`client_id` NULL** do **not** appear until you backfill.4 5## 1. Title backfill6 7[`scripts/backfill_session_metadata.sql`](../scripts/backfill_session_metadata.sql) sets **`sessions.title`** from the **first user** message in **`chat_messages`** (whitespace collapsed, max 60 characters). It only updates rows where **`title` IS NULL or blank**.8 9## 2. `client_id` backfill (so old chats show in your browser)10 11Use the **same UUID** as in the browser: **DevTools → Application → Local Storage → `text2sql_client_id`**.12 13```bash14python scripts/run_backfill_session_metadata.py --client-id "YOUR-UUID-HERE"15```16 17Or set in **`.env`** (not committed):18 19```env20BACKFILL_CLIENT_ID=YOUR-UUID-HERE21```22 23Then:24 25```bash26python scripts/run_backfill_session_metadata.py27```28 29That updates every session that **has at least one chat message** and **`client_id` IS NULL**, assigning your browser id. New sessions created by the app already set `client_id` from the UI.30 31**Shared database:** only run this UUID for sessions that **should** belong to that browser. Do not assign one person’s UUID to everyone’s historical rows.32 33## What the Python script does34 351. Runs the SQL file above (**titles**).362. If **`--client-id`** or **`BACKFILL_CLIENT_ID`** is set, runs a parameterized **`UPDATE`** for **`client_id`** on NULL rows that have messages.37 38## Manual SQL39 40You can still paste section **1** from the `.sql` file in pgAdmin / Supabase. For **`client_id`**, prefer the Python command so you do not edit UUIDs inside the SQL file.41 42Section **3** in the SQL file (commented) deletes empty shell sessions if you want to clean those rows.43 44## After backfill45 46Restart the API if needed, hard-refresh the UI, and confirm the sidebar lists your chats.47