+
    ‚°ñj‰:  ã                   óö  € ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIH	t	 ^ RI
HtHt ^ RIHtHt RtRsRsR,t ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHtHt ^ RIH t H!t! ^ RI"H#t# ^ RI$H%t% ^ RI&H't' ^ RI(H)t) ^ RI*t+^ RI,t,RtR t/R t0R t1R t2R t3R t4R t5R t6R t7Rt8^^ut9t:R t;Rs<Rt=R t>R  t?R! t@R" tAR# tBR$ tCR%tDR-R& ltER'tFR( tGR) tHR* tIR+ tJR#   ]- d    ]P\                  ! RRR7        Loi ; i).é    N)Úclosing)Úlog_startup_warning)ÚFileLockÚTimeout)ÚargsÚdatabase_default_pathF)Úcommand)ÚConfig)ÚMigrationContext)ÚScriptDirectory)Úcreate_engineÚevent)ÚURLÚmake_url)ÚOperationalError)Úsessionmaker)Ú
StaticPool)ÚBaseTz"Database packages failed to import©Úexc_infoc                 ó   € \         # )z?
Temporary function to check if the dependencies are available
)Ú_DB_AVAILABLE© ó    Ú3C:\Ai_Coding\apps\studio\ComfyUI\app\database\db.pyÚdependencies_availabler   (   s
   € ô Ðr   c                 ó˜   € . p \          F  p \        P                  ! V4       K  	  V #   \         d    T P	                  T4        K?  i ; i)z3Names of the database packages that fail to import.)Ú_DEPENDENCIESÚ	importlibÚimport_moduleÚImportErrorÚappend)ÚmissingÚnames     r   Úmissing_dependenciesr%   /   sH   € à€Gßˆð	!Ü×#Ò# DÖ)ñ ð
 €Nøô ô 	!Ø�N‰N˜4× ð	!ús   �)©A	ÁA	c                 ó6   € \        4       ;'       d	    \        RJ# )zÎ
Temporary function to check if the database is available to create a session
During initial release there may be environmental issues (or missing dependencies) that prevent the database from being created
N)r   ÚSessionr   r   r   Úcan_create_sessionr(   :   s   € ô
 "Ó#×;Ð;¬°tÐ(;Ð;r   c                  ó¾  € \         P                  P                  \         P                  P                  \        4      R 4      p \         P                  P                  \         P                  P                  V R4      4      p\         P                  P                  \         P                  P                  V R4      4      p\        V4      pVP                  P                  RR\         P                  P                  V4      P                  RR4      4       VP                  RVP                  RR4      4       VP                  R\        4       P                  RR4      4       V# )	z../..zalembic.iniÚ
alembic_dbÚDEFAULTÚhereÚ%z%%Úscript_locationzsqlalchemy.url)ÚosÚpathÚjoinÚdirnameÚ__file__Úabspathr
   Úfile_configÚsetÚreplaceÚset_main_optionÚget_database_url)Ú	root_pathÚconfig_pathÚscripts_pathÚconfigs       r   Úget_alembic_configr>   B   sê   € Ü—‘—‘œRŸW™WŸ_™_¬XÓ6¸Ó@€IÜ—'‘'—/‘/¤"§'¡'§,¡,¨y¸-Ó"HÓI€KÜ—7‘7—?‘?¤2§7¡7§<¡<°	¸<Ó#HÓI€Lä�KÓ €Fð ×Ñ×Ñ˜9 f¬b¯g©g¯o©o¸kÓ.J×.RÑ.RÐSVÐX\Ó.]Ô^Ø
