
    g(/                        d dl mZmZmZ d dlmZmZ d dlmZm	Z	m
Z
 d dlmZmZ d dlm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 G d de      Z G d d      Z G d dee	      Z G d de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())    )get_citext_oidsget_hstore_oidsregister_type_handlers)NotSupportedErrorrouter)AddConstraintAddIndexRemoveIndex)	OperationOperationCategory)CheckConstraintc                   \    e Zd ZdZej
                  Zd Zd Zd Z	d Z
d Zd Zed        Zy	)
CreateExtensionTc                     || _         y Nname)selfr   s     z/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/contrib/postgres/operations.py__init__zCreateExtension.__init__   s	    	    c                      y r    r   	app_labelstates      r   state_forwardszCreateExtension.state_forwards       r   c                 &   |j                   j                  dk7  s*t        j                  |j                   j                  |      sy | j                  || j                        s-|j                  d|j                  | j                        z         t        j                          t        j                          t        |j                          t        |j                   d      r1|j                   j                  |j                   j                   d       y y )N
postgresqlz!CREATE EXTENSION IF NOT EXISTS %sregister_geometry_adaptersT)
connectionvendorr   allow_migratealiasextension_existsr   execute
quote_namer   cache_clearr   r   hasattrr!   r   r   schema_editor
from_stateto_states        r   database_forwardsz!CreateExtension.database_forwards   s    ##**l:&BVBV$$**IC
 $$]DII>!!3**49956
 	##%##% 	}778=++-IJ$$??((33T Kr   c                 <   t        j                  |j                  j                  |      sy | j	                  || j
                        r-|j                  d|j                  | j
                        z         t        j                          t        j                          y )NzDROP EXTENSION IF EXISTS %s)r   r$   r"   r%   r&   r   r'   r(   r   r)   r   r+   s        r   database_backwardsz"CreateExtension.database_backwards,   st    ##M$<$<$B$BIN  		:!!-0H0H0SS 	##%##%r   c                     |j                   j                         5 }|j                  d|g       t        |j	                               cd d d        S # 1 sw Y   y xY w)Nz-SELECT 1 FROM pg_extension WHERE extname = %s)r"   cursorr'   boolfetchone)r   r,   	extensionr3   s       r   r&   z CreateExtension.extension_exists7   sG    %%,,.&NN? )* /..s   ,AAc                      d| j                   z  S )NzCreates extension %sr   r   s    r   describezCreateExtension.describe?   s    %		11r   c                      d| j                   z  S )Nzcreate_extension_%sr   r8   s    r   migration_name_fragmentz'CreateExtension.migration_name_fragmentB   s    $tyy00r   N)__name__
