+
    jHàjæ  ã                  óì   a € 0 t $ R t^ RIHt ^ RIt^ RIt^ RIHt ^ RIH	t	 ^ RI
HtHtHt ]P                  ! ]4      tRtRt]! R04      t]! 4       tR	]R
&   R R ltR R ltR R ltR R ltR R ltR# )a7  One-shot import of the pre-isolation ``hosted_room*`` rows into ``shared-state.db``.

``0e422e0ece`` repointed the room store from the root ``state.db`` to ``shared-state.db`` without
moving the rows it already held, so an install that had rooms started with an empty coordination
set and every pre-existing room resolved to "hosted room not found" (#109775). The first open after
the upgrade copies the rows across once; the marker row keeps that a one-shot step, because a purge
in THIS store must never be undone by re-importing rows the legacy store still holds.
)ÚannotationsN)Úclosing)ÚPath)ÚclockÚtable_columnsÚtable_existszstate.dbÚhosted_room_legacy_importsÚhosted_room_driver_leasesz	set[Path]Ú_failed_sourcesc               ó    € V ^8„  d   QhRRRR/# )é   Údb_pathr   ÚreturnzPath | None© )Úformats   "ÚG/home/ubuntu/.hermes/hermes-agent/gateway/hosted_rooms_legacy_import.pyÚ__annotate__r       s   € ÷ Yñ Y˜ð Y +ñ Yó    c                óR   € V P                   R8X  d   V P                  \        4      # R# )zÜThe pre-isolation store for ``db_path``, or ``None`` when this database has no predecessor.

Only the shared coordination database has one: callers that pass any other path (older
layouts, tests) own that file directly.
zshared-state.dbN)ÚnameÚ	with_nameÚSOURCE_NAME)r   s   &r   Úsource_pathr       s'   € ð .5¯\©\Ð=NÔ-Nˆ7×Ñœ[Ó)ÐXÐTXÐXr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úconnúsqlite3.Connectionr   r   r   Úboolr   )r   s   "r   r   r   )   s'   € ÷ _ñ _Ð$ð _¨tð _¸ñ _r   c                óÈ   € \        V4      pVe   V\        9   d   R# \        V \        4      ;'       d0    V P	                  R\         R2\
        34      P                  4       RJ# )ziTrue once the import for this database has been recorded, given up on for this process, or never applies.NTzSELECT 1 FROM z WHERE source=?)r   r
   r   ÚMARKER_TABLEÚexecuter   Úfetchone)r   r   Úsources   && r   Úsettledr"   )   sc   € ä˜Ó!€FØ‚~˜¤?Ô2ÙÜ˜œlÓ+÷ _ð _°·±Ø
œ˜ oÐ6¼¸ó1HßHPÉË
ÐZ^ð1_ð _r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úlegacyr   Útargetr   Ústrr   zlist[tuple[str, str]]r   )r   s   "r   r   r   2   s,   € ÷ ñ Ð 2ð Ð<Nð ÐVYð Ð^sñ r   c           
     óŒ  aaa€ ^ RI Hp V UUUUu/ uF  w  rErgVf   K  WE3VbK  	  pppppV P                  RS R24       U	u. uF  p	\        V	^,          4      NK  	  up	o\	        VS4      oS Uu. uF  qUS9   g   K  WU3NK  	  p
pV
P                  VVV3R lVP                  4        4       4       V
# u uppppi u up	i u upi )ao  ``(target column, source expression)`` pairs for copying ``name``.

