
    g!                         d Z ddlmZ  G d d      Z G d de      Z G d de      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z	 G d de      Z
 G d de      Zy)z~
Helpers to manipulate deferred DDL statements that might need to be adjusted or
discarded within when executing a migration.
    )deepcopyc                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
	Referencez0Base class that defines the reference interface.c                      y)zU
        Return whether or not this instance references the specified table.
        F selftables     y/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/db/backends/ddl_references.pyreferences_tablezReference.references_table            c                      y)zV
        Return whether or not this instance references the specified column.
        Fr   r	   r
   columns      r   references_columnzReference.references_column   r   r   c                      y)zU
        Return whether or not this instance references the specified index.
        Fr   r	   r
   indexs      r   references_indexzReference.references_index   r   r   c                      y)zI
        Rename all references to the old_name to the new_table.
        Nr   r	   	old_table	new_tables      r   rename_table_referencesz!Reference.rename_table_references        	r   c                      y)zL
        Rename all references to the old_column to the new_column.
        Nr   )r	   r
   
old_column
new_columns       r   rename_column_referencesz"Reference.rename_column_references$   r   r   c                 N    d| j                   j                  dt        |       dS )N< >)	__class____name__strr	   s    r   __repr__zReference.__repr__*   s     NN33SY??r   c                     t        d      )Nz>Subclasses must define how they should be converted to string.)NotImplementedErrorr(   s    r   __str__zReference.__str__-   s    !L
 	
r   N)r&   
__module____qualname____doc__r   r   r   r   r    r)   r,   r   r   r   r   r   	   s)    :@
r   r   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)TablezHold a reference to a table.c                      || _         || _        y N)r
   
quote_name)r	   r
   r4   s      r   __init__zTable.__init__6   s    
$r   c                      | j                   |k(  S r3   r
   r   s     r   r   zTable.references_table:   s    zzU""r   c                 D    | j                  |      xr t        |       |k(  S r3   )r   r'   r   s      r   r   zTable.references_index=   s!    $$U+BD	U0BBr   c                 2    | j                   |k(  r|| _         y y r3   r7   r   s      r   r   zTable.rename_table_references@   s    ::""DJ #r   c                 8    | j                  | j                        S r3   )r4   r
   r(   s    r   r,   zTable.__str__D   s    tzz**r   N)	r&   r-   r.   r/   r5   r   r   r   r,   r   r   r   r1   r1   3   s    &%#C#+r   r1   c                   "    e Zd ZdZd Zd Zd Zy)TableColumnsz9Base class for references to multiple columns of a table.c                      || _         || _        y r3   r
   columns)r	   r
   r?   s      r   r5   zTableColumns.__init__K   s    
r   c                 @    | j                   |k(  xr || j                  v S r3   r>   r   s      r   r   zTableColumns.references_columnO   s    zzU"=v'==r   c                     | j                   |k(  r3t        | j                        D ]  \  }}||k(  s|| j                  |<    y y r3   )r
   	enumerater?   )r	   r
   r   r   r   r   s         r   r    z%TableColumns.rename_column_referencesR   s@    ::!*4<<!8vZ'*4DLL' "9 r   N)r&   r-   r.   r/   r5   r   r    r   r   r   r<   r<   H   s    C>5r   r<   c                   *     e Zd ZdZd fd	Zd Z xZS )Columnsz(Hold a reference to one or many columns.c                 B    || _         || _        t        |   ||       y r3   )r4   col_suffixessuperr5   )r	   r
   r?   r4   rF   r%   s        r   r5   zColumns.__init__\   s!    $((r   c                 j      fddj                  fdt         j                        D              S )Nc                     j                  |       }	 j                  |   }|rdj                  ||      }|S # t        $ r Y |S w xY wNz{} {})r4   rF   format
