o
    <g(/                     @   sj  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 deZG dd	 d	eZG d
d deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd dZG dd dee	ZG dd dee
ZG dd deZG d d! d!eZG d"d# d#eZG d$d% d%eZG d&d' d'eZ d(S ))    )get_citext_oidsget_hstore_oidsregister_type_handlers)NotSupportedErrorrouter)AddConstraintAddIndexRemoveIndex)	OperationOperationCategory)CheckConstraintc                   @   sR   e Zd ZdZejZdd Zdd Zdd Z	dd	 Z
d
d Zdd Zedd ZdS )CreateExtensionTc                 C   s
   || _ d S Nname)selfr    r   U/var/www/html/venv/lib/python3.10/site-packages/django/contrib/postgres/operations.py__init__      
zCreateExtension.__init__c                 C      d S r   r   r   	app_labelstater   r   r   state_forwards      zCreateExtension.state_forwardsc                 C   s   |j jdkst|j j|sd S | || js"|d|| j  t	
  t
  t|j  t|j dr@|j |j j d d S d S )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_stater   r   r   database_forwards   s$   

z!CreateExtension.database_forwardsc                 C   sL   t |jj|s
d S | || jr|d|| j  t	  t
	  d S )NzDROP EXTENSION IF EXISTS %s)r   r    r   r!   r"   r   r#   r$   r   r%   r   r'   r   r   r   database_backwards,   s   z"CreateExtension.database_backwardsc                 C   sH   |j  }|d|g t| W  d    S 1 sw   Y  d S )Nz-SELECT 1 FROM pg_extension WHERE extname = %s)r   cursorr#   boolfetchone)r   r(   	extensionr-   r   r   r   r"   7   s   
$z CreateExtension.extension_existsc                 C   
   d| j  S )NzCreates extension %sr   r   r   r   r   describe?   r   zCreateExtension.describec                 C   r1   )Nzcreate_extension_%sr   r2   r   r   r   migration_name_fragmentB   s   
z'CreateExtension.migration_name_fragmentN)__name__
__module____qualname__
reversibler   ADDITIONcategoryr   r   r+   r,   r"   r3   propertyr4   r   r   r   r   r      s    r   c                   @      e Zd Zdd ZdS )BloomExtensionc                 C   
   d| _ d S )Nbloomr   r2   r   r   r   r   H   r   zBloomExtension.__init__Nr5   r6   r7   r   r   r   r   r   r=   G       r=   c                   @   r<   )BtreeGinExtensionc                 C   r>   )N	btree_ginr   r2   r   r   r   r   M   r   zBtreeGinExtension.__init__Nr@   r   r   r   r   rB   L   rA   rB   c                   @   r<   )BtreeGistExtensionc                 C   r>   )N
