
    j                     B    S SK Jr  S SKJr  S SKJrJr   " S S\5      rg)    )GeometryField)DatabaseSchemaEditor)ColFuncc                      ^  \ rS rSrSrSrSrSrSrS r	U 4S jr
S	S
.U 4S jjrU 4S jr SU 4S jjrS rU 4S jrS rSrU =r$ )PostGISSchemaEditor   GISTGIST_GEOMETRY_OPS_NDzST_ConvexHull(%(expressions)s)zLALTER COLUMN %(column)s TYPE %(type)s USING ST_Force3D(%(column)s)::%(type)szLALTER COLUMN %(column)s TYPE %(type)s USING ST_Force2D(%(column)s)::%(type)sc                 L    U R                   R                  R                  U5      $ N)
connectionopsgeo_quote_name)selfnames     e/var/www/html/KUNJ/venv/lib/python3.13/site-packages/django/contrib/gis/db/backends/postgis/schema.pyr   "PostGISSchemaEditor.geo_quote_name   s    ""11$77    c                 H   > [        USS5      (       a  g[        TU ]	  X5      $ )Nspatial_indexFT)getattrsuper_field_should_be_indexed)r   modelfield	__class__s      r   r   ,PostGISSchemaEditor._field_should_be_indexed   s%    5/511w/==r   N)fieldsc                   > Ub#  [        U5      S:w  d  [        US   S5      (       d  [        TU ]  " U4SU0UD6$ U R                  " XS   40 UD6$ )N   r   geodeticr   )lenhasattrr   _create_index_sql_create_spatial_index_sql)r   r   r   kwargsr   s       r   r%   %PostGISSchemaEditor._create_index_sql   sW    >S[A-WVAY
5S5S7,UL6LVLL--eAYI&IIr   c                   > [        US5      (       a  [        US5      (       d  [        TU ]	  XX4XV5      $ UR                  S:X  a  UR                  S:X  a  U R                  nO9UR                  S:X  a  UR                  S:X  a  U R
                  nOU R                  nUU R                  UR                  5      USS.-  / 4/ 4$ )z&
Special case when dimension changed.
dim       )columntype	collation)	r$   r   _alter_column_type_sqlr*   sql_alter_column_to_3dsql_alter_column_to_2dsql_alter_column_type
quote_namer.   )	r   table	old_field	new_fieldnew_typeold_collationnew_collation	sql_alterr   s	           r   r1   *PostGISSchemaEditor._alter_column_type_sql    s     y%((	50I0I71)}  ==A)--1"433I]]aIMMQ$633I22I "ooi.>.>?$!#  
 	
r   c	                 x  > [         TU ]  UUUUUUUUS9  [        U[        5      =(       a    UR                  n	[        U[        5      =(       a    UR                  n
U	(       d(  U
(       a!  U R                  U R                  X5      5        g U	(       a)  U
(       d!  U R                  U R                  X5      5        g g g )N)strict)r   _alter_field
isinstancer   r   executer&   _delete_spatial_index_sql)r   r   r7   r8   old_typer9   old_db_paramsnew_db_paramsr?   old_field_spatial_indexnew_field_spatial_indexr   s              r   r@    PostGISSchemaEditor._alter_field>   s     	 	 		
 y-0LY5L5L 	  y-0LY5L5L 	  '+BLL77IJ$-DLL77IJ .E$r   c                 f    U R                  UR                  R                  UR                  /S5      $ )N_id)_create_index_name_metadb_tabler.   )r   r   r   s      r   _create_spatial_index_name.PostGISSchemaEditor._create_spatial_index_name_   s'    &&u{{';';ell^USSr   c           	      `  > S nS nU/nUR                   S:X  a!  [        [        S U5      U R                  S9nS nO.UR                  S:  a  UR
                  (       d  U R                  /nUR                  S5      =n(       d  U R                  X5      n[        TU ])  UUUSU R                  -  UUS9$ )NRASTER)templater+   r   z	 USING %s)r   r   using	opclassesexpressions)	geom_typer   r   rast_index_templater*   	geographygeom_index_ops_ndgetrO   r   r%   geom_index_type)	r   r   r   r'   rV   rU   r   r   r   s	           r   r&   -PostGISSchemaEditor._create_spatial_index_sqlb   s    	??h& s4/$:R:RSKFYY]5??//0I

6***225@Dw( 4 44# ) 
 	
r   c                 F    U R                  X5      nU R                  X5      $ r   )rO   _delete_index_sql)r   r   r   
index_names       r   rC   -PostGISSchemaEditor._delete_spatial_index_sql{   s#    44UB
%%e88r    )F)__name__
__module____qualname____firstlineno__r\   rZ   rX   r2   r3   r   r   r%   r1   r@   rO   r&   rC   __static_attributes____classcell__)r   s   @r   r   r      sl    O.: 	W  	W 8>
 26 J J
N KBT
29 9r   r   N)django.contrib.gis.db.modelsr   $django.db.backends.postgresql.schemar   django.db.models.expressionsr   r   r   rb   r   r   <module>rl      s    6 E 2w9. w9r   