IndexErrorr   idxcolsuffixr	   s       r   col_strz Columns.__str__.<locals>.col_strb   sY    //&)C**3/!..f5C J  Js   #9 	AA, c              3   6   K   | ]  \  }} ||        y wr3   r   .0rN   r   rQ   s      r   	<genexpr>z"Columns.__str__.<locals>.<genexpr>l   !      
4K[S&GFC 4K   joinrB   r?   r	   rQ   s   `@r   r,   zColumns.__str__a   s1    	 yy 
4=dll4K
 
 	
r   )r   r&   r-   r.   r/   r5   r,   __classcell__r%   s   @r   rD   rD   Y   s    2)

r   rD   c                   (     e Zd ZdZ fdZd Z xZS )	IndexNamez"Hold a reference to an index name.c                 B    || _         || _        t        |   ||       y r3   )rP   create_index_namerG   r5   )r	   r
   r?   rP   rb   r%   s        r   r5   zIndexName.__init__t   s!    !2(r   c                 d    | j                  | j                  | j                  | j                        S r3   )rb   r
   r?   rP   r(   s    r   r,   zIndexName.__str__y   s#    %%djj$,,LLr   r\   r^   s   @r   r`   r`   q   s    ,)
Mr   r`   c                   &     e Zd Zd fd	Zd Z xZS )IndexColumnsc                 8    || _         t        | 	  ||||       y r3   )	opclassesrG   r5   )r	   r
   r?   r4   rF   rg   r%   s         r   r5   zIndexColumns.__init__~   s    "\Br   c                 j      fddj                  fdt         j                        D              S )Nc                     dj                  j                  |       j                  |         }	 j                  |   }|rdj                  ||      }|S # t        $ r Y |S w xY wrJ   )rK   r4   rg   rF   rL   rM   s       r   rQ   z%IndexColumns.__str__.<locals>.col_str   so     ..!8$..:MNC**3/!..f5C J  Js   #A 	A#"A#rR   c              3   6   K   | ]  \  }} ||        y wr3   r   rT   s      r   rV   z'IndexColumns.__str__.<locals>.<genexpr>   rW   rX   rY   r[   s   `@r   r,   zIndexColumns.__str__   s1    
	 yy 
4=dll4K
 
 	
r   )r   r   )r&   r-   r.   r5   r,   r]   r^   s   @r   re   re   }   s    C
r   re   c                   P     e Zd ZdZ fdZ fdZ fdZ fdZ fdZd Z	 xZ
S )ForeignKeyNamez'Hold a reference to a foreign key name.c                 d    t        ||      | _        || _        || _        t        |   ||       y r3   )r<   to_referencesuffix_templatecreate_fk_namerG   r5   )r	   
from_tablefrom_columnsto_table
to_columnsro   rp   r%   s          r   r5   zForeignKeyName.__init__   s7     ):>.,	
r   c                 \    t         |   |      xs | j                  j                  |      S r3   )rG   r   rn   )r	   r
   r%   s     r   r   zForeignKeyName.references_table   s0    w'. 
$2C2C2T2T3
 	
