
    h.                         S SK Jr  S SKJrJr  S SKJrJrJrJ	r	J
r
  S SKJr  S SKJr  S SKJr  S SKJr  S/r " S	 S5      r " S
 S\	5      rg)    )NoneType)names_digestsplit_identifier)ColExpressionListFFuncOrderBy)Collate)Q)Query)	partitionIndexc                   x    \ rS rSrSrSrSSSSSSS.S jr\S 5       rS	 r	SS
 jr
S rS rS rS rS rS rSrg)r      idx    N)fieldsnamedb_tablespace	opclasses	conditionincludec                   U(       a  U(       d  [        S5      e[        U[        [        45      (       d  [        S5      eU(       a  U(       d  [        S5      e[        U[        [
        45      (       d  [        S5      e[        U[        [
        45      (       d  [        S5      eU(       d  U(       d  [        S5      eU(       a  U(       a  [        S5      eU(       a  U(       d  [        S5      eU(       a  U(       a  [        S	5      eU(       a#  [        U5      [        U5      :w  a  [        S
5      eU(       a"  [        S U 5       5      (       d  [        S5      eU(       a  U(       d  [        S5      e[        U[        [        [
        45      (       d  [        S5      e[	        U5      U l        U R                   Vs/ s H.  nUR                  S5      UR                  S5      (       a  SOS4PM0     snU l        U=(       d    SU l        X0l        X@l        XPl        U(       a  [        U5      OSU l        [        S U 5       5      U l        g s  snf )Nz(An index must be named to use opclasses.z%Index.condition must be a Q instance.z(An index must be named to use condition.z%Index.fields must be a list or tuple.z(Index.opclasses must be a list or tuple.z@At least one field or expression is required to define an index.z4Index.fields and expressions are mutually exclusive.z*An index must be named to use expressions.zgIndex.opclasses cannot be used with expressions. Use django.contrib.postgres.indexes.OpClass() instead.zGIndex.fields and Index.opclasses must have the same number of elements.c              3   B   #    U  H  n[        U[        5      v   M     g 7fN)
isinstancestr).0fields     J/var/www/html/env/lib/python3.13/site-packages/django/db/models/indexes.py	<genexpr>!Index.__init__.<locals>.<genexpr>;   s     I&j44&s   z8Index.fields must contain only strings with field names.zA covering index must be named.z&Index.include must be a list or tuple.-DESC r   c              3   f   #    U  H'  n[        U[        5      (       a  [        U5      OUv   M)     g 7fr   )r   r   r   )r    
expressions     r"   r#   r$   L   s,      !
)
 (
C88AjMjH)s   /1)
ValueErrorr   r   r   listtuplelenallr   removeprefix
startswithfields_ordersr   r   r   r   r   expressions)	selfr   r   r   r   r   r   r2   
field_names	            r"   __init__Index.__init__   s    TGHH)h]33DEETGHH&4-00DEE)dE]33GHH6R  6F  tIJJ9E  VI6  #I&IIIWXX4>??'HdE#:;;EFF6l #kk
)
 $$S)Z5J5J35O5O6UWX)
 JB	*"")0uW~b  !
)!
 

s   >5Ic                 ,    [        U R                  5      $ r   )boolr2   r3   s    r"   contains_expressionsIndex.contains_expressionsQ   s    D$$%%    c                   ^ U R                   c  g [        USS9nUR                  U R                   5      nUR                  TR                  S9nUR                  UTR                  5      u  pgU[        U4S jU 5       5      -  $ )NF)model
alias_cols)
connectionc              3   F   >#    U  H  nTR                  U5      v   M     g 7fr   )quote_value)r    pschema_editors     r"   r#   +Index._get_condition_sql.<locals>.<genexpr>\   s     HA=44Q77s   !)r   r   build_whereget_compilerr@   as_sqlr,   )r3   r>   rD   querywherecompilersqlparamss     `     r"   _get_condition_sqlIndex._get_condition_sqlU   sw    >>!Ee4!!$..1%%1I1I%Jll8]-E-EFUHHHHHr<   c                 h   U R                    Vs/ s H'  oQR                  R                  U5      R                  PM)     nnU R	                  X5      nU R
                  (       ap  / nU R
                   H:  n	[        U	5      n
U
R                  UR                  5        UR                  U
5        M<     [        U6 R                  [        USS95      nS nS nOU R                   VVs/ s H   u  p^UR                  R                  U5      PM"     nnnUR                  R                  R                  (       a  U R                   Vs/ s H  oS   PM	     nnOS/[!        U R                  5      -  nS nUR"                  " U4UU R$                  UU R&                  UU R(                  UUUS.	UD6$ s  snf s  snnf s  snf )NF)r?      r'   )	r   r   usingr   col_suffixesr   r   r   r2   )r   _meta	get_fieldcolumnrN   r2   IndexExpressionset_wrapper_classesr@   appendr   resolve_expressionr   r1   featuressupports_index_column_orderingr-   _create_index_sqlr   r   r   )r3   r>   rD   rR   kwargsr4   r   r   index_expressionsr)   index_expressionr2   r   rS   _orders                   r"   
create_sqlIndex.create_sql^   s   GK||
GSKK!!*-44| 	 
 ++EA	 ""..
#2:#>  44]5M5MN!(()9: / )*;<OOe.K FL &*%7%7%7MJ %%j1%7   ''00OO6:6H6HI6HUa6HI "tc$*<*<&==K..
,,%nn#
 
 	
3
 
  Js   .F$ 'F)=F/c                 <    UR                   " XR                  40 UD6$ r   )_delete_index_sqlr   )r3   r>   rD   r^   s       r"   
remove_sqlIndex.remove_sql   s    ..uiiJ6JJr<   c                    U R                   R                  < SU R                   R                  < 3nUR                  SS5      nSU R                  0nU R
                  (       a  U R
                  US'   U R                  b  U R                  US'   U R                  (       a  U R                  US'   U R                  (       a  U R                  US'   U R                  (       a  U R                  US	'   XR                  U4$ )
N.zdjango.db.models.indexeszdjango.db.modelsr   r   r   r   r   r   )	__class__
__module____name__replacer   r   r   r   r   r   r2   )r3   pathr^   s      r"   deconstructIndex.deconstruct   s    ..33T^^5L5LM||68JK$))$;;#{{F8)&*&8&8F?#>>"&..F;>>"&..F;<< $F9&&//r<   c                 L    U R                  5       u  pnU R                  " U0 UD6$ )zCreate a copy of this Index.)rp   rk   )r3   ra   argsr^   s       r"   cloneIndex.clone   s(    **,~~t.v..r<   c           	         [        UR                  R                  5      u  p#U R                   VVs/ s H*  u  pEUR                  R	                  U5      R
                  PM,     nnn[        X`R                  5       VVVs/ s H  u  nu  pEU(       a  SOSU-  PM     nnnnU/U-   U R                  /-   n	USS < SUS   SS < S[        U	SS	06< SU R                  < 3< 3U l	        [        U R                  5      U R                  :  a  [        S
5      eU R                  S   S:X  d"  U R                  S   R                  5       (       a  SU R                  SS -  U l	        ggs  snnf s  snnnf )z
Generate a unique name for the index.

The name is divided into 3 parts - table name (12 chars), field name
(8 chars) and unique hash + suffix (10 chars). Each part is made to
fit its size by truncating the excess length.
z-%sz%sN   ra   r      length   zVIndex too long for multiple database support. Is self.suffix longer than 3 characters?zD%srQ   )r   rT   db_tabler1   rU   rV   zipsuffixr   r   r-   max_name_lengthr*   isdigit)
r3   r>   ra   
table_namer4   rb   column_namescolumn_namecolumn_names_with_order	hash_datas
             r"   set_name_with_modelIndex.set_name_with_model   sf    ))=)=> &*%7%7
%7!
 KK!!*-44%7 	 
 58005#
500j e$+55 	  #
  L#::dkk]J	sOOBQ#Y9q94;;G
	
 tyy>D000,  99Q<3$))A,"6"6"8"8		!"-DI #9/
#
s   1E$>E*c                    SU R                   R                  < SU R                  (       d  SOS[        U R                  5      -  < U R                  (       d  SOS[        U R                  5      -  < U R
                  (       d  SOS[        U R
                  5      -  < U R                  c  SOS[        U R                  5      -  < U R                  c  SOSU R                  -  < U R                  (       d  SOS	[        U R                  5      -  < U R                  (       d  SOS
[        U R                  5      -  < S3$ )N<:r'   z
 fields=%sz expressions=%sz name=%sz db_tablespace=%sz condition=%sz include=%sz opclasses=%s>)
rk   __qualname__r   reprr2   r   r   r   r   r   r9   s    r"   __repr__Index.__repr__   s    NN''kkB|d4;;6G'GG&&B,=TEUEU@V,VViiBZ$tyy/%AA %%- (40B0B+CCD ..(Bo.NNllBT\\8J(JJnnB/D<P*PP
 	
r<   c                     U R                   UR                   :X  a!  U R                  5       UR                  5       :H  $ [        $ r   )rk   rp   NotImplemented)r3   others     r"   __eq__Index.__eq__   s5    >>U__,##%):):)<<<r<   )r   r   r2   r   r1   r   r   r   )r'   )rm   rl   r   __firstlineno__r}   r~   r5   propertyr:   rN   rc   rg   rp   rt   r   r   r   __static_attributes__r   r<   r"   r   r      sh    F O
 <
| & &I&
PK0 /
!.F
 r<   c                   f   ^  \ rS rSrSrSr\\4rS	S jr	\
S 5       r     S
U 4S jjrS rSrU =r$ )rW      z7Order and wrap expressions for CREATE INDEX statements.z%(expressions)sc                     U(       aS  UR                   R                  (       a7  [        U R                   Vs/ s H  nU[        Ld  M  UPM     sn5      U l        g g g s  snf r   )r[   collate_as_index_expressionr,   wrapper_classesr   )r3   r@   wrapper_clss      r"   rX   #IndexExpression.set_wrapper_classes   sX    *--II#( (,';';';"'1  ';$D  J:s   AAc                     Xl         g r   r   )clsr   s     r"   register_wrappers!IndexExpression.register_wrappers   s    -r<   c           	        >^  [        T R                  5       5      n[        U 4S jU5      u  pxU V	s/ s H  n	[        U	5      PM     n
n	[	        U
5      [	        [        U
5      5      :w  aA  [        SSR                  T R                   Vs/ s H  oR                  PM     sn5      -  5      eUS[	        U5      S-    U:w  aA  [        SSR                  T R                   Vs/ s H  oR                  PM     sn5      -  5      eUS   nUR                  UUUUU5      n[        U[        5      (       d
  [        USS9nU(       a  [        UU 4S jS	9nU V	s/ s H  oR                  5       PM     nn	[!        US S
 5       H  u  pU	R#                  XS-      /5        M     US
   R#                  U/5        T R#                  US   /5        OT R#                  U/5        [$        TT ])  XX4U5      $ s  sn	f s  snf s  snf s  sn	f )Nc                 0   > [        U TR                  5      $ r   )r   r   )er3   s    r"   <lambda>4IndexExpression.resolve_expression.<locals>.<lambda>   s    jD$8$89r<   zAMultiple references to %s can't be used in an indexed expression.z, rQ   z8%s must be topmost expressions in an indexed expression.z(%(expressions)s))templatec                 L   > TR                   R                  [        U 5      5      $ r   )r   indextype)wr3   s    r"   r   r     s    d2288aAr<   )keyr   )r+   flattenr   r   r-   setr*   joinr   r   rZ   r   r   r	   sortedcopy	enumerateset_source_expressionssuper)r3   rI   allow_joinsreuse	summarizefor_saver2   r_   wrapperswrapperwrapper_typesr   root_expressionresolve_root_expressionirk   s   `              r"   rZ   "IndexExpression.resolve_expression   s    4<<>*&/9'
# 7??h7gh?}S%7!88))AEAUAUVAU+--AUV  q3x=1,-9J))AEAUAUVAU+--AUV  ,A."1"D"D#
 1377"?=PQOAH 7??h7hH?'"6
..Q/@A 7 RL//0AB''!6 ''(9:w)(
 	
W @ W W* @s   G*	G/G4G9c                 (    U R                   " X40 UD6$ r   )rH   )r3   rK   r@   extra_contexts       r"   	as_sqliteIndexExpression.as_sqlite)  s    {{8A=AAr<   r   r   )NTNFF)rm   rl   r   r   __doc__r   r
   r   r   rX   classmethodr   rZ   r   r   __classcell__)rk   s   @r"   rW   rW      sQ    A H(O	 . .
 ;
zB Br<   rW   N)typesr   django.db.backends.utilsr   r   django.db.models.expressionsr   r   r   r	   r
   django.db.models.functionsr   django.db.models.query_utilsr   django.db.models.sqlr   django.utils.functionalr   __all__r   rW   r   r<   r"   <module>r      sA     C N N . * & -)G GTTBd TBr<   