o 3a$@s6ddlmZmZmZddlmZmZddlmZm Z ddl m Z Gddde Z Gddde Z Gd d d e ZGd d d e ZGd dde ZGddde ZGddde ZGddde ZGddde ZGdddZGdddeeZGdddee ZGddde ZGdd d eZGd!d"d"eZd#S)$)get_citext_oidsget_hstore_oidsregister_type_handlers)NotSupportedErrorrouter)AddIndex RemoveIndex) Operationc@sLeZdZdZddZddZddZdd Zd d Zd d Z e ddZ dS)CreateExtensionTcCs ||_dSNname)selfr rD/usr/lib/python3/dist-packages/django/contrib/postgres/operations.py__init__  zCreateExtension.__init__cCdSr rr app_labelstaterrrstate_forwardszCreateExtension.state_forwardscCsb|jjdkst|jj|sdS|||js"|d||jt t t |jdS)N postgresqlz!CREATE EXTENSION IF NOT EXISTS %s) connectionvendorr allow_migratealiasextension_existsr execute quote_namer cache_clearrrrr schema_editor from_stateto_staterrrdatabase_forwardss z!CreateExtension.database_forwardscCsLt|jj|s dS|||jr|d||jt t dS)NzDROP EXTENSION IF EXISTS %s) rrrrrr rr rr!rr"rrrdatabase_backwards$s z"CreateExtension.database_backwardscCsH|j}|d|gt|WdS1swYdS)Nz-SELECT 1 FROM pg_extension WHERE extname = %s)rcursorrboolfetchone)rr# extensionr(rrrr/s  $z CreateExtension.extension_existscC d|jS)NzCreates extension %sr rrrrdescribe7rzCreateExtension.describecCr,)Nzcreate_extension_%sr r-rrrmigration_name_fragment:s z'CreateExtension.migration_name_fragmentN) __name__ __module__ __qualname__ reversiblerrr&r'rr.propertyr/rrrrr s r c@eZdZddZdS)BloomExtensioncC d|_dS)Nbloomr r-rrrrArzBloomExtension.__init__Nr0r1r2rrrrrr6? r6c@r5)BtreeGinExtensioncCr7)N btree_ginr r-rrrrGrzBtreeGinExtension.__init__Nr9rrrrr;Er:r;c@r5)BtreeGistExtensioncCr7)N btree_gistr r-rrrrMrzBtreeGistExtension.__init__Nr9rrrrr=Kr:r=c@r5)CITextExtensioncCr7)Ncitextr r-rrrrSrzCITextExtension.__init__Nr9rrrrr?Qr:r?c@r5)CryptoExtensioncCr7)Npgcryptor r-rrrrYrzCryptoExtension.__init__Nr9rrrrrAWr:rAc@r5)HStoreExtensioncCr7)Nhstorer r-rrrr_rzHStoreExtension.__init__Nr9rrrrrC]r:rCc@r5)TrigramExtensioncCr7)Npg_trgmr r-rrrrerzTrigramExtension.__init__Nr9rrrrrEcr:rEc@r5)UnaccentExtensioncCr7)Nunaccentr r-rrrrkrzUnaccentExtension.__init__Nr9rrrrrGir:rGc@r5)NotInTransactionMixincCs|jjr td|jjdS)Nz_The %s operation cannot be executed inside a transaction (set atomic = False on the migration).)rin_atomic_blockr __class__r0rr#rrr_ensure_not_in_transactionpsz0NotInTransactionMixin._ensure_not_in_transactionN)r0r1r2rMrrrrrIos rIc@,eZdZdZdZddZddZddZd S) AddIndexConcurrentlyzDCreate an index using PostgreSQL's CREATE INDEX CONCURRENTLY syntax.FcCsd|jjd|jj|jfS)Nz7Concurrently create index %s on field(s) %s of model %s, )indexr joinfields model_namer-rrrr.}s  zAddIndexConcurrently.describecCsD|||j||j}||jj|r |j||jdddSdSNT) concurrently) rMapps get_modelrTallow_migrate_modelrr add_indexrQrrr#r$r%modelrrrr& z&AddIndexConcurrently.database_forwardscCsD|||j||j}||jj|r |j||jdddSdSrU) rMrWrXrTrYrr remove_indexrQr[rrrr'r]z'AddIndexConcurrently.database_backwardsNr0r1r2__doc__atomicr.r&r'rrrrrOys  rOc@rN) RemoveIndexConcurrentlyzBRemove an index using PostgreSQL's DROP INDEX CONCURRENTLY syntax.FcCsd|j|jfS)Nz$Concurrently remove index %s from %s)r rTr-rrrr.sz RemoveIndexConcurrently.describecCs^|||j||j}||jj|r-|j||jf}| |j }|j ||dddSdSrU) rMrWrXrTrYrrmodelsmodel_name_lowerget_index_by_namer r^)rrr#r$r%r\from_model_staterQrrrr&  z)RemoveIndexConcurrently.database_forwardscCs^|||j||j}||jj|r-|j||jf}| |j }|j ||dddSdSrU) rMrWrXrTrYrrrcrdrer rZ)rrr#r$r%r\to_model_staterQrrrr'rgz*RemoveIndexConcurrently.database_backwardsNr_rrrrrbs  rbc@s<eZdZdddddZddZdd Zd d Zd d ZdS)CollationOperationlibcT)provider deterministiccCs||_||_||_||_dSr )r localerkrl)rr rmrkrlrrrrs zCollationOperation.__init__cCrr rrrrrrrz!CollationOperation.state_forwardscCsJ|j|jd}|jr|jdkr|j|d<|jdur|j|d<|jjg|fS)N)r rmrjrkFrl)r rmrkrlrKr2)rkwargsrrr deconstructs   zCollationOperation.deconstructc Cs|jdur|jjjstd|jdkr|jjjstdd||ji}|jdkr1||j|d<|jdur:d|d<| d ||j d d d | Dd dS)NFz4Non-deterministic collations require PostgreSQL 12+.rjz*Non-libc providers require PostgreSQL 10+.rmrkfalserlz$CREATE COLLATION %(name)s (%(args)s)rPcss"|] \}}|d|VqdS)=Nr).0optionvaluerrr s z6CollationOperation.create_collation..)r args) rlrfeatures%supports_non_deterministic_collationsrrk&supports_alternate_collation_providersr rmrr rRitems)rr#rvrrrcreate_collations&     z#CollationOperation.create_collationcCs|d||jdS)NzDROP COLLATION %s)rr r rLrrrremove_collationsz#CollationOperation.remove_collationN)r0r1r2rrror{r|rrrrris  ric@4eZdZdZddZddZddZedd Zd S) CreateCollationzCreate a collation.cC.|jjdkst|jj|sdS||dSNr)rrrrrr{r"rrrr& z!CreateCollation.database_forwardscC"t|jj|s dS||dSr )rrrrr|r"rrrr'z"CreateCollation.database_backwardscC d|jS)NzCreate collation r r-rrrr. zCreateCollation.describecCd|jS)Nzcreate_collation_%sr lowerr-rrrr/z'CreateCollation.migration_name_fragmentN r0r1r2r`r&r'r.r4r/rrrrr~r~c@r}) RemoveCollationzRemove a collation.cCrr)rrrrrr|r"rrrr&rz!RemoveCollation.database_forwardscCrr )rrrrr{r"rrrr'rz"RemoveCollation.database_backwardscCr)NzRemove collation r r-rrrr.rzRemoveCollation.describecCr)Nzremove_collation_%srr-rrrr/rz'RemoveCollation.migration_name_fragmentNrrrrrrrrN)django.contrib.postgres.signalsrrr django.dbrrdjango.db.migrationsrr$django.db.migrations.operations.baser r r6r;r=r?rArCrErGrIrOrbrir~rrrrrs& 6 3