×ÑÐ,¨l×.BÑ.BÀ3ÈÓ.MÔNØ
×ÑÐ+Ô-=Ó-?×-GÑ-GÈÈTÓ-RÔSà€Mr   c                  óö   € \         P                  e   \         P                  # ^ R Ip \        P                  P                  V P                  4       R4      p\        P                  ! RVR7      P                  4       # )Nz
comfyui.dbÚsqlite)Údatabase)
r   Údatabase_urlÚfolder_pathsr/   r0   r1   Úget_user_directoryr   ÚcreateÚrender_as_string)rC   Údb_paths     r   r9   r9   Q   sV   € Ü×ÑÒ$Ü× Ñ Ð ãä�g‰g�l‰l˜<×:Ñ:Ó<¸lÓK€Gô �:Š:�h¨Ô1×BÑBÓDÐDr   c                  ó   € \         # ©N)r   r   r   r   Úget_legacy_default_db_pathrJ   ]   s   € Ü Ð r   c                  óŒ   € \        4       p V P                  R 4      '       d   \        V 4      P                  # \	        RV  R24      h)z
sqlite:///zUnsupported database URL 'z'.)r9   Ú
startswithr   rA   Ú
ValueError)Úurls    r   Úget_db_pathrO   a   s>   € Ü
Ó
€CØ
‡~�~�l×#Ò#Ü˜‹}×%Ñ%Ð%äÐ5°c°U¸"Ð=Ó>Ð>r   c           	      ó  € \         P                  e   R # \        4       pVf   R # \        P                  P                  V4      \        P                  P                  V 4      8X  d   R # \        P                  P                  V 4      '       g&   \        P                  P                  V4      '       g   R # VR,           p\        P                  P                  V4      '       d   R # \        P                  P                  VR,           4      '       dy    \        \        P                  ! V4      4      ;_uu_ 4       pVP                  R4      P                  4       w  p pR R R 4       X'       d   \        P                  ! RT R24       R # \        P                  ! W4       \         P"                  ! W 4       \        P$                  ! RV RV RV  R	24       R #   + '       g   i     L‚; i  \        P                   d    ^p Lži ; i)
Nz.bakz-walzPRAGMA wal_checkpoint(TRUNCATE)z Not relocating legacy database 'z@': its WAL could not be checkpointed, so it may still be in use.zRenamed legacy database 'z' to 'z' and copied it to 'Ú')r   rB   rJ   r/   r0   r4   Úexistsr   Úsqlite3ÚconnectÚexecuteÚfetchoneÚErrorÚloggingÚwarningr7   ÚshutilÚcopyÚinfo)rG   Úlegacy_db_pathÚbackup_pathÚlegacyÚbusyÚ_s   &     r   Úcopy_legacy_default_dbrb   i   so  € Ü×ÑÒ$Ùä/Ó1€NØÒÙä	‡w�w‡��~Ó&¬"¯'©'¯/©/¸'Ó*BÔBÙä	‡w�w‡~�~�g×Ò¤b§g¡g§n¡n°^×&DÒ&DÙà  6Õ)€KÜ	‡w�w‡~�~�k×"Ò"Ùä	‡w�w‡~�~�n vÕ-×.Ò.ð	ÜœŸš¨Ó8×9Ô9¸VØ#Ÿ^™^Ð,MÓN×WÑWÓY‘
��a˜÷ :÷ Ü�OŠOØ2°>Ð2Bð C;ð <ôñ Ü‡J‚Jˆ~Ô+Ü
‡K‚K�Ô%Ü‡L‚LØ
# NÐ#3°6¸+¸ÐFZÐ[bÐZcÐcdÐeö÷ :×9ûä�}‰}ô 	ØŠDð	ús0   Ä'G) Ä8$GÅG) ÇG&	Ç!G) Ç&G) Ç)HÈHc                 óˆ   € \         P                  P                  V 4      pV'       d   \         P                  ! VR R7       R# R# )T)Úexist_okN)r/   r0   r2   Úmakedirs)rG   Údb_dirs   & r   Úprepare_file_db_pathrg   �   s*   € Ü�W‰W�_‰_˜WÓ%€FßÜ
�Š�F T×*ñ r   g      @c           	      ó¶  aa€ \         P                  ! 4       \        ,           oVV3R  lp\        \        P
                  ! V 4      4      ;_uu_ 4       p\        \        P
                  ! S4      4      ;_uu_ 4       pVP                  WBR7       RRR4       RRR4       \        P                  ! V S4       R#   + '       g   i     L1; i  + '       g   i     L<; i)c                 ó€   <€ V \         \        39   d,   \        P                  ! 4       S8”  d   \	        R S R24      hR# R# )rQ   z*' stayed locked; database backup abandonedN)Ú_SQLITE_BUSYÚ_SQLITE_LOCKEDÚtimeÚ	monotonicÚTimeoutError)ÚstatusÚ	remainingÚtotalÚdeadlineÚdestination_paths   &&&€€r   Úgive_up_when_locked_too_longÚ6_backup_database.<locals>.give_up_when_locked_too_longŸ   s>   ø€ Ø”l¤NÐ3Ô3¼¿ºÓ8HÈ8Ô8SÜ Ð#3Ð"4Ð4^Ð_Ó`Ð`ñ 9TÑ3r   )ÚprogressN)	rl   rm   Ú_BACKUP_TIMEOUT_SECONDSr   rS   rT   ÚbackuprZ   Úcopymode)Úsource_pathrs   rt   ÚsourceÚdestinationrr   s   &f   @r   Ú_backup_databaser}   ™   s‡   ù€ ô �~Š~ÓÔ"9Õ9€Höaô 
