o
    h$                     @   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   j/var/www/html/magazine_api/magazine_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   boolZ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__Z
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 )NZbloomr   r,   r   r   r   r   A   r   zBloomExtension.__init__Nr/   r0   r1   r   r   r   r   r   r4   ?       r4   c                   @   r3   )BtreeGinExtensionc                 C   r5   )NZ	btree_ginr   r,   r   r   r   r   G   r   zBtreeGinExtension.__init__Nr6   r   r   r   r   r8   E   r7   r8   c                   @   r3   )BtreeGistExtensionc                 C   r5   )NZ
btree_gistr   r,   r   r   r   r   M   r   zBtreeGistExtension.__init__Nr6   r   r   r   r   r9   K   r7   r9   c                   @   r3   )CITextExtensionc                 C   r5   )NZcitextr   r,   r   r   r   r   S   r   zCITextExtension.__init__Nr6   r   r   r   r   r:   Q   r7   r:   c                   @   r3   )CryptoExtensionc                 C   r5   )NZpgcryptor   r,   r   r   r   r   Y   r   zCryptoExtension.__init__Nr6   r   r   r   r   r;   W   r7   r;   c                   @   r3   )HStoreExtensionc                 C   r5   )NZhstorer   r,   r   r   r   r   _   r   zHStoreExtension.__init__Nr6   r   r   r   r   r<   ]   r7   r<   c                   @   r3   )TrigramExtensionc                 C   r5   )NZpg_trgmr   r,   r   r   r   r   e   r   zTrigramExtension.__init__Nr6   r   r   r   r   r=   c   r7   r=   c                   @   r3   )UnaccentExtensionc                 C   r5   )NZunaccentr   r,   r   r   r   r   k   r   zUnaccentExtension.__init__Nr6   r   r   r   r   r>   i   r7   r>   c                   @   r3   )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   Zin_atomic_blockr   	__class__r/   r   r#   r   r   r   _ensure_not_in_transactionp   s   z0NotInTransactionMixin._ensure_not_in_transactionN)r/   r0   r1   rB   r   r   r   r   r?   o   s    r?   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)Zconcurrently)	rB   apps	get_modelrI   allow_migrate_modelr   r   	add_indexrF   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 rJ   )	rB   rK   rL   rI   rM   r   r   remove_indexrF   rO   r   r   r   r'      rQ   z'AddIndexConcurrently.database_backwardsNr/   r0   r1   __doc__Zatomicr-   r&   r'   r   r   r   r   rD   y   s    rD   c                   @   rC   )
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   rI   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 rJ   )rB   rK   rL   rI   rM   r   r   modelsmodel_name_lowerget_index_by_namer   rR   )r   r   r#   r$   r%   rP   Zfrom_model_staterF   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 rJ   )rB   rK   rL   rI   rM   r   r   rV   rW   rX   r   rN   )r   r   r#   r$   r%   rP   Zto_model_staterF   r   r   r   r'      rY   z*RemoveIndexConcurrently.database_backwardsNrS   r   r   r   r   rU      s    rU   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   localer\   r]   )r   r   r^   r\   r]   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   r^   r[   r\   Fr]   )r   r^   r\   r]   r@   r1   )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+.r[   z*Non-libc providers require PostgreSQL 10+.r^   r\   falser]   z$CREATE COLLATION %(name)s (%(args)s)rE   c                 s   s"    | ]\}}| d | V  qdS )=Nr   ).0optionvaluer   r   r   	<genexpr>   s     z6CollationOperation.create_collation.<locals>.<genexpr>)r   args)r]   r   featuresZ%supports_non_deterministic_collationsr   r\   Z&supports_alternate_collation_providersr    r^   r   r   rG   items)r   r#   rg   r   r   r   create_collation   s&   




z#CollationOperation.create_collationc                 C   s   | d|| j  d S )NzDROP COLLATION %s)r   r    r   rA   r   r   r   remove_collation   s   z#CollationOperation.remove_collationN)r/   r0   r1   r   r   r`   rj   rk   r   r   r   r   rZ      s    rZ   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   rj   r"   r   r   r   r&      
   z!CreateCollation.database_forwardsc                 C   "   t |jj|s
d S | | d S r   )r   r   r   r   rk   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	r/   r0   r1   rT   r&   r'   r-   r2   r.   r   r   r   r   rm          rm   c                   @   rl   )RemoveCollationzRemove a collation.c                 C   rn   ro   )r   r   r   r   r   rk   r"   r   r   r   r&      rp   z!RemoveCollation.database_forwardsc                 C   rq   r   )r   r   r   r   rj   r"   r   r   r   r'      rr   z"RemoveCollation.database_backwardsc                 C   rs   )NzRemove collation r   r,   r   r   r   r-     rt   zRemoveCollation.describec                 C   ru   )Nzremove_collation_%srv   r,   r   r   r   r.     rx   z'RemoveCollation.migration_name_fragmentNry   r   r   r   r   r{      rz   r{   N)Zdjango.contrib.postgres.signalsr   r   r   Z	django.dbr   r   Zdjango.db.migrationsr   r   Z$django.db.migrations.operations.baser	   r
   r4   r8   r9   r:   r;   r<   r=   r>   r?   rD   rU   rZ   rm   r{   r   r   r   r   <module>   s&    6
3