
    yj)                         U d Z ddlmZ ddlZddlmZ ddlmZm	Z	m
Z
mZ ddlmZ dZeed<   d	Zedz  ed
<   dZeee         z  dz  ed<   dZeee         z  dz  ed<   ej        j        ZddZddZdS )zmadd webhooks table

Revision ID: 88b0fb10906f
Revises: 05486ce795d5
Create Date: 2025-07-25 16:12:11.015327

    )SequenceN)op)column_existsconstraint_existsindex_existstable_exists)settings88b0fb10906frevision05486ce795d5down_revisionbranch_labels
depends_onreturnc                  "   t          j        dt          j        dt          j                    dd          t          j        dt          j                    t          j        d          d          t          j        d	t          j                    d          t          j        d
t          j        d          dt          j                                                  t          j	        dd          t                     t          j        t          j        d          ddgdt                     t          j        dt          j        dt          j                    d          t                     t          j        dt          j        dt          j                    d          t                     t          j        t          j        dt           dt           d                     t          j        dddt                     t          j        dddt                     t          j        dt          j        dt          j                    d          t                     t          j        dddgt                     t          j        t          j                              } t+          ddd|           rt          j        ddt                     t/          dd|           rt          j        ddt                     t/          dd |           rt          j        dd t                     t/          dd!|           rt          j        dd!t                     t/          dd|           rt          j        ddt                     d S d S )"Nwebhook_endpointsidTF)primary_keynullableworkspace_namezworkspaces.namer   url
created_at)timezone)r   server_defaultzlength(url) <= 2048webhook_endpoint_url_length)nameschema&idx_webhook_endpoints_workspace_lookup)uniquer   queue	task_typework_unit_keyz
            DO $$
            DECLARE
                rows_updated INT;
            BEGIN
                LOOP
                    UPDATE ay  .queue
                    SET
                        task_type = COALESCE(payload->>'task_type', 'representation'),
                        work_unit_key =
                            COALESCE(payload->>'task_type', 'representation') || ':' ||
                            COALESCE(payload->>'workspace_name', 'None') || ':' ||
                            COALESCE(payload->>'session_name', 'None') || ':' ||
                            COALESCE(payload->>'sender_name', 'None') || ':' ||
                            COALESCE(payload->>'target_name', 'None')
                    WHERE id IN (
                        SELECT id FROM a3  .queue
                        WHERE task_type IS NULL OR work_unit_key IS NULL
                        LIMIT 1000
                    );

                    GET DIAGNOSTICS rows_updated = ROW_COUNT;
                    EXIT WHEN rows_updated = 0;
                END LOOP;
            END $$;
            )r   r   active_queue_sessions)indexunique_work_unit_keyunique_active_queue_sessionr!   
session_idsender_nametarget_name)r   create_tablesaColumnTEXT
ForeignKeyDateTimefuncnowCheckConstraintr   create_indexf
add_columnTextexecutetextalter_columncreate_unique_constraintinspectget_bindr   drop_constraintr   drop_column	inspectors    [/DATA/AppData/hermes/projects/honcho/migrations/versions/88b0fb10906f_add_webhooks_table.pyupgraderD      s   O
	GII		
 	
 	
 		GIIM+,,		
 	
 	
 		%U333
	K&&&7;;==		
 	
 	
 	07TUUU-   2 O
566	    M
	+rwyy4888    M
	/2799t<<<    J
 #   )/!  	
 	
  @ OG[5HHHHOG_uVLLLL M
	/2799D999    		    
2;==))I!>)  
 	)+B6	
 	
 	
 	
 ,lIFF M
.VLLLL,mYGG N
.fMMMM,mYGG N
.fMMMM,k9EE L
.FKKKKKKL L    c                     t          j        t          j                              } t	          d|           rZt          dd|           r.t          j        t          j        d          dt                     t          j	        dt                     t          dd|           rt          j        ddt                     t          dd|           rt          j        ddt                     t          dd	d
|           rt          j        d	dt                     t          dd|           rt          j        ddt                     t          dd|           rt          j        ddt                     t          dd|           sBt          j        dt          j        dt          j                    d          t                     t          dd|           sBt          j        dt          j        dt          j                    d          t                     t          dd|           sBt          j        dt          j        dt          j                    d          t                     t          dd|           sBt          j        dt          j        dt          j                    d          t                     t          ddd
|           s!t          j        ddg dt                     d S d S )Nr   r    )
table_namer   r   r"   r#   r$   r%   r'   r!   work_unit_datar)   Tr   r*   r+   Fr(   )r)   r*   r+   r#   )r-   r=   r   r>   r   r   
drop_indexr6   r   
drop_tabler   r@   r   r?   r7   r.   r/   r<   rA   s    rC   	downgraderK      s&   
2;==))I'33 
:!I9
 
 	 M=>>.    	)&9999Wk955 <
wF;;;;Woy99 @
w???? !79  
 	"$;F	
 	
 	
 	
 ,oyII P
.OOOO,.>	JJ Q
.0@PPPP 0,	JJ 

#IlBGII===	
 	
 	
 	
 0-KK 

#ImRWYY>>>	
 	
 	
 	
 0-KK 

#ImRWYY>>>	
 	
 	
 	
 0+yII 

#Ik2799u===	
 	
 	
 	
 %	  
 	#)#EEE		
 	
 	
 	
 	
 	

 
rE   )r   N)__doc__collections.abcr   
sqlalchemyr-   alembicr   migrations.utilsr   r   r   r   
src.configr	   r   str__annotations__r   r   r   DBSCHEMAr   rD   rK    rE   rC   <module>rW      sC     % $ $ $ $ $                             #   *sTz * * *,0sXc]"T) 0 0 0)-
C(3-$& - - -		vL vL vL vLrL
 L
 L
 L
 L
 L
rE   