”—’ Ó-×	.Ô	.°&Ü”W—_’_Ð%5Ó6×7Ô7¸;Ø�M‰M˜+ˆMÔM÷ 8÷ 
/ô ‡O‚O�KÐ!1Ö2÷ 8×7ú÷ 
/×	.ús$   Á(CÁ9B5	ÂCÂ5CÃ CÃC	c                ó0  € V R,           p\        V4      s \        P                  ^ R7       R#   \         d]    \        P
                  ! R\        R R24        \        P                  \        R7        R#   \         d    \        RT  R24      hi ; ii ; i)	aŒ  Acquire an OS-level file lock to prevent multi-process access.

Uses filelock for cross-platform support (macOS, Linux, Windows).
The OS automatically releases the lock when the process exits, even on crashes.
If the lock is held, waits up to _LOCK_WAIT_SECONDS for it to be released, since a
relaunch can start while the previous process is still exiting. The lock is never
taken from a holder.
ú.lock©Útimeoutz%Database lock is held; waiting up to Úgzs for it to be releasedz$Could not acquire lock on database 'zk'. Another ComfyUI process may already be using it. Use --database-url to specify a separate database file.N)r   Ú_db_lockÚacquirer   rX   r\   Ú_LOCK_WAIT_SECONDSÚRuntimeError)rG   Ú	lock_paths   & r   Ú_acquire_file_lockrˆ   ¬   s    € ð ˜'Õ!€IÜ˜	Ó"€HðÜ×Ñ ÐÖ#øÜô 	Ü�ŠÐ<Ô=OÐPQÐ<RÐRiÐjÔkð	Ü×ÑÔ%7Ð×8øÜô 	ÜØ6°w°ið @Jð Jóð ð	úð		ús   –. ®*BÁA6Á6BÂBc                 ó‚  €  \        4       p T R,           p\        P                  P	                  T4      '       g   R# \        T4      p TP                  ^ R7       TP                  4        R#   \         d     R# i ; i  \         d    T u # \         d(   p\        P                  ! RT RT 24        Rp?R# Rp?ii ; i)zËThe database path if another process holds its lock, else None.

Never waits and never keeps the lock: a free lock is taken and released at once.
A missing lock file means no holder, so none is created.
Nr   r€   z#Could not check the database lock 'z': )rO   rM   r/   r0   rR   r   r„   Úreleaser   Ú	ExceptionrX   Údebug)rG   r‡   ÚprobeÚes       r   Úlock_holder_db_pathr�   Æ   s°   € ðÜ“-ˆð ˜'Õ!€IÜ�7‰7�>‰>˜)×$Ò$ÙÜ�YÓ€EðOØ�‰˜aˆÔ Ø�‰Œñ øô ô Úðûô ô ØŠÜô Oä�ŠÐ;¸I¸;ÀcÈ!ÈÐM×NÐNÙûðOús5   ‚
A, Á"A> Á,A;Á:A;Á>B>ÂB>ÂB>ÂB9Â9B>c                ó   € V R9   # )zACheck if the database URL refers to an in-memory SQLite database.)zsqlite:///:memory:z	sqlite://r   ©Údb_urls   &r   Ú_is_memory_dbr“   ß   s   € àÐ8Ñ8Ð8r   c                  ól   € \        4       p \        V 4      '       d   \        V 4       R # \        V 4       R # rI   )r9   r“   Ú_init_memory_dbÚ_init_file_dbr‘   s    r   Úinit_dbr—   ä   s%   € ÜÓ€Fä�V×ÒÜ˜Öä�fÖr   c                óÊ   € \        V \        RR/R7      p\        P                  ! VR4      R 4       p\        P
                  P                  V4       \        VR7      s\        s	R# )uù   Initialize an in-memory SQLite database using metadata.create_all.

