o
    ˜¨Êh .  ã                   @   sf  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 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)ÚCheckConstraintc                   @   sL   e Zd Zd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   úT/var/www/html/env/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   sb   |j jdkst |j j|¡sd S |  || j¡s"| d| | j¡ ¡ t	 
¡  t 
¡  t|j ƒ d S )NÚ
postgresqlz!CREATE EXTENSION IF NOT EXISTS %s)Ú
connectionÚvendorr   Úallow_migrateÚaliasÚextension_existsr   ÚexecuteÚ
quote_namer   Úcache_clearr   r   ©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    2   s   þ
$ûz CreateExtension.extension_existsc                 C   ó
   d| j  S )NzCreates extension %sr   ©r   r   r   r   Údescribe:   r   zCreateExtension.describec                 C   r.   )Nzcreate_extension_%sr   r/   r   r   r   Úmigration_name_fragment=   s   
z'CreateExtension.migration_name_fragmentN)Ú__name__Ú
__module__Ú__qualname__Ú
reversibler   r   r(   r)   r    r0   Úpropertyr1   r   r   r   r   r      s    r   c                   @   ó   e Zd Zdd„ ZdS )ÚBloomExtensionc                 C   ó
   d| _ d S )NÚbloomr   r/   r   r   r   r   C   r   zBloomExtension.__init__N©r2   r3   r4   r   r   r   r   r   r8   B   ó    r8   c                   @   r7   )ÚBtreeGinExtensionc                 C   r9   )NÚ	btree_ginr   r/   r   r   r   r   H   r   zBtreeGinExtension.__init__Nr;   r   r   r   r   r=   G   r<   r=   c                   @   r7   )ÚBtreeGistExtensionc                 C   r9   )NÚ
btree_gistr   r/   r   r   r   r   M   r   zBtreeGistExtension.__init__Nr;   r   r   r   r   r?   L   r<   r?   c                   @   r7   )ÚCITextExtensionc                 C   r9   )NÚcitextr   r/   r   r   r   r   R   r   zCITextExtension.__init__Nr;   r   r   r   r   rA   Q   r<   rA   c                   @   r7   )ÚCryptoExtensionc                 C   r9   )NÚpgcryptor   r/   r   r   r   r   W   r   zCryptoExtension.__init__Nr;   r   r   r   r   rC   V   r<   rC   c                   @   r7   )ÚHStoreExtensionc                 C   r9   )NÚhstorer   r/   r   r   r   r   \   r   zHStoreExtension.__init__Nr;   r   r   r   r   rE   [   r<   rE   c                   @   r7   )ÚTrigramExtensionc                 C   r9   )NÚpg_trgmr   r/   r   r   r   r   a   r   zTrigramExtension.__init__Nr;   r   r   r   r   rG   `   r<   rG   c                   @   r7   )ÚUnaccentExtensionc                 C   r9   )NÚunaccentr   r/   r   r   r   r   f   r   zUnaccentExtension.__init__Nr;   r   r   r   r   rI   e   r<   rI   c                   @   r7   )Ú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__r2   ©r   r%   r   r   r   Ú_ensure_not_in_transactionk   s   ÿÿÿz0NotInTransactionMixin._ensure_not_in_transactionN)r2   r3   r4   rO   r   r   r   r   rK   j   r<   rK   c                   @   ó,   e Zd ZdZd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_namer/   r   r   r   r0   x   s
   ýzAddIndexConcurrently.describec                 C   sD   |   |¡ |j || j¡}|  |jj|¡r |j|| jdd� d S d S ©NT)Úconcurrently)	rO   ÚappsÚ	get_modelrV   Úallow_migrate_modelr   r   Ú	add_indexrS   ©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 rW   )	rO   rY   rZ   rV   r[   r   r   Úremove_indexrS   r]   r   r   r   r)   …   r_   z'AddIndexConcurrently.database_backwardsN©r2   r3   r4   Ú__doc__Úatomicr0   r(   r)   r   r   r   r   rQ   s   s    rQ   c                   @   rP   )
Ú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   rV   r/   r   r   r   r0   ‘   ó   z RemoveIndexConcurrently.describec                 C   s^   |   |¡ |j || j¡}|  |jj|¡r-|j|| jf }| 	| j
¡}|j||dd� d S d S rW   )rO   rY   rZ   rV   r[   r   r   ÚmodelsÚmodel_name_lowerÚget_index_by_namer   r`   )r   r   r%   r&   r'   r^   Úfrom_model_staterS   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 rW   )rO   rY   rZ   rV   r[   r   r   rh   ri   rj   r   r\   )r   r   r%   r&   r'   r^   Úto_model_staterS   r   r   r   r)   œ   rl   z*RemoveIndexConcurrently.database_backwardsNra   r   r   r   r   rd   Œ   s    rd   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   Úlocalerp   rq   )r   r   rr   rp   rq   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   rr   ro   rp   Frq   )r   rr   rp   rq   rM   r4   )r   Úkwargsr   r   r   Údeconstruct¯   s   