r   c                 `    t         |   ||      xs | j                  j                  ||      S r3   )rG   r   rn   )r	   r
   r   r%   s      r   r   z ForeignKeyName.references_column   s7    w(6
 @00?	@r   c                 ^    t         |   ||       | j                  j                  ||       y r3   )rG   r   rn   r	   r   r   r%   s      r   r   z&ForeignKeyName.rename_table_references   s(    '	9=11)YGr   c                 b    t         |   |||       | j                  j                  |||       y r3   )rG   r    rn   )r	   r
   r   r   r%   s       r   r    z'ForeignKeyName.rename_column_references   s,    (
JG225*jQr   c                     | j                   | j                  j                  | j                  j                  d   dz  }| j	                  | j                  | j                  |      S )Nr   )rs   	to_column)ro   rn   r
   r?   rp   )r	   rP   s     r   r,   zForeignKeyName.__str__   sY    %%))//**2215)
 
 ""4::t||VDDr   )r&   r-   r.   r/   r5   r   r   r   r    r,   r]   r^   s   @r   rl   rl      s(    1
"

@
HREr   rl   c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
	Statementz
    Statement template and formatting parameters container.

    Allows keeping a reference to a statement without interpolating identifiers
    that might have to be adjusted if they're referencing a table or column
    that is removed
    c                      || _         || _        y r3   templateparts)r	   r   r   s      r   r5   zStatement.__init__   s     
r   c                 \    t        fd| j                  j                         D              S )Nc              3   \   K   | ]#  }t        |d       xr |j                         % yw)r   N)hasattrr   )rU   partr
   s     r   rV   z-Statement.references_table.<locals>.<genexpr>   s4      
+ D,-N$2G2G2NN+s   ),anyr   valuesr   s    `r   r   zStatement.references_table   s*     


))+
 
 	
r   c                 `    t        fd| j                  j                         D              S )Nc              3   ^   K   | ]$  }t        |d       xr |j                         & yw)r   N)r   r   )rU   r   r   r
   s     r   rV   z.Statement.references_column.<locals>.<genexpr>   s7      
+ D-.X43I3I%QW3XX+   *-r   r   s    ``r   r   zStatement.references_column   *     


))+
 
 	
r   c                 `    t        fd| j                  j                         D              S )Nc              3   ^   K   | ]$  }t        |d       xr |j                         & yw)r   N)r   r   )rU   r   r   r
   s     r   rV   z-Statement.references_index.<locals>.<genexpr>   s6      
+ D,-U$2G2Gu2UU+r   r   r   s    ``r   r   zStatement.references_index   r   r   c                     | j                   j                         D ]!  }t        |d      s|j                  ||       # y )Nr   )r   r   r   r   )r	   r   r   r   s       r   r   z!Statement.rename_table_references   s4    JJ%%'Dt67,,Y	B (r   c                     | j                   j                         D ]"  }t        |d      s|j                  |||       $ y )Nr    )r   r   r   r    )r	   r
   r   r   r   s        r   r    z"Statement.rename_column_references   s6    JJ%%'Dt78--eZL (r   c                 4    | j                   | j                  z  S r3   r   r(   s    r   r,   zStatement.__str__   s    }}tzz))r   N)r&   r-   r.   r/   r5   r   r   r   r   r    r,   r   r   r   r}   r}      s,    


C
M
*r   r}   c                   4     e Zd Z fdZ fdZd Zd Z xZS )Expressionsc                     || _         || _        || _        | j                   j                  j	                  | j                  g      D cg c]  }|j
                  j                   }}t        | !  ||       y c c}w r3   )	compilerexpressionsquote_valuequery	_gen_colstargetr   rG   r5   )r	   r
   r   r   r   rO   r?   r%   s          r   r5   zExpressions.__init__   sz     && }}**44d6F6F5GH
H JJH 	 
 	(	
s   	A9c                     | j                   |k7  ry | j                  j                  ||i      | _        t        |   ||       y r3   )r
   r   relabeled_clonerG   r   rx   s      r   r   z#Expressions.rename_table_references   s?    ::"++;;Y	<RS'	9=r   c                 r   | j                   |k7  ry t        | j                        }g | _        | j                  j
                  j                  |g      D ][  }|j                  j                  |k(  r||j                  _        | j                  j                  |j                  j                         ] || _        y r3   )
r
   r   r   r?   r   r   r   r   r   append)r	   r
   r   r   r   rO   s         r   r    z$Expressions.rename_column_references   s    ::t//0==&&00+?Czz  J.$.

!LL

 1 12 @ 'r   c                     | j                   j                  | j                        \  }}t        | j                  |      }|t        |      z  S r3   )r   compiler   mapr   tuple)r	   sqlparamss      r   r,   zExpressions.__str__  sA    mm++D,<,<=VT%%v.U6]""r   )r&   r-   r.   r5   r   r    r,   r]   r^   s   @r   r   r      s    )>	'#r   r   N)r/   copyr   r   r1   r<   rD   r`   re   rl   r}   r   r   r   r   <module>r      s   
 '
 '
T+I +*55 5"
l 
0	M 	M
7 
.+E\ +E\**	 **Z#, #r   