Alembic migrations don't work with in-memory SQLite because each
connection gets its own separate database â€” tables created by Alembic's
internal connection are lost immediately.
Úcheck_same_threadF)Ú	poolclassÚconnect_argsrT   c                 óh   € V P                  4       pVP                  R 4       VP                  4        R# ©úPRAGMA foreign_keys=ONN©ÚcursorrU   Úclose©Údbapi_connectionÚconnection_recordr    s   && r   Úset_sqlite_pragmaÚ*_init_memory_db.<locals>.set_sqlite_pragmaú   ó&   € à!×(Ñ(Ó*ˆØ�‰Ð/Ô0Ø�‰Žr   ©ÚbindN)
r   r   r   Úlistens_forr   ÚmetadataÚ
create_allr   r'   ÚWriteSession)r’   Úenginer¥   s   &  r   r•   r•   í   sb   € ô ØÜØ)¨5Ð1ô€Fô ×Ò�v˜yÓ)ñó *ðô
 	‡M�M×Ñ˜VÔ$ô  Ô'€GÜ‚Lr   c                óü   € \        4       p\        V4       \        V4        \        V4       \        P
                  P                  V4      p\        WV4       R#   \         d    \        P                  4        h i ; i)zBInitialize a file-backed SQLite database using Alembic migrations.N)rO   rg   rˆ   rb   r/   r0   rR   Ú_migrate_and_bindr‹   rƒ   rŠ   )r’   rG   Ú	db_existss   &  r   r–   r–     sb   € ä‹m€GÜ˜Ô!ô
 �wÔðÜ˜wÔ'Ü—G‘G—N‘N 7Ó+ˆ	Ü˜&¨9Ö5øÜô Ü×ÑÔØðús   ¢6A Á!A;ÚNORMALc                 ó6   € V P                  R \         24       R# )zPRAGMA synchronous=N)rU   ÚWAL_SYNCHRONOUS©r£   r¤   s   &&r   Ú_set_wal_synchronousr¶     s   € Ø×ÑÐ2´?Ð2CÐDÖEr   Ú0007_record_content_splitc                 óª   € \         ;QJ d,    R  V P                  WR7       4       F  '       g   K   R# 	  R# ! R  V P                  WR7       4       4      # )c              3   óH   "  € T F  pVP                   \        8H  x € K  	  R # 5irI   )ÚrevisionÚ_DESTRUCTIVE_REVISION)Ú.0rº   s   & r   Ú	<genexpr>Ú0_upgrade_discards_the_catalog.<locals>.<genexpr>&  s#   é € ð áUˆHð 	×ÑÔ2Ö2ÛUùs   ‚ ")ÚupperÚlowerTF)ÚanyÚiterate_revisions)ÚscriptÚ