btree_gistr   r2   r   r   r   r   R   r   zBtreeGistExtension.__init__Nr@   r   r   r   r   rD   Q   rA   rD   c                   @   r<   )CITextExtensionc                 C   r>   )Ncitextr   r2   r   r   r   r   W   r   zCITextExtension.__init__Nr@   r   r   r   r   rF   V   rA   rF   c                   @   r<   )CryptoExtensionc                 C   r>   )Npgcryptor   r2   r   r   r   r   \   r   zCryptoExtension.__init__Nr@   r   r   r   r   rH   [   rA   rH   c                   @   r<   )HStoreExtensionc                 C   r>   )Nhstorer   r2   r   r   r   r   a   r   zHStoreExtension.__init__Nr@   r   r   r   r   rJ   `   rA   rJ   c                   @   r<   )TrigramExtensionc                 C   r>   )Npg_trgmr   r2   r   r   r   r   f   r   zTrigramExtension.__init__Nr@   r   r   r   r   rL   e   rA   rL   c                   @   r<   )UnaccentExtensionc                 C   r>   )Nunaccentr   r2   r   r   r   r   k   r   zUnaccentExtension.__init__Nr@   r   r   r   r   rN   j   rA   rN   c                   @   r<   )NotInTransactionMixinc                 C   s   |j jrtd| jj d S )Nz_The %s operation cannot be executed inside a transaction (set atomic = False on the migration).)r   in_atomic_blockr   	__class__r5   r   r(   r   r   r   _ensure_not_in_transactionp   s   z0NotInTransactionMixin._ensure_not_in_transactionN)r5   r6   r7   rT   r   r   r   r   rP   o   rA   rP   c                   @   2   e Zd ZdZdZejZdd Zdd Z	dd Z
d	S )
AddIndexConcurrentlyzDCreate an index using PostgreSQL's CREATE INDEX CONCURRENTLY syntax.Fc                 C   s   d| j jd| j j| jf S )Nz7Concurrently create index %s on field(s) %s of model %s, )indexr   joinfields
model_namer2   r   r   r   r3   ~   s
   zAddIndexConcurrently.describec                 C   sD   |  | |j|| j}| |jj|r |j|| jdd d S d S NT)concurrently)	rT   apps	get_modelr[   allow_migrate_modelr   r!   	add_indexrX   r   r   r(   r)   r*   modelr   r   r   r+      
   
z&AddIndexConcurrently.database_forwardsc                 C   sD   |  | |j|| j}| |jj|r |j|| jdd d S d S r\   )	rT   r^   r_   r[   r`   r   r!   remove_indexrX   rb   r   r   r   r,      rd   z'AddIndexConcurrently.database_backwardsN)r5   r6   r7   __doc__atomicr   r9   r:   r3   r+   r,   r   r   r   r   rV   x   s    rV   c                   @   rU   )
RemoveIndexConcurrentlyzBRemove an index using PostgreSQL's DROP INDEX CONCURRENTLY syntax.Fc                 C      d| j | jf S )Nz$Concurrently remove index %s from %sr   r[   r2   r   r   r   r3         z RemoveIndexConcurrently.describec                 C   s^   |  | |j|| j}| |jj|r-|j|| jf }|	| j
}|j||dd d S d S r\   )rT   r^   r_   r[   r`   r   r!   modelsmodel_name_lowerget_index_by_namer   re   )r   r   r(   r)   r*   rc   from_model_staterX   r   r   r   r+         
z)RemoveIndexConcurrently.database_forwardsc                 C   s^   |  | |j|| j}| |jj|r-|j|| jf }|	| j
}|j||dd d S d S r\   )rT   r^   r_   r[   r`   r   r!   rl   rm   rn   r   ra   )r   r   r(   r)   r*   rc   to_model_staterX   r   r   r   r,      rp   z*RemoveIndexConcurrently.database_backwardsN)r5   r6   r7   rf   rg   r   REMOVALr:   r3   r+   r,   r   r   r   r   rh      s    rh   c                   @   s<   e Zd ZdddddZdd Zdd	 Zd
d Zdd ZdS )CollationOperationlibcT)providerdeterministicc                C   s   || _ || _|| _|| _d S r   )r   localeru   rv   )r   r   rw   ru   rv   r   r   r   r      s   
zCollationOperation.__init__c                 C   r   r   r   r   r   r   r   r      r   z!CollationOperation.state_forwardsc                 C   sJ   | j | jd}| jr| jdkr| j|d< | jdu r| j|d< | jjg |fS )N)r   rw   rt   ru   Frv   )r   rw   ru   rv   rR   r7   )r   kwargsr   r   r   deconstruct   s   


zCollationOperation.deconstructc              	   C   sp   d| | ji}| jdkr| | j|d< | jdu rd|d< |d| | jdd	d
 | D d  d S )Nrw   rt   ru   Ffalserv   z$CREATE COLLATION %(name)s (%(args)s)rW   c                 s   s"    | ]\}}| d | V  qdS )=Nr   ).0optionvaluer   r   r   	<genexpr>   s    
z6CollationOperation.create_collation.<locals>.<genexpr>)r   args)r$   rw   ru   rv   r#   r   rY   items)r   r(   r   r   r   r   create_collation   s   



z#CollationOperation.create_collationc                 C   s   | d|| j  d S )NzDROP COLLATION %s)r#   r$   r   rS   r   r   r   remove_collation   s   z#CollationOperation.remove_collationN)r5   r6   r7   r   r   ry   r   r   r   r   r   r   rs      s    rs   c                   @   :   e Zd ZdZejZdd Zdd Zdd Z	e
dd	 Zd
S )CreateCollationzCreate a collation.c                 C   .   |j jdkst|j j|sd S | | d S Nr   )r   r   r   r    r!   r   r'   r   r   r   r+      
   z!CreateCollation.database_forwardsc                 C   "   t |jj|s
