
    Zi!                        d dl mZ d dlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ erd d	lmZ  ej                  ej                        	 	 	 	 	 	 dd       Z ej                  ej"                        dd       Z ej                  ej&                        	 	 	 	 	 	 dd       Z ej                  ej*                        	 	 	 	 	 	 dd       Z ej                  ej.                        dd       Z ej                  ej2                        	 	 	 	 	 	 dd       Z ej                  ej6                        	 	 	 	 	 	 dd       Z ej                  ej:                        	 	 	 	 	 	 d d       Z ej                  ej>                        	 	 	 	 	 	 d!d       Z  ej                  ejB                        d"d       Z" ej                  ejF                        	 	 	 	 	 	 d#d       Z$ ej                  ejJ                        	 	 	 	 	 	 d$d       Z& ej                  ejN                        	 	 	 	 	 	 d%d       Z( ej                  ejR                        	 	 	 	 	 	 d&d       Z*y
)'    )TYPE_CHECKINGschema   )ops)
Operations   )_copy)sqla_2)TableNc                    | j                   j                  j                  | j                   j                  d       |j                  }|j                  }|j
                  }|j                  }|j                  }|j                  }|j                  }|j                  }	|j                  }
|j                  }|j                  }|j                  }fd}|ri|rg| j                  j!                  |t#        j$                  ||      |      }|j&                  D ]&  } ||      s| j                   j)                  |       ( |dusJ |dusJ  | j                   j*                  ||f||	|
|||||||d
|j,                   |rn| j                  j!                  || j                  j/                  ||      |      }|j&                  D ]&  } ||      s| j                   j1                  |       ( y y )Nc                 ~    t        | t        j                         xr  | j                   xs | j                        S N)
isinstance	sa_schemaPrimaryKeyConstraint_create_rule)
constraintcompilers    U/home/portmadness/app/.venv/lib/python3.12/site-packages/alembic/operations/toimpl.py_count_constraintz'alter_column.<locals>._count_constraint&   s<    j)*H*HII 
'''L:+B+B8+L	
    r   T)
nullableserver_defaultnametype_r   existing_typeexisting_server_defaultexisting_nullablecommentexisting_comment)impldialectstatement_compilerr   r   r   modify_typecolumn_name
table_namer   modify_server_defaultmodify_namemodify_nullablemodify_commentr!   
schema_objtabler   Columnconstraintsdrop_constraintalter_columnkwcolumnadd_constraint)
operations	operationr   r   r   r   r&   r'   r   r   new_column_namer   r    r!   r   tr   r   s                    @r   r1   r1      s    &&99H ++M!33'??!!E''K%%JF44N++O((H&&G 11

 !!''[-8 ( 

 -- 	<J ,//
;	< #$...$ JOO   %# 7+) ,,  !!''!!((e< ( 

 -- 	;J ,..z:	; r   c                     i }|j                   |j                   |d<    | j                  j                  |j                  | j                        fi | y N	if_exists)r;   r"   
drop_tableto_tablemigration_contextr5   r6   r2   s      r   r<   r<   U   sR    	B&#--;JOO:778<>r   c                     |j                  | j                        } | j                  j                  |j                  |f|j
                  |j                  d|j                   y )N)r   r;   )	to_columnr>   r"   drop_columnr'   r   r;   r2   )r5   r6   r3   s      r   rB   rB   _   sa       !=!=>FJOO %%	
 ,,r   c                     |j                  | j                        }i }|j                  |j                  |d<    | j                  j                  |fi | y Nif_not_exists)to_indexr>   rE   r"   create_index)r5   r6   idxr2   s       r   rG   rG   m   sT     

Z99
:C	B*'55? JOO  ++r   c                     i }|j                   |j                   |d<    | j                  j                  |j                  | j                        fi | y r:   )r;   r"   
drop_indexrF   r>   r?   s      r   rJ   rJ   x   sR    	B&#--;JOO:778
r   c                     i }|j                   |j                   |d<   |j                  | j                        } | j                  j                  |fi | |S rD   )rE   r=   r>   r"   create_table)r5   r6   r2   r-   s       r   rL   rL      sY     
B*'55?z;;<E JOO  -"-Lr   c                 |    | j                   j                  |j                  |j                  |j                         y )Nr   )r"   rename_tabler'   new_table_namer   r5   r6   s     r   rN   rN      s4     OO  i66y?O?O ! r   c                 p    |j                  | j                        }| j                  j                  |       y r   )r=   r>   r"   create_table_commentr5   r6   r-   s      r   rR   rR      s,     z;;<EOO((/r   c                 p    |j                  | j                        }| j                  j                  |       y r   )r=   r>   r"   drop_table_commentrS   s      r   rU   rU      s,     z;;<EOO&&u-r   c                    |j                   }|j                  }|j                  }|j                  }|j                  }|j
                  }|j                  t        |      }| j                  j                  |||      } | j                  j                  ||f||j                  ||d| |j                  D ]  }	t        |	t        j                        r|rKt        |	t        j                         r1t#        |j$                        dk(  rt#        |	j&                        dk(  rk| j                  j)                  |	        |j*                  D ]  }
| j                  j-                  |
        | j                  j.                  j0                  xr! | j                  j.                  j2                   }|j4                  }|r|r| j                  j7                  |       y y y )Nr   )r   rE   inline_referencesinline_primary_keyr   )r'   r3   r   r2   rW   rX   r-   r
   r,   r"   
add_columnrE   r/   r   r   r   ForeignKeyConstraintlenforeign_keyscolumnsr4   indexesrG   r#   supports_commentsinline_commentsr    create_column_comment)r5   r6   r'   r3   r   r2   rW   rX   r8   r   indexwith_commentr    s                r   rY   rY      s   %%JFF	B!33"55||v##Jv#FAJOO --+-  mm 7
*i&D&DE
 "z9+I+IJ++,1
**+q0OO**:67  ,$$U+, 	11 	8''777  nnG<--f5  wr   c                 l    | j                   j                  |j                  | j                               y r   )r"   r4   to_constraintr>   rP   s     r   create_constraintrf      s*     OO""
 < <=r   c                 $   i }|j                    t        st        d      |j                   |d<    | j                  j                  | j
                  j                  |j                  |j                  |j                  |j                        fi | y )NzSQLAlchemy 2.0 requiredr;   r   )r;   r   NotImplementedErrorr"   r0   r,   generic_constraintconstraint_namer'   constraint_typer   r?   s      r   r0   r0      s     
B&%&?@@#--;#JOO##00%%  %%##	 	1 	
 r   c                 |    | j                   j                  |j                  |j                  |j                         y )N)multiinsert)r"   bulk_insertr-   rowsrm   rP   s     r   rn   rn      s0     OOY5J5J   r   c                 z    | j                   j                  j                  |j                  |j                         y )N)execution_options)r>   r"   executesqltextrq   rP   s     r   execute_sqlrt      s4       %%--Y-H-H . r   )r5   r   r6   zops.AlterColumnOpreturnN)r5   r   r6   zops.DropTableOpru   N)r5   r   r6   zops.DropColumnOpru   N)r5   r   r6   zops.CreateIndexOpru   N)r5   r   r6   zops.DropIndexOpru   N)r5   r   r6   zops.CreateTableOpru   r   )r5   r   r6   zops.RenameTableOpru   N)r5   r   r6   zops.CreateTableCommentOpru   N)r5   r   r6   zops.DropTableCommentOpru   N)r5   r   r6   zops.AddColumnOpru   N)r5   r   r6   zops.AddConstraintOpru   N)r5   r   r6   zops.DropConstraintOpru   N)r5   r   r6   zops.BulkInsertOpru   N)r5   r   r6   zops.ExecuteSQLOpru   N)+typingr   
sqlalchemyr   r    r   baser   util.sqla_compatr
   r   sqlalchemy.sql.schemar   implementation_forAlterColumnOpr1   DropTableOpr<   DropColumnOprB   CreateIndexOprG   DropIndexOprJ   CreateTableOprL   RenameTableOprN   CreateTableCommentOprR   DropTableCommentOprU   AddColumnOprY   AddConstraintOprf   DropConstraintOpr0   BulkInsertOprn   ExecuteSQLOprt    r   r   <module>r      sJ   ! *   $ %+ s001@;@;)<@;	@; 2@;F s/ 0 s//0

);
	
 1
 s001,,)<,	, 2, s/ 0 s001)< 2 s001)<	 2 s77800)C0	0 90 s556..)A.	. 7. s/,6 0,6^ s223)>	 4 s334)?	 5& s//0);	 1 s//0);	 1r   