Columns only the target has take the same default the in-place column migration applies, so a
legacy layout from before the actor/authority columns imports instead of tripping NOT NULL.
Columns only the source has are dropped; columns the target added without a default are left
to its DDL default.
)Ú_LEGACY_COLUMNSzPRAGMA table_info(Ú)c              3  ój   <"  € T F(  w  w  rpVS8X  g   K  VS9   g   K  VS9  g   K#  W#3x € K*  	  R # 5i©Nr   )Ú.0ÚtableÚcolumnÚdefaultr   Úsource_columnsÚtarget_columnss   &   €€€r   Ú	<genexpr>Ú&_select_expressions.<locals>.<genexpr>@   sG   øé € ð aÑCSÑ'?¡¨¸Ø˜T‘Mô #Ø&,°Ñ&>ô #ØCIÐQ_ÑC_ô #�&Õ"ÓCSùs   ƒ3–3Ÿ3¨3)Úgateway.hosted_roomsr(   r   r&   r   ÚextendÚitems)r$   r%   r   r(   r-   r.   Ú_r/   ÚdefaultsÚrowÚpairsr0   r1   s   &&f        @@r   Ú_select_expressionsr;   2   sÀ   ú€ õ 5áJYÖqÉ/Ñ-F¨U¸AÐ]dÔ(�� Ò(É/€HÓqØ-3¯^©^Ð>PÐQUÐPVÐVWÐ<XÔ-YÓZÑ-Y c”c˜#˜a�&–kÑ-YÑZ€NÜ" 6¨4Ó0€NÙ,:ÓW©N &ÈÑ>VÔˆfÓ©N€EÐWØ	‡L�Lö aÀ8Ç>Á>ÔCSó aô aà€Lùõ rùÚZùâWs   ‘	B4
ŸB4
ÁB<Á1CÁ>Cc               ó$   € V ^8„  d   QhRRRRRR/# )r   r%   r   r!   r   r   Úintr   )r   s   "r   r   r   E   s"   € ÷ +ñ +Ð)ð +°4ð +¸Cñ +r   c                ó˜  aa€ ^ RI Hp . pV P                  R4       Uu0 uF  p\        V^ ,          4      kK  	  upo\	        \
        P                  ! RV R2R^
R7      4      ;_uu_ 4       pVP                  R4       Uu. uF  p\        V^ ,          4      NK  	  pp\        VR R	7       EF…  pV\        9   g#   V\        8X  g   VP                  R4      '       d   K3  \        W4      '       gA   V P                  \        VP                  R
V34      P                  4       ^ ,          4      4       \        WPV4      pV'       g   Kš  V U	U
u. uF  w  ršV	NK	  	  pp	p
VP                  RRP                  R V 4       4       RV 24      pRV9   d"   VP                  R4      oVV3R lV 4       pRpMRpVR8X  d-   \!        V4      pV Uu. uF  p\        VS,          4      NK  	  ppV P#                  V RV RRP                  V4       RRP                  R\%        V4      ,          4       R2V4       EKˆ  	  V'       dW   R\'        VR4      9  dF   V P                  VP)                  RRP                  R\%        V4      ,          4       R2R7      V4       RRR4       \%        V4      # u upi u upi u up
p	i u upi   + '       g   i     L0; i)uo  Copy every room ``target`` does not have yet, with all of its child rows; returns rooms copied.

A room id present in both stores is skipped as a unit: grafting the legacy events under this
store's room would leave ``next_seq`` behind ``MAX(seq)`` and every later append colliding.
Room-scoped tables therefore use a plain INSERT â€” a row the target refuses raises and aborts
the whole import rather than being dropped in silence. A table this store has not created yet
(the driver, policy and replica schemas are initialized by their own modules) is created from
the source's own DDL so its rows survive the upgrade too.
)Ú_EVENT_BYTES_BACKFILLz SELECT room_id FROM hosted_roomszfile:z?mode=roT)ÚuriÚtimeoutzNSELECT name FROM sqlite_master WHERE type='table' AND name GLOB 'hosted_room*'c                ó   € V R 8g  V 3# )Úhosted_roomsr   )r   s   &r   Ú<lambda>Ú_copy_rows.<locals>.<lambda>W   s   € °D¸NÑ4JÈDÑ3Qr   )Úkeyz;SELECT sql FROM sqlite_master WHERE type='table' AND name=?zSELECT z, c              3  ó*   "  € T F	  w  rVx € K  	  R # 5ir+   r   )r,   r7   Úexprs   &  r   r2   Ú_copy_rows.<locals>.<genexpr>a   s   é € Ð5PÉ%¹w¸qµdË%ùs   ‚z FROM Úroom_idc              3  óZ   <"  € T F   p\        VS,          4      S9  g   K  Vx € K"  	  R # 5ir+   )r&   )r,   r9   ÚexistingÚ
room_indexs   & €€r   r2   rI   d   s#   øé € ÐT¡t ¬s°3°zµ?Ó/CÈ8Ñ/SŸš£tùs   ƒ+¡
+ÚINSERTzINSERT OR IGNORErC   z INTO z (z
) VALUES (Ú?r)   Úevent_byteszroom_id IN ()ÚwhereN)Ú_nextÚ
_migrating)r4   r?   r   r&   r   Úsqlite3ÚconnectÚsortedÚ_SKIP_TABLESr   Úendswithr   r    r;   ÚjoinÚindexÚlistÚexecutemanyÚlenr   r   )r%   r!   r?   Úcopied_roomsr9   r$   Únamesr   r:   r.   r7   ÚcolumnsÚrowsÚverbrL   rM   s   &&            @@r   Ú
_copy_rowsrc   E   s•  ù€ õ ;à €LØ'-§~¡~Ð6XÔ'YÓZÑ'Y ”�C˜•F–Ñ'YÑZ€HÜ	”—’ 5¨¨°Ð!9¸tÈRÔP×	QÔ	QÐU[Ø(.¯©Ø\ô)^ó _ñ )^ ”�S˜•V–ñ )^ˆð _ô ˜5Ñ&Q×RÐRˆDØ”|Ô# t¬|Ô';¸t¿}¹}ÐMd×?eÒ?eÙÜ ×-Ò-Ø—‘œs 6§>¡>ØQÐTXÐSZó$\ß\dÑ\dÓ\fÐghõ$jó  kô lä'¨¸Ó=ˆEßÙÙ/4Ô5©u¡) &“v©uˆGÑ5Ø—>‘> G¨D¯I©IÑ5PÉ%Ó5PÓ,PÐ+QÐQWÐX\ÐW]Ð"^Ó_ˆDØ˜GÔ#Ø$Ÿ]™]¨9Ó5�
ÝT¡tÓT�Ø‘à)�Ø�~Ô%Ü˜D“z�Ù@DÓEÁ¸¤ C¨
¥OÖ 4Á�ÐEØ×ÑØ�&˜˜t˜f B t§y¡y°Ó'9Ð&:¸*ÀTÇYÁYÈsÔUXÐY`ÓUaÕOaÓEbÐDcÐcdÐeÐgk÷mñ) S÷, ˜M´¸vÀ~Ó1VÔVØ�N‰NØ%×,Ñ,°\À$Ç)Á)ÈCÔRUÐVbÓRcÕLcÓBdÐAeÐefÐ3gÐ,ÓhÐjvôx÷7 
Rô: ˆ|ÓÐùò= [ùò_ùó 6ùò  F÷/ 
R×	QúsE   žJ$Á*J9Á>J)ÂB/J9ÅJ.ÅA0J9ÇJ4
Ç AJ9È;AJ9Ê)J9Ê9K		c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   r   r   r   ÚNoner   )r   s   "r   r   r   s   s'   € ÷ eñ eÐ0ð e¸4ð eÀDñ er   c                óˆ  € \        V4      pVe   \        W4      '       d   R# V P                  R4        VP                  4       '       d   \	        W4      M^ pT P                  R\         R24       T P                  R\         R	2\        \        R4      T34       T P                  R4       T'       d   \        P                  R
Y24       R# R#   \
        \        P                  3 dY   pT P                  R4       T P                  R4       \        P                  T4       \        P                  RY$4        Rp?R# Rp?ii ; i)züCopy the pre-isolation rows in once, then record the marker; never fails the open.