ýzCollationOperation.deconstructc              	   C   sŒ   | j du r|jjjstdƒ‚d| | j¡i}| jdkr#| | j¡|d< | j du r,d|d< | d| | j	¡d	 
d
d„ | ¡ D ƒ¡dœ ¡ d S )NFz4Non-deterministic collations require PostgreSQL 12+.rr   ro   rp   Úfalserq   z$CREATE COLLATION %(name)s (%(args)s)rR   c                 s   s"   � | ]\}}|› d |› �V  qdS )ú=Nr   )Ú.0ÚoptionÚvaluer   r   r   Ú	<genexpr>Ë   s   € 
ÿz6CollationOperation.create_collation.<locals>.<genexpr>)r   Úargs)rq   r   ÚfeaturesÚ%supports_non_deterministic_collationsr   r"   rr   rp   r!   r   rT   Ú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   rN   r   r   r   Úremove_collationÑ   s   ÿz#CollationOperation.remove_collationN)r2   r3   r4   r   r   rt   r   r€   r   r   r   r   rn   ¥   s    rn   c                   @   ó4   e Zd Zd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   r/   r   r   r   r0   æ   ó   zCreateCollation.describec                 C   ó   d| j  ¡  S )Nzcreate_collation_%s©r   Úlowerr/   r   r   r   r1   é   ó   z'CreateCollation.migration_name_fragmentN©	r2   r3   r4   rb   r(   r)   r0   r6   r1   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   r/   r   r   r   r0   ý   r‰   zRemoveCollation.describec                 C   rŠ   )Nzremove_collation_%sr‹   r/   r   r   r   r1      r�   z'RemoveCollation.migration_name_fragmentNrŽ   r   r   r   r   r�   î   r�   r�   c                       s@   e Zd Zd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   rV   Ú
constraint©rM   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   rV   r/   r   r   r   r0     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)
rY   rZ   rV   r[   r   r   r•   Ú
create_sqlr!   Ústr)r   r   r%   r&   r'   r^   Úconstraint_sqlr   r   r   r(     s   úz'AddConstraintNotValid.database_forwardsc                    s   t ƒ jd S )NÚ
_not_valid)r”   r1   r/   r–   r   r   r1   "  s   z-AddConstraintNotValid.migration_name_fragment)
r2   r3   r4   rb   r   r0   r(   r6   r1   Ú__classcell__r   r   r–   r   r‘     s    
r‘   c                   @   sL   e Zd Zd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   ©rV   r   )r   rV   r   r   r   r   r   *  s   
zValidateConstraint.__init__c                 C   re   )Nz"Validate constraint %s on model %srf   r/   r   r   r   r0   .  rg   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)rY   rZ   rV   r[   r   r   r!   r"   Ú_metaÚdb_tabler   r]   r   r   r   r(   1  s   
þÿÿÿz$ValidateConstraint.database_forwardsc                 C   r   r   r   r$   r   r   r   r)   <  s   z%ValidateConstraint.database_backwardsc                 C   r   r   r   r   r   r   r   r   @  r   z!ValidateConstraint.state_forwardsc                 C   s   d| j  ¡ | j ¡ f S )Nz%s_validate_%s)rV   rŒ   r   r/   r   r   r   r1   C  s   z*ValidateConstraint.migration_name_fragmentc                 C   s   | j jg | j| jdœfS )Nrž   )rM   r2   rV   r   r/   r   r   r   rt   G  s   þýzValidateConstraint.deconstructN)r2   r3   r4   rb   r   r0   r(   r)   r   r6   r1   rt   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
   Údjango.db.models.constraintsr   r   r8   r=   r?   rA   rC   rE   rG   rI   rK   rQ   rd   rn   r‚   r�   r‘   r�   r   r   r   r   Ú<module>   s,    6	2"