@@ -40,7 +40,7 @@ pub async fn create_session(
4040 let bearer_token = generate_token ( ) ;
4141
4242 sqlx:: query (
43- "INSERT INTO sessions (id, merchant_id, deposit_txid, bearer_token, balance_zatoshis, balance_remaining, cost_per_request, requests_made, refund_address, status, expires_at)
43+ "INSERT INTO agent_sessions (id, merchant_id, deposit_txid, bearer_token, balance_zatoshis, balance_remaining, cost_per_request, requests_made, refund_address, status, expires_at)
4444 VALUES (?, ?, ?, ?, ?, ?, ?, 0, ?, 'active', strftime('%Y-%m-%dT%H:%M:%SZ', 'now', '+' || ? || ' hours'))"
4545 )
4646 . bind ( & id)
@@ -72,7 +72,7 @@ pub async fn create_session(
7272pub async fn get_session ( pool : & SqlitePool , session_id : & str ) -> Result < Option < Session > > {
7373 let row = sqlx:: query_as :: < _ , ( String , String , String , String , i64 , i64 , i64 , i64 , Option < String > , String , String , String , Option < String > ) > (
7474 "SELECT id, merchant_id, deposit_txid, bearer_token, balance_zatoshis, balance_remaining, cost_per_request, requests_made, refund_address, status, expires_at, created_at, closed_at
75- FROM sessions WHERE id = ?"
75+ FROM agent_sessions WHERE id = ?"
7676 )
7777 . bind ( session_id)
7878 . fetch_optional ( pool)
@@ -99,7 +99,7 @@ pub async fn validate_and_deduct(pool: &SqlitePool, bearer_token: &str) -> Resul
9999 // Atomic deduction: single UPDATE with WHERE guards prevents race conditions.
100100 // If balance < cost or session is expired/inactive, rows_affected == 0.
101101 let result = sqlx:: query (
102- "UPDATE sessions SET
102+ "UPDATE agent_sessions SET
103103 balance_remaining = balance_remaining - cost_per_request,
104104 requests_made = requests_made + 1
105105 WHERE bearer_token = ?
@@ -114,7 +114,7 @@ pub async fn validate_and_deduct(pool: &SqlitePool, bearer_token: &str) -> Resul
114114 if result. rows_affected ( ) == 0 {
115115 // Mark depleted/expired sessions so they don't linger
116116 sqlx:: query (
117- "UPDATE sessions SET status = CASE
117+ "UPDATE agent_sessions SET status = CASE
118118 WHEN expires_at < strftime('%Y-%m-%dT%H:%M:%SZ', 'now') THEN 'expired'
119119 WHEN balance_remaining < cost_per_request THEN 'depleted'
120120 ELSE status END
@@ -131,7 +131,7 @@ pub async fn validate_and_deduct(pool: &SqlitePool, bearer_token: &str) -> Resul
131131 // Read back the updated session state
132132 let row = sqlx:: query_as :: < _ , ( String , String , i64 , i64 , i64 , Option < String > ) > (
133133 "SELECT id, merchant_id, balance_remaining, cost_per_request, requests_made, refund_address
134- FROM sessions WHERE bearer_token = ?"
134+ FROM agent_sessions WHERE bearer_token = ?"
135135 )
136136 . bind ( bearer_token)
137137 . fetch_optional ( pool)
@@ -177,7 +177,7 @@ pub async fn close_session(pool: &SqlitePool, session_id: &str) -> Result<Option
177177 } ;
178178
179179 sqlx:: query (
180- "UPDATE sessions SET status = 'closed', closed_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now') WHERE id = ?"
180+ "UPDATE agent_sessions SET status = 'closed', closed_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now') WHERE id = ?"
181181 )
182182 . bind ( session_id)
183183 . execute ( pool)
@@ -219,7 +219,7 @@ pub async fn get_summary(pool: &SqlitePool, session_id: &str) -> Result<Option<S
219219pub async fn list_for_merchant ( pool : & SqlitePool , merchant_id : & str ) -> Result < Vec < Session > > {
220220 let rows = sqlx:: query_as :: < _ , ( String , String , String , String , i64 , i64 , i64 , i64 , Option < String > , String , String , String , Option < String > ) > (
221221 "SELECT id, merchant_id, deposit_txid, bearer_token, balance_zatoshis, balance_remaining, cost_per_request, requests_made, refund_address, status, expires_at, created_at, closed_at
222- FROM sessions WHERE merchant_id = ? ORDER BY created_at DESC LIMIT 100"
222+ FROM agent_sessions WHERE merchant_id = ? ORDER BY created_at DESC LIMIT 100"
223223 )
224224 . bind ( merchant_id)
225225 . fetch_all ( pool)
@@ -245,7 +245,7 @@ pub async fn list_for_merchant(pool: &SqlitePool, merchant_id: &str) -> Result<V
245245/// Check if a deposit txid has already been used for a session
246246pub async fn txid_already_used ( pool : & SqlitePool , txid : & str ) -> bool {
247247 sqlx:: query_scalar :: < _ , i64 > (
248- "SELECT COUNT(*) FROM sessions WHERE deposit_txid = ?"
248+ "SELECT COUNT(*) FROM agent_sessions WHERE deposit_txid = ?"
249249 )
250250 . bind ( txid)
251251 . fetch_one ( pool)
0 commit comments