The copy runs inside the caller's schema transaction under its own savepoint, so a crash or a
refused row leaves either both the copied rows and the marker or neither.
NzSAVEPOINT legacy_importzROLLBACK TO legacy_importzRELEASE legacy_importzVhosted rooms: could not import the pre-isolation %s (%s); will retry on the next startzCREATE TABLE IF NOT EXISTS zM (source TEXT PRIMARY KEY, imported_at REAL NOT NULL, rooms INTEGER NOT NULL)zINSERT OR IGNORE INTO z. (source, imported_at, rooms) VALUES (?, ?, ?)z=hosted rooms: imported %d pre-isolation Group Chat(s) from %s)r   r"   r   Úis_filerc   ÚOSErrorrT   ÚErrorr
   ÚaddÚloggerÚwarningr   r   r   Úinfo)r   r   r!   ÚcopiedÚexcs   &&   r   Úimport_legacy_roomsrp   s   s  € ô ˜Ó!€FØ‚~œ ×/Ò/ÙØ‡L�LÐ*Ô+ð
Ø-3¯^©^×-=Ò-=”˜DÔ)À1ˆð 	‡L�LØ
%¤l ^ð  4Að  	BôCà‡L�LØ
 ¤ Ð.\Ð]Ü	”e˜D“k 6Ð*ô,ð 	‡L�LÐ(Ô)ßÜ�‰ÐSÐU[Ödñ øô ”W—]‘]Ð#ô ð 	�‰Ð0Ô1Ø�‰Ð,Ô-Ü×Ñ˜FÔ#Ü�‰ÐoØô	$åûðús   µC ÁC ÃEÃ)AD<Ä<E)Ú__conditional_annotations__Ú__doc__Ú
__future__r   ÚloggingrT   Ú
contextlibr   Úpathlibr   Úgateway.hosted_rooms_commonr   r   r   Ú	getLoggerÚ__name__rk   r   r   Ú	frozensetrW   Úsetr
   Ú__annotations__r   r"   r;   rc   rp   )rq   s   @r   Ú<module>r}      sw   øðôõ #ã Û Ý Ý ç JÑ Jà	×	Ò	˜8Ó	$€à€Ø+€ñ Ð5Ð6Ó7€ñ !›U€�Ó "õYõ_õõ&+÷\er   