o
    ^"<f$                     @   s6  d dl mZmZmZ d dl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d#S )$    )get_citext_oidsget_hstore_oidsregister_type_handlers)NotSupportedErrorrouter)AddIndexRemoveIndex)	Operationc                   @   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   Y/var/www/html/kck/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   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   /   s   
$z CreateExtension.extension_existsc                 C   
   d| j  S )NzCreates extension %sr   r   r   r   r   describe7   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   r.   propertyr/   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   A   r   zBloomExtension.__init__Nr0   r1   r2   r   r   r   r   r   r6   ?       r6   c                   @   r5   )BtreeGinExtensionc                 C   r7   )N	btree_ginr   r-   r   r   r   r   G   r   zBtreeGinExtension.__init__Nr9   r   r   r   r   r;   E   r:   r;   c                   @   r5   )BtreeGistExtensionc                 C   r7   )N
btree_gistr   r-   r   r   r   r   M   r   zBtreeGistExtension.__init__Nr9   r   r   r   r   r=   K   r:   r=   c                   @   r5   )CITextExtensionc                 C   r7   )Ncitextr   r-   r   r   r   r   S   r   zCITextExtension.__init__Nr9   r   r   r   r   r?   Q   r:   r?   c                   @   r5   )CryptoExtensionc                 C   r7   )Npgcryptor   r-   r   r   r   r   Y   r   zCryptoExtension.__init__Nr9   r   r   r   r   rA   W   r:   rA   c                   @   r5   )HStoreExtensionc                 C   r7   )Nhstorer   r-   r   r   r   r   _   r   zHStoreExtension.__init__Nr9   r   r   r   r   rC   ]   r:   rC   c                   @   r5   )TrigramExtensionc                 C   r7   )Npg_trgmr   r-   r   r   r   r   e   r   zTrigramExtension.__init__Nr9   r   r   r   r   rE   c   r:   rE   c                   @   r5   )UnaccentExtensionc                 C   r7   )Nunaccentr   r-   r   r   r   r   k   r   zUnaccentExtension.__init__Nr9   r   r   r   r   rG   i   r:   rG   c                   @   r5   )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__r0   r   r#   r   r   r   _ensure_not_in_transactionp   s   z0NotInTransactionMixin._ensure_not_in_transactionN)r0   r1   r2   rM   r   r   r   r   rI   o   s    rI   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   r.   }   s
   zAddIndexConcurrently.describec                 C   sD   |  | |j|| j}| |jj|r |j|| jdd d S d S NT)concurrently)	rM   apps	get_modelrT   allow_migrate_modelr   r   	add_indexrQ   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 rU   )	rM   rW   rX   rT   rY   r   r   remove_indexrQ   r[   r   r   r   r'      r]   z'AddIndexConcurrently.database_backwardsNr0   r1   r2   __doc__atomicr.   r&   r'   r   r   r   r   rO   y   s    rO   c                   @   rN   )
RemoveIndexConcurrentlyzBRemove an index using PostgreSQL's DROP INDEX CONCURRENTLY syntax.Fc                 C   s   d| j | jf S )Nz$Concurrently remove index %s from %s)r   rT   r-   r   r   r   r.      s   z RemoveIndexConcurrently.describec                 C   s^   |  | |j|| j}| |jj|r-|j|| jf }|	| j
}|j||dd d S d S rU   )rM   rW   rX   rT   rY   r   r   modelsmodel_name_lowerget_index_by_namer   r^   )r   r   r#   r$   r%   r\   from_model_staterQ   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 rU   )rM   rW   rX   rT   rY   r   r   rc   rd   re   r   rZ   )r   r   r#   r$   r%   r\   to_model_staterQ   r   r   r   r'      rg   z*RemoveIndexConcurrently.database_backwardsNr_   r   r   r   r   rb      s    rb   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   localerk   rl   )r   r   rm   rk   rl   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   rm   rj   rk   Frl   )r   rm   rk   rl   rK   r2   )r   kwargsr   r   r   deconstruct   s   


zCollationOperation.deconstructc              	   C   s   | j du r|jjjstd| jdkr|jjjstdd|| ji}| jdkr1|| j|d< | j du r:d|d< |	d	|| j
d
dd | D d  d S )NFz4Non-deterministic collations require PostgreSQL 12+.rj   z*Non-libc providers require PostgreSQL 10+.rm   rk   falserl   z$CREATE COLLATION %(name)s (%(args)s)rP   c                 s   s"    | ]\}}| d | V  qdS )=Nr   ).0optionvaluer   r   r   	<genexpr>   s     z6CollationOperation.create_collation.<locals>.<genexpr>)r   args)rl   r   features%supports_non_deterministic_collationsr   rk   &supports_alternate_collation_providersr    rm   r   r   rR   items)r   r#   rv   r   r   r   create_collation   s&   




z#CollationOperation.create_collationc                 C   s   | d|| j  d S )NzDROP COLLATION %s)r   r    r   rL   r   r   r   remove_collation   s   z#CollationOperation.remove_collationN)r0   r1   r2   r   r   ro   r{   r|   r   r   r   r   ri      s    ri   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   r.         zCreateCollation.describec                 C      d| j   S )Nzcreate_collation_%sr   lowerr-   r   r   r   r/         z'CreateCollation.migration_name_fragmentN	r0   r1   r2   r`   r&   r'   r.   r4   r/   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   r.     r   zRemoveCollation.describec                 C   r   )Nzremove_collation_%sr   r-   r   r   r   r/     r   z'RemoveCollation.migration_name_fragmentNr   r   r   r   r   r      r   r   N)django.contrib.postgres.signalsr   r   r   	django.dbr   r   django.db.migrationsr   r   $django.db.migrations.operations.baser	   r
   r6   r;   r=   r?   rA   rC   rE   rG   rI   rO   rb   ri   r~   r   r   r   r   r   <module>   s&    6
3