
    (Gjn                    P    d Z ddlmZ ddlZddlZddZej        dd            ZdS )u  Shared SQLite primitives for the small per-profile / board stores.

The projects and kanban stores open WAL SQLite files with the same two
primitives — an idempotent column-add migration and an IMMEDIATE write
transaction. One definition here keeps the two stores from drifting.
    )annotationsNconnsqlite3.Connectiontablestrcolumnddlreturnboolc                    	 |                      d| d|            dS # t          j        $ r/}dt          |                                          v rY d}~dS  d}~ww xY w)aP  ``ALTER TABLE <table> ADD COLUMN <ddl>``, idempotent across races.

    Returns ``True`` when this call added the column. Swallows the
    ``duplicate column name`` error a concurrent migrator may have run first
    (issue #21708). ``column`` is the human-readable name for the call site;
    ``ddl`` carries the actual definition.
    zALTER TABLE z ADD COLUMN Tzduplicate column nameNF)executesqlite3OperationalErrorr   lower)r   r   r   r	   excs        </home/rurouni/.hermes/hermes-agent/hermes_cli/sqlite_util.pyadd_column_if_missingr      s|    <E<<s<<===t#   "c#hhnn&6&66655555s    A#AAAc              #     K   |                      d           	 | V  |                      d           dS # t          $ r. 	 |                      d           n# t          j        $ r Y nw xY w w xY w)a  An IMMEDIATE write transaction: at most one concurrent writer wins.

    The explicit ROLLBACK is guarded so a SQLite auto-rollback (no active
    transaction left under EIO / lock contention / corruption) cannot shadow
    the original exception with a spurious rollback error.
    zBEGIN IMMEDIATECOMMITROLLBACKN)r   	Exceptionr   r   )r   s    r   	write_txnr      s       	LL"###	


 	X    	LL$$$$' 	 	 	D	s,   4 
A,AA,A'$A,&A''A,)
r   r   r   r   r   r   r	   r   r
   r   )r   r   )__doc__
__future__r   
contextlibr   r   contextmanagerr        r   <module>r      sz     # " " " " "        "      r   