target_revÚcurrent_revs   &&&r   Ú_upgrade_discards_the_catalogrÆ   %  sY   € ß‹3ñ à×0Ñ0°zÐ0ÔUó�3Œ3ð Š3ð ˆ3ñ à×0Ñ0°zÐ0ÔUóó ð r   c                 óä  € \        4       p\        V 4      p\        V 4      p\        P                  ! VR 4      R 4       p\        P                  ! VR 4      R 4       p\        P                  ! VR4      R 4       pVP	                  4       p	 V	P                  R4      P                  4       p
V
P                  4       R8w  d   \        P                  ! RV
4       MX\        P                  ! VR \        4       \        P                  ! VR \        4       \        V	P                  P                  4        \        P                   ! V	4      pVP#                  4       p\$        P&                  ! V4      pVP)                  4       pVf   \        P                  ! R
4       MˆWÎ8w  dƒ   VR,           pV'       d   \+        W4       MR	p \,        P.                  ! W>4       \        P0                  ! RV RV 24       T'       d)   \=        YÞT4      '       d   \?        R\@         RT R24       V	PC                  4        \E        VR7      s#\E        VR7      s$R	#   \         d    \        P                  ! R4        EL=i ; i  \2         dw   p\        P4                  ! RRR7       T'       dP    \+        Yñ4       \6        P8                  ! T4       Th  \2         d    \        P:                  ! RT 24        Thi ; iThR	p?ii ; i)rT   c                 óh   € V P                  4       pVP                  R 4       VP                  4        R# r�   rŸ   r¢   s   && r   r¥   Ú,_migrate_and_bind.<locals>.set_sqlite_pragma4  r§   r   c                 ó6   € R V n         V P                  R4       R # )Nrž   )Úisolation_levelrU   rµ   s   &&r   Úconfigure_write_connectionÚ5_migrate_and_bind.<locals>.configure_write_connection?  s   € à+/ÐÔ(Ø× Ñ Ð!9Ö:r   Úbeginc                 ó(   € V P                  R 4       R# )zBEGIN IMMEDIATEN)Úexec_driver_sql)Ú
connections   &r   Úbegin_immediateÚ*_migrate_and_bind.<locals>.begin_immediateD  s   € à×"Ñ"Ð#4Ö5r   zPRAGMA journal_mode=WALÚwalz=SQLite WAL mode unavailable; continuing with %s journal mode.zKCould not enable SQLite WAL mode; continuing with the default journal mode.NzNo target revision found.z.bkpzDatabase upgraded from z to zError upgrading databaseTr   zRestoring the database from its pre-upgrade backup, or removing the backup afterwards, failed; the pre-upgrade copy is kept at z8The asset catalog was rebuilt from scratch by migration a	  : manual tags, user metadata, previews, renames, API-created records and job_id links from the previous database were discarded. Record deletions were also discarded, so files still on disk will be catalogued again. The database from before the upgrade was kept at Ú.r¨   )%r>   r   r   rª   rT   rÐ   Ú
scalar_onerÀ   rX   rY   Úlistenr¶   rÑ   r£   r   r   Ú	configureÚget_current_revisionr   Úfrom_configÚget_current_headr}   r	   Úupgrader\   r‹   rŒ   r/   ÚremoveÚ	exceptionrÆ   r   r»   r¡   r   r'   r­   )r’   rG   r±   r=   r®   Úwrite_enginer¥   rÌ   rÒ   ÚconnÚjournal_modeÚcontextrÅ   rÃ   rÄ   r^   rŽ   s   &&&              r   r°   r°   ,  sž  € ÜÓ!€Fô ˜6Ó"€FÜ  Ó(€Lô ×Ò�v˜yÓ)ñó *ðô ×Ò�| YÓ/ñ;ó 0ð;ô ×Ò�| WÓ-ñ6ó .ð6ð �>‰>Ó€DðCØ×+Ñ+Ð,EÓF×QÑQÓSˆð ×ÑÓ 5Ô(Ü�OŠOÐ[Ð]iÕjô �LŠL˜ Ô,@ÔAÜ�LŠL˜ yÔ2FÔGÜ  §¡×!AÑ!AÕBä×(Ò(¨Ó.€GØ×.Ñ.Ó0€Kä×(Ò(¨Ó0€FØ×(Ñ(Ó*€JàÒÜ�ŠÐ3Õ4Ø	Ô	"à Õ&ˆßÜ˜WÕ2àˆKð	Ü�OŠO˜FÔ/Ü�LŠLÐ2°;°-¸tÀJÀ<ÐPÔQ÷ Ô8¸È[×YÒYÜØJÜ(Ð)ð *ð "�] !ð%ôð 	‡J�J„Lô  Ô'€GÜ \Ô2‚Løôu ô gÜ�ŠÐe×fðgûô< ô 	Ü�MŠMÐ4¸tÕDßðÜ$ [Ô:Ü—I’I˜kÔ*ð ˆGøô !ô Ü×%Ò%ðVØVaÐUbðdõð ˆGðúð
 ˆGûð	úsN   Â	I Æ:2I. É!I+É*I+É.K/É9 K*Ê!J=Ê;K*Ê=$K%Ë!K*Ë$K%Ë%K*Ë*K/c                  ó   € \        4       # rI   )r'   r   r   r   Úcreate_sessionrä   ‰  s
   € Ü‹9Ðr   c                 ó   € \        4       # )a‚  A session whose transactions open with BEGIN IMMEDIATE. Do filesystem work before
using it: the write lock is held from the first statement until commit. Do not open
one inside another: the inner one waits out busy_timeout for the outer's lock, then
fails with "database is locked", indistinguishable from real contention. Rule out a
nested session before investigating lock contention.)r­   r   r   r   Úcreate_write_sessionræ   �  s   € ô ‹>Ðr   )Ú
sqlalchemyÚalembicÚblake3rI   )Kr   rX   r/   rZ   rS   rl   Ú
contextlibr   Ú
app.loggerr   Úfilelockr   r   Úcomfy.cli_argsr   r   r   r'   r­   r   rè   r	   Úalembic.configr
   Úalembic.runtime.migrationr   Úalembic.scriptr   rç   r   r   Úsqlalchemy.enginer   r   Úsqlalchemy.excr   Úsqlalchemy.ormr   Úsqlalchemy.poolr   Úapp.database.modelsr   Úapp.assets.database.modelsÚappré   r!   rŒ   r   r%   r(   r>   r9   rJ   rO   rb   rg   rw   rj   rk   r}   rƒ   r…   rˆ   r�   r“   r—   r•   r–   r´   r¶   r»   rÆ   r°   rä   ræ   r   r   r   Ú<module>rø      s)  ðÛ Û Û 	Û Û Û Ý Ý *ß &ß 6à€Ø
€Ø€ð 4€ðGÝÝ%Ý:Ý.ß/ß/Ý/Ý+Ý*å(Û%Ûà€Mòòò<òò	Eò!ò?ò#òL+ð Ð Ø  !Ð €ˆnò3ð  €ØÐ òò4ò29ò
òò4ð( €ôFð 4Ð òòZ3òzôøðU ô Gà‡M‚MÐ6À×FðGús   ¾A
C ÃC8Ã7C8