+
    Uj                        R t ^ RIHt ^ RIt^ RIt]P
                  ! R]P                  4      tR tR R lt	R t
R R	 ltRR
 R lltRR R lltR# )u  Ultron master DB logic for the jarvis-tools service (Railway).
Full Supabase SQL (read + write). Creds from env SUPABASE_URL +
SUPABASE_DB_PASSWORD. Seatbelt on drop/truncate/where-less delete. Isolated from
the memory service (psycopg only — no ML deps).
)annotationsNz\b(drop|truncate)\bc                    \         P                  P                  RR4      p \         P                  P                  RR4      pV '       d	   V'       g   R# \        P                  ! RV 4      pV'       g   R# VP                  ^4      p\         P                  P                  RR4      pV'       d1   V\        \         P                  P                  RR4      4      R	V 2V3# R
V R2RRV3# )u   (host, port, user, password). Prefers the IPv4 pooler when
SUPABASE_POOLER_HOST is set (required from Railway — the direct
db.<ref>.supabase.co host is IPv6-only and unreachable there). Falls back to
the direct connection otherwise (fine from a Mac/VPS).SUPABASE_URL SUPABASE_DB_PASSWORDNz//([^.]+)\.SUPABASE_POOLER_HOSTSUPABASE_POOLER_PORT5432z	postgres.zdb.z.supabase.coi8  postgres)osenvirongetresearchgroupint)urlpwmrefpoolers        ultron_db.py_credsr      s    
 **..
,C	.	3BB
		.#&A
''!*CZZ^^2B7FBJJNN+A6JKC5!2' 	'#l#T:r::    c                   V ^8  d   QhRR/# )   returnbool )formats   "r   __annotate__r    "   s        D  r   c                     \        4       R J# )N)r   r   r   r   
configuredr"   "   s    84r   c                 f    ^ RI p \        4       w  rr4V P                  RV RV RV RV R2	^RR7      # )	    Nzhost=z port=z user=z
 password=z  dbname=postgres sslmode=requireT)connect_timeout
autocommit)psycopgr   connect)r'   hostportuserr   s        r   _connectr,   &   sQ    !8D??
vVD6vZt <* 	+<>4  Q Qr   c                    V ^8  d   QhRRRR/# )r   sqlstrr   r   r   )r   s   "r   r    r    .   s        r   c                    V P                  4       p\        P                  V4      '       d   R # \        P                  ! RV4      '       d/   \        P                  ! RV\        P
                  4      '       g   R # R# )Tz(?is)^\s*(delete|update)\bz	\bwhere\bF)strip_DANGERr   r   matchI)r.   ss   & r   _needs_confirmr6   .   sN    		A~~a	xx-q11		,24400r   c               $    V ^8  d   QhRRRRRR/# )r   r.   r/   confirmr   r   )r   s   "r   r    r    8   s!     9 9s 9S 9# 9r   c                   \        V 4      P                  4       p V '       g   R # \        V 4      '       d!   \        V4      P                  4       R8w  d   R# \	        4       ;_uu_ 4       pVP                  V 4      pVP                  '       d   VP                   Uu. uF  qDP                  NK  	  ppVP                  R4      pV'       g    RRR4       R# RP                  V4      pRP                  R V 4       4      p\        V4      R8X  d   R	MR
p	V RR\        V4      ,           RV V	 2p
V
R,          \        V
4      R8  d   RMR
,           uuRRR4       # RVP                   R2uuRRR4       # u upi   + '       g   i     R# ; i)zultron_query failed: no SQL.yesztThat statement is irreversible (drop/truncate or a WHERE-less delete/update). Re-send with confirm='yes' to proceed.i  Nz(0 rows) | 
c              3  R   "   T F  pR P                  R V 4       4      x  K  	  R# 5i)r;   c              3  B   "   T F  qf   RM
\        V4      x  K  	  R # 5i)Nr   )r/   ).0vs   & r   	<genexpr>"query.<locals>.<genexpr>.<genexpr>H   s     B12A6s   N)join)r?   rs   & r   rA   query.<locals>.<genexpr>G   s&      RLPq

BBBBDs   %'u   
…(first 500 rows)r   -:Ni  Ni  u    …[truncated]u   OK — z row(s) affected.)r/   r1   r6   lowerr,   executedescriptionname	fetchmanyrC   lenrowcount)r.   r8   conncurdcolsrowsheadbodymoreouts   &&         r   queryrW   8   s?   
c(..
C-cs7|113u<I	tll3???$'OO4OqFFOD4==%D! 
 ::d#D99 RLPR RD.1$i3.>*BDF"S3t9_-RvdV<Cu:c#ho!22N 
 &78 
 5 
s+   '2E7E2-E7A:E7E72E77F	c                    V ^8  d   QhRRRR/# )r   tabler/   r   r   )r   s   "r   r    r    O   s     R R# Rs Rr   c           
        \        V 4      P                  4       p \        4       ;_uu_ 4       pV '       g   VP                  R 4      P	                  4        Uu. uF  q"^ ,          NK  	  pp. pV FF  p VP                  RV R24      P                  4       ^ ,          pVP                  RV RV R24       KH  	  RRP                  V4      ,           uuR	R	R	4       # VP                  R
V 34      P	                  4       pV'       g   RV : R2uuR	R	R	4       # V  R2RP                  R V 4       4      ,           uuR	R	R	4       # u upi   \         d    Rp Li ; i  + '       g   i     R	# ; i)zWselect table_name from information_schema.tables where table_schema='public' order by 1zselect count(*) from ""?-  (z rows)zTables:
r<   Nzselect column_name, data_type from information_schema.columns where table_schema='public' and table_name=%s order by ordinal_positionzNo table named .z
 columns:
c              3  8   "   T F  w  rR V RV R2x  K  	  R# 5i)r]   r^   )Nr   )r?   cts   &  r   rA   schema.<locals>.<genexpr>d   s      0QDDA2aS1#QDs   )	r/   r1   r,   rH   fetchallfetchone	ExceptionappendrC   )rY   rN   rD   tabslinesrc   nrQ   s   &       r   schemarl   O   s_   JE	t"&,,9#::B(*#E F #EQaDD #ED F E'=aS%BCLLNqQA r!Bqc01  5!11 
 ||(*/3 4<8: 	 $UIQ/% 
& $tyy0QD0Q'QQ' 
F ! A 
sS   *ED?'	E1*E3E(EE!E?EE	EE	EE(	)r   )__doc__
__future__r   r   r   compiler4   r2   r   r"   r,   r6   rW   rl   r   r   r   <module>rp      sP   
 # 	 	
**+RTT
2;( Q9.R Rr   