
    `gjn                    R    d Z ddlmZ ddlZddlZddZej                  dd       Zy)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.
    )annotationsNc                    	 | j                  d| d|        y# t        j                  $ r&}dt        |      j	                         v rY d}~y 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OperationalErrorstrlower)conntablecolumnddlexcs        I/root/.hermes/venv/lib/python3.12/site-packages/hermes_cli/sqlite_util.pyadd_column_if_missingr      sR    |E7,se<=## "c#hnn&66s    AAAAc              #     K   | j                  d       	 |  | j                  d       y# t        $ r- 	 | j                  d        # t        j                  $ r Y  w xY ww xY w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      sp      	LL"#	
 	X  	LL$ 	 '' 		s<   A$+ A$	A!AA!AA!AA!!A$)
r
   sqlite3.Connectionr   r   r   r   r   r   returnbool)r
   r   )__doc__
__future__r   
contextlibr   r   contextmanagerr        r   <module>r      s4    #  "  r   