d S | | d S r   )r   r    r   r!   r   r'   r   r   r   r,         z"CreateCollation.database_backwardsc                 C      d| j  S )NzCreate collation r   r2   r   r   r   r3         zCreateCollation.describec                 C      d| j   S )Nzcreate_collation_%sr   lowerr2   r   r   r   r4         z'CreateCollation.migration_name_fragmentN)r5   r6   r7   rf   r   r9   r:   r+   r,   r3   r;   r4   r   r   r   r   r          r   c                   @   r   )RemoveCollationzRemove a collation.c                 C   r   r   )r   r   r   r    r!   r   r'   r   r   r   r+      r   z!RemoveCollation.database_forwardsc                 C   r   r   )r   r    r   r!   r   r'   r   r   r   r,      r   z"RemoveCollation.database_backwardsc                 C   r   )NzRemove collation r   r2   r   r   r   r3     r   zRemoveCollation.describec                 C   r   )Nzremove_collation_%sr   r2   r   r   r   r4     r   z'RemoveCollation.migration_name_fragmentN)r5   r6   r7   rf   r   rr   r:   r+   r,   r3   r;   r4   r   r   r   r   r      r   r   c                       sF   e Zd ZdZejZ fddZdd Zdd Z	e
 fdd	Z  ZS )
AddConstraintNotValidzg
    Add a table constraint without enforcing validation, using PostgreSQL's
    NOT VALID syntax.
    c                    s$   t |ts	tdt || d S )Nz<AddConstraintNotValid.constraint must be a check constraint.)
isinstancer   	TypeErrorsuperr   )r   r[   
constraintrR   r   r   r     s
   
zAddConstraintNotValid.__init__c                 C   s   d| j j| jf S )Nz*Create not valid constraint %s on model %s)r   r   r[   r2   r   r   r   r3     s   zAddConstraintNotValid.describec                 C   sT   |j || j}| |jj|r&| j||}|r(|jt	|d d d d S d S d S )Nz
 NOT VALID)params)
r^   r_   r[   r`   r   r!   r   
create_sqlr#   str)r   r   r(   r)   r*   rc   constraint_sqlr   r   r   r+     s   z'AddConstraintNotValid.database_forwardsc                    s   t  jd S )N
_not_valid)r   r4   r2   r   r   r   r4   )  s   z-AddConstraintNotValid.migration_name_fragment)r5   r6   r7   rf   r   r9   r:   r   r3   r+   r;   r4   __classcell__r   r   r   r   r   
  s    
r   c                   @   sR   e Zd ZdZejZdd Zdd Zdd Z	dd	 Z
d
d Zedd Zdd ZdS )ValidateConstraintz&Validate a table NOT VALID constraint.c                 C   s   || _ || _d S r   r[   r   )r   r[   r   r   r   r   r   3  s   
zValidateConstraint.__init__c                 C   ri   )Nz"Validate constraint %s on model %srj   r2   r   r   r   r3   7  rk   zValidateConstraint.describec                 C   sL   |j || j}| |jj|r$|d||jj	|| j
f  d S d S )Nz%ALTER TABLE %s VALIDATE CONSTRAINT %s)r^   r_   r[   r`   r   r!   r#   r$   _metadb_tabler   rb   r   r   r   r+   :  s   
z$ValidateConstraint.database_forwardsc                 C   r   r   r   r'   r   r   r   r,   E  s   z%ValidateConstraint.database_backwardsc                 C   r   r   r   r   r   r   r   r   I  r   z!ValidateConstraint.state_forwardsc                 C   s   d| j  | j f S )Nz%s_validate_%s)r[   r   r   r2   r   r   r   r4   L  s   z*ValidateConstraint.migration_name_fragmentc                 C   s   | j jg | j| jdfS )Nr   )rR   r5   r[   r   r2   r   r   r   ry   P  s   zValidateConstraint.deconstructN)r5   r6   r7   rf   r   
ALTERATIONr:   r   r3   r+   r,   r   r;   r4   ry   r   r   r   r   r   .  s    
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   r=   rB   rD   rF   rH   rJ   rL   rN   rP   rV   rh   rs   r   r   r   r   r   r   r   r   <module>   s,    ;	,$