
    h	                         d 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y)z~
Helpers to manipulate deferred DDL statements that might need to be adjusted or
discarded within when executing a migration.
c                   4    e 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     d/var/www/html/ranktracker/api/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)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    !"bccr   N)
r    
__module____qualname____doc__r
   r   r   r   r#   r&   r   r   r	   r   r      s%    :@dr   r   c                   (    e 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   r.   s      r	   __init__zTable.__init__,   s    
$r   c                      | j                   |k(  S r-   r   r   s     r	   r
   zTable.references_table0   s    zzU""r   c                 2    | j                   |k(  r|| _         y y r-   r1   r   s      r	   r   zTable.rename_table_references3   s    ::""DJ #r   c                 8    | j                  | j                        S r-   )r.   r   r"   s    r	   r&   zTable.__str__7   s    tzz**r   N)r    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y)TableColumnsz9Base class for references to multiple columns of a table.c                      || _         || _        y r-   r   columns)r   r   r8   s      r	   r/   zTableColumns.__init__>   s    
r   c                 @    | j                   |k(  xr || j                  v S r-   r7   r   s      r	   r   zTableColumns.references_columnB   s    zzU"=v'==r   c                     | j                   |k(  r3t        | j                        D ]  \  }}||k(  s|| j                  |<    y y r-   )r   	enumerater8   )r   r   r   r   indexr   s         r	   r   z%TableColumns.rename_column_referencesE   sE    ::!*4<<!8 5vZ'*4DLL'5 r   N)r    r'   r(   r)   r/   r   r   r   r   r	   r5   r5   ;   s    C>5r   r5   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 r-   )r.   col_suffixessuperr/   )r   r   r8   r.   r@   r   s        r	   r/   zColumns.__init__O   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{} {})r.   r@   format
IndexErrorr   idxcolsuffixr   s       r	   col_strz Columns.__str__.<locals>.col_strU   sY    //&)C**3/!..f5C J  Js   #9 	AA, c              3   6   K   | ]  \  }} ||        y wr-   r   .0rH   r   rK   s      r	   	<genexpr>z"Columns.__str__.<locals>.<genexpr>_        Y+#v-Y   joinr;   r8   r   rK   s   `@r	   r&   zColumns.__str__T   s(    	 yyY4<<AXYYYr   )r   r    r'   r(   r)   r/   r&   __classcell__r   s   @r	   r>   r>   L   s    2)
Zr   r>   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 r-   )rJ   create_index_namerA   r/   )r   r   r8   rJ   r\   r   s        r	   r/   zIndexName.__init__e   s!    !2(r   c                 d    | j                  | j                  | j                  | j                        S r-   )r\   r   r8   rJ   r"   s    r	   r&   zIndexName.__str__j   s#    %%djj$,,LLr   rV   rX   s   @r	   rZ   rZ   b   s    ,)
Mr   rZ   c                   &     e Zd Zd fd	Zd Z xZS )IndexColumnsc                 8    || _         t        | 	  ||||       y r-   )	opclassesrA   r/   )r   r   r8   r.   r@   ra   r   s         r	   r/   zIndexColumns.__init__o   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rD   )rE   r.   ra   r@   rF   rG   s       r	   rK   z%IndexColumns.__str__.<locals>.col_strt   so     ..!8$..:MNC**3/!..f5C J  Js   #A 	A#"A#rL   c              3   6   K   | ]  \  }} ||        y wr-   r   rN   s      r	   rP   z'IndexColumns.__str__.<locals>.<genexpr>   rQ   rR   rS   rU   s   `@r	   r&   zIndexColumns.__str__s   s(    
	 yyY4<<AXYYYr   )r   r   )r    r'   r(   r/   r&   rW   rX   s   @r	   r_   r_   n   s    CZr   r_   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 r-   )r5   to_referencesuffix_templatecreate_fk_namerA   r/   )r   
from_tablefrom_columnsto_table
to_columnsri   rj   r   s          r	   r/   zForeignKeyName.__init__   s1    (:>.,\3r   c                 \    t         |   |      xs | j                  j                  |      S r-   )rA   r
   rh   )r   r   r   s     r	   r
   zForeignKeyName.references_table   s*    w'.[$2C2C2T2TUZ2[[r   c                 `    t         |   ||      xs | j                  j                  ||      S r-   )rA   r   rh   )r   r   r   r   s      r	   r   z ForeignKeyName.references_column   s2    G%eV4 ?//v>	
r   c                 ^    t         |   ||       | j                  j                  ||       y r-   )rA   r   rh   )r   r   r   r   s      r	   r   z&ForeignKeyName.rename_table_references   s(    '	9=11)YGr   c                 b    t         |   |||       | j                  j                  |||       y r-   )rA   r   rh   )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 )N    )rm   	to_column)ri   rh   r   r8   rj   )r   rJ   s     r	   r&   zForeignKeyName.__str__   sY    %%))//**2215)
 
 ""4::t||VDDr   )r    r'   r(   r)   r/   r
   r   r   r   r&   rW   rX   s   @r	   rf   rf      s(    14\
HREr   rf   c                   4    e 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 r-   templateparts)r   rz   r{   s      r	   r/   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
   )rO   partr   s     r	   rP   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   )rO   r   r   r   s     r	   rP   z.Statement.references_column.<locals>.<genexpr>   s7      
 D-.X43I3I%QW3XX
s   *-r   r   s    ``r	   r   zStatement.references_column   s*     


))+
 
 	
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   s;    JJ%%' 	CDt67,,Y	B	C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   s=    JJ%%' 	MDt78--eZL	Mr   c                 4    | j                   | j                  z  S r-   ry   r"   s    r	   r&   zStatement.__str__   s    }}tzz))r   N)
r    r'   r(   r)   r/   r
   r   r   r   r&   r   r   r	   rw   rw      s'    

C
M
*r   rw   N)	r)   r   r+   r5   r>   rZ   r_   rf   rw   r   r   r	   <module>r      st   d dD+I +$55 5"Zl Z,	M 	MZ7 Z*E\ ED#*	 #*r   