__module____qualname__
reversibler   ADDITIONcategoryr   r   r/   r1   r&   r9   propertyr;   r   r   r   r   r      sD    J ))H,	&+2 1 1r   r   c                       e Zd Zd Zy)BloomExtensionc                     d| _         y )Nbloomr   r8   s    r   r   zBloomExtension.__init__H   s	    	r   Nr<   r=   r>   r   r   r   r   rD   rD   G   s    r   rD   c                       e Zd Zd Zy)BtreeGinExtensionc                     d| _         y )N	btree_ginr   r8   s    r   r   zBtreeGinExtension.__init__M   s	    	r   NrG   r   r   r   rI   rI   L   s     r   rI   c                       e Zd Zd Zy)BtreeGistExtensionc                     d| _         y )N
btree_gistr   r8   s    r   r   zBtreeGistExtension.__init__R   s	     	r   NrG   r   r   r   rM   rM   Q   s    !r   rM   c                       e Zd Zd Zy)CITextExtensionc                     d| _         y )Ncitextr   r8   s    r   r   zCITextExtension.__init__W   	    	r   NrG   r   r   r   rQ   rQ   V       r   rQ   c                       e Zd Zd Zy)CryptoExtensionc                     d| _         y )Npgcryptor   r8   s    r   r   zCryptoExtension.__init__\   	    	r   NrG   r   r   r   rW   rW   [       r   rW   c                       e Zd Zd Zy)HStoreExtensionc                     d| _         y )Nhstorer   r8   s    r   r   zHStoreExtension.__init__a   rT   r   NrG   r   r   r   r]   r]   `   rU   r   r]   c                       e Zd Zd Zy)TrigramExtensionc                     d| _         y )Npg_trgmr   r8   s    r   r   zTrigramExtension.__init__f   s	    	r   NrG   r   r   r   ra   ra   e   s    r   ra   c                       e Zd Zd Zy)UnaccentExtensionc                     d| _         y )Nunaccentr   r8   s    r   r   zUnaccentExtension.__init__k   rZ   r   NrG   r   r   r   re   re   j   r[   r   re   c                       e Zd Zd Zy)NotInTransactionMixinc                 t    |j                   j                  r"t        d| j                  j                  z        y )Nz_The %s operation cannot be executed inside a transaction (set atomic = False on the migration).)r"   in_atomic_blockr   	__class__r<   r   r,   s     r   _ensure_not_in_transactionz0NotInTransactionMixin._ensure_not_in_transactionp   s;    ##33#9;?>>;R;RS  4r   N)r<   r=   r>   rn   r   r   r   ri   ri   o   s    r   ri   c                   >    e Zd ZdZdZej                  Zd Zd Z	d Z
y)AddIndexConcurrentlyzDCreate an index using PostgreSQL's CREATE INDEX CONCURRENTLY syntax.Fc                     d| j                   j                  ddj                  | j                   j                        d| j                  S )NzConcurrently create index z on field(s) , z
 of model )indexr   joinfields
model_namer8   s    r   r9   zAddIndexConcurrently.describe~   s4    JJOOIIdjj''(OO
 	
r   c                     | j                  |       |j                  j                  || j                        }| j	                  |j
                  j                  |      r|j                  || j                  d       y y NT)concurrently)	rn   apps	get_modelrv   allow_migrate_modelr"   r%   	add_indexrs   r   r   r,   r-   r.   models         r   r/   z&AddIndexConcurrently.database_forwards   se    ''6''	4??C##M$<$<$B$BEJ##E4::D#I Kr   c                     | j                  |       |j                  j                  || j                        }| j	                  |j
                  j                  |      r|j                  || j                  d       y y rx   )	rn   rz   r{   rv   r|   r"   r%   remove_indexrs   r~   s         r   r1   z'AddIndexConcurrently.database_backwards   se    ''6)))T__E##M$<$<$B$BEJ&&udjjt&L Kr   N)r<   r=   r>   __doc__atomicr   r@   rA   r9   r/   r1   r   r   r   rp   rp   x   s&    NF ))H
JMr   rp   c                   >    e Zd ZdZdZej                  Zd Zd Z	d Z
y)RemoveIndexConcurrentlyzBRemove an index using PostgreSQL's DROP INDEX CONCURRENTLY syntax.Fc                 :    d| j                   d| j                  S )NzConcurrently remove index z from r   rv   r8   s    r   r9   z RemoveIndexConcurrently.describe   s    9=DOOTTr   c                 T   | j                  |       |j                  j                  || j                        }| j	                  |j
                  j                  |      rK|j                  || j                  f   }|j                  | j                        }|j                  ||d       y y rx   )rn   rz   r{   rv   r|   r"   r%   modelsmodel_name_lowerget_index_by_namer   r   )r   r   r,   r-   r.   r   from_model_staters   s           r   r/   z)RemoveIndexConcurrently.database_forwards   s    ''6)))T__E##M$<$<$B$BEJ)00D<Q<Q1QR$66tyyAE&&ue$&G Kr   c                 T   | j                  |       |j                  j                  || j                        }| j	                  |j
                  j                  |      rK|j                  || j                  f   }|j                  | j                        }|j                  ||d       y y rx   )rn   rz   r{   rv   r|   r"   r%   r   r   r   r   r}   )r   r   r,   r-   r.   r   to_model_staters   s           r   r1   z*RemoveIndexConcurrently.database_backwards   s    ''6''	4??C##M$<$<$B$BEJ%__Y8M8M-MNN"44TYY?E##E5t#D Kr   N)r<   r=   r>   r   r   r   REMOVALrA   r9   r/   r1   r   r   r   r   r      s'    LF ((HUHEr   r   c                   2    e Zd ZddddZd Zd Zd Zd Zy	)
CollationOperationlibcT)providerdeterministicc                <    || _         || _        || _        || _        y r   )r   localer   r   )r   r   r   r   r   s        r   r   zCollationOperation.__init__   s    	 *r   c                      y r   r   r   s      r   r   z!CollationOperation.state_forwards   r   r   c                     | j                   | j                  d}| j                  r| j                  dk7  r| j                  |d<   | j                  du r| j                  |d<   | j                  j
                  g |fS )N)r   r   r   r   Fr   )r   r   r   r   rl   r>   )r   kwargss     r   deconstructzCollationOperation.deconstruct   so    ))t{{;==T]]f4!%F:&&*&8&8F?#NN''
 	
r   c           	      f   d|j                  | j                        i}| j                  dk7  r|j                  | j                        |d<   | j                  du rd|d<   |j	                  d|j                  | j
                        dj                  d	 |j                         D              d
z         y )Nr   r   r   Ffalser   z$CREATE COLLATION %(name)s (%(args)s)rr   c              3   0   K   | ]  \  }}| d |   yw)=Nr   ).0optionvalues      r   	<genexpr>z6CollationOperation.create_collation.<locals>.<genexpr>   s#      "=IMFEvhaw'\s   )r   args)r(   r   r   r   r'   r   rt   items)r   r,   r   s      r   create_collationz#CollationOperation.create_collation   s    -224;;?@==F",77FD&$+D!2%00;		 "=AZZ\" 	
r   c                 ^    |j                  d|j                  | j                        z         y )NzDROP COLLATION %s)r'   r(   r   rm   s     r   remove_collationz#CollationOperation.remove_collation   s'    -":":499"EE	
r   N)r<   r=   r>   r   r   r   r   r   r   r   r   r   r      s     17t +


 
r   r   c                   J    e Zd ZdZej
                  Zd Zd Zd Z	e
d        Zy)CreateCollationzCreate a collation.c                     |j                   j                  dk7  s*t        j                  |j                   j                  |      sy | j                  |       y Nr    )r"   r#   r   r$   r%   r   r+   s        r   r/   z!CreateCollation.database_forwards   H    ##**l:&BVBV$$**IC
 m,r   c                 |    t        j                  |j                  j                  |      sy | j	                  |       y r   )r   r$   r"   r%   r   r+   s        r   r1   z"CreateCollation.database_backwards   /    ##M$<$<$B$BINm,r   c                      d| j                    S )NzCreate collation r   r8   s    r   r9   zCreateCollation.describe       "499+..r   c                 <    d| j                   j                         z  S )Nzcreate_collation_%sr   lowerr8   s    r   r;   z'CreateCollation.migration_name_fragment       $tyy'888r   N)r<   r=   r>   r   r   r@   rA   r/   r1   r9   rB   r;   r   r   r   r   r      s3     ))H--
/ 9 9r   r   c                   J    e Zd ZdZej
                  Zd Zd Zd Z	e
d        Zy)RemoveCollationzRemove a collation.c                     |j                   j                  dk7  s*t        j                  |j                   j                  |      sy | j                  |       y r   )r"   r#   r   r$   r%   r   r+   s        r   r/   z!RemoveCollation.database_forwards   r   r   c                 |    t        j                  |j                  j                  |      sy | j	                  |       y r   )r   r$   r"   r%   r   r+   s        r   r1   z"RemoveCollation.database_backwards   r   r   c                      d| j                    S )NzRemove collation r   r8   s    r   r9   zRemoveCollation.describe  r   r   c                 <    d| j                   j                         z  S )Nzremove_collation_%sr   r8   s    r   r;   z'RemoveCollation.migration_name_fragment  r   r   N)r<   r=   r>   r   r   r   rA   r/   r1   r9   rB   r;   r   r   r   r   r      s3     ((H--
/ 9 9r   r   c                   Z     e Zd ZdZej
                  Z fdZd Zd Z	e
 fd       Z xZS )AddConstraintNotValidzg
    Add a table constraint without enforcing validation, using PostgreSQL's
    NOT VALID syntax.
    c                 \    t        |t              st        d      t        |   ||       y )Nz<AddConstraintNotValid.constraint must be a check constraint.)
isinstancer   	TypeErrorsuperr   )r   rv   
constraintrl   s      r   r   zAddConstraintNotValid.__init__  s.    *o6N  	Z0r   c                 N    d| j                   j                  d| j                  S )NzCreate not valid constraint 
 on model )r   r   rv   r8   s    r   r9   zAddConstraintNotValid.describe  s     OO  OO
 	
r   c                    |j                   j                  || j                        }| j                  |j                  j
                  |      r?| j                  j                  ||      }|r |j                  t        |      dz   d        y y y )Nz
 NOT VALID)params)
rz   r{   rv   r|   r"   r%   r   
create_sqlr'   str)r   r   r,   r-   r.   r   constraint_sqls          r   r/   z'AddConstraintNotValid.database_forwards  s|    )))T__E##M$<$<$B$BEJ!__77}MN %%c.&9L&HQU%V	  Kr   c                     t         |   dz   S )N
_not_valid)r   r;   )r   rl   s    r   r;   z-AddConstraintNotValid.migration_name_fragment)  s    w.==r   )r<   r=   r>   r   r   r@   rA   r   r9   r/   rB   r;   __classcell__)rl   s   @r   r   r   
  s9    
 !))H1
W > >r   r   c                   \    e Zd ZdZej
                  Zd Zd Zd Z	d Z
d Zed        Zd Zy	)
ValidateConstraintz&Validate a table NOT VALID constraint.c                      || _         || _        y r   rv   r   )r   rv   r   s      r   r   zValidateConstraint.__init__3  s    $	r   c                 :    d| j                   d| j                  S )NzValidate constraint r   r   r8   s    r   r9   zValidateConstraint.describe7  s    7;yy$//RRr   c                 D   |j                   j                  || j                        }| j                  |j                  j
                  |      rT|j                  d|j                  |j                  j                        d|j                  | j                               y y )NzALTER TABLE z VALIDATE CONSTRAINT )rz   r{   rv   r|   r"   r%   r'   r(   _metadb_tabler   r~   s         r   r/   z$ValidateConstraint.database_forwards:  s}    )))T__E##M$<$<$B$BEJ!! ",,U[[-A-AB!,,TYY7 Kr   c                      y r   r   r+   s        r   r1   z%ValidateConstraint.database_backwardsE  s    r   c                      y r   r   r   s      r   r   z!ValidateConstraint.state_forwardsI  r   r   c                 p    | j                   j                         d| j                  j                         S )N
_validate_)rv   r   r   r8   s    r   r;   z*ValidateConstraint.migration_name_fragmentL  s%    #'??#8#8#:DIIOO<MNNr   c                 b    | j                   j                  g | j                  | j                  dfS )Nr   )rl   r<   rv   r   r8   s    r   r   zValidateConstraint.deconstructP  s/    NN##"oo		
 	
r   N)r<   r=   r>   r   r   
ALTERATIONrA   r   r9   r/   r1   r   rB   r;   r   r   r   r   r   r   .  sE    0 ++HS	 O O
r   r   N)!django.contrib.postgres.signalsr   r   r   	django.dbr   r   django.db.migrationsr   r	   r
   $django.db.migrations.operations.baser   r   django.db.models.constraintsr   r   rD   rI   rM   rQ   rW   r]   ra   re   ri   rp   r   r   r   r   r   r   r   r   r   <module>r      s    
 0 E E M 881i 81v_ 
   
! !
o 
o 
o 
 
 
 M0( M4E3[ E4)
 )
X9( 929( 92!>M !>H*
 *
r   