
    +'&hm                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 dd	lm
Z
 dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z# ddl$m%Z% ddl$m&Z& ddl$m'Z' ddl(m)Z) ddl(m*Z* ddl(m+Z+  ej,                    Z-	  e.            Z/ G d d e          Z0d! Z1 e1             d" Z2 e2             d# Z3d$ Z4 ej5        d%           ej5        d%d&           G d' d(ej6                                          Z7 ej5        d)           ej5        d)d*           G d+ d,ej8                                          Z9 ej:        e7          d-             Z; ej:        e9          d.             Z< eed/          d0             Z= eed/          d1             Z> ej?        e7          d2             Z@ ej?        e9          d3             ZAe-B                    ej6                  d4             ZCe-B                    ej8                  d5             ZD ej5        d6           G d7 d8ejE                              ZF ej5        d9           G d: d;ejG                              ZH ej:        eF          d<             ZI ej:        eH          d=             ZJ ej?        eF          d>             ZK ej?        eH          d?             ZLe-B                    ejE                  d@             ZMe-B                    ejG                  dA             ZN ej5        dB           ej5        dBdC           G dD dEejO                                          ZP ej5        dF           ej5        dFdG           G dH dIejQ                                          ZR ej:        eP          dJ             ZS ej:        eR          dK             ZT ej?        eP          dL             ZU ej?        eR          dM             ZVe-B                    ejO                  dN             ZWe-B                    ejQ                  dO             ZXdPS )Qz0Some helpers to use with Alembic migration tool.    )	renderers)rewriter)_add_column)
_add_index)
_add_table)_drop_column)_drop_index)_drop_table)RenameTable)format_table_name)visit_rename_table)
SQLiteImpl)BatchOperations)
Operations)ops)Column)text)MySQLDialect)SQLiteDialect)compiles)	DropTable)func)TypeDecorator)	Geography)Geometry)Raster)_check_spatial_type)_get_gis_cols)_spatial_idx_namec                       e Zd ZdZdZdS )GeoPackageImplzCClass to copy the Alembic implementation from SQLite to GeoPackage.
geopackageN)__name__
__module____qualname____doc____dialect__     V/var/www/html/reinick/venv/lib/python3.11/site-packages/geoalchemy2/alembic_helpers.pyr!   r!   (   s        MMKKKr)   r!   c                  n    t           j        } dd}| j        |_        |t           _        | t           _        dS )8Monkey patch SQLAlchemy to fix spatial index reflection.Nc                     | j         ||fdd i|}|j        j        dk    }	 |                    d                    |rdnd                                                    }|s|S n# t          $ r |cY S w xY w|r$t          d                    |                    }n"t          d                    |                    }|                    |                                          }	|	rt          d	 |D                       }
|	D ]f}|d
         }t          ||          }t          |d                   r||
v r4|                    ||gdddid           |
                    |           g|S )Nschemar"   zPRAGMA main.table_info({})gpkg_geometry_columnsgeometry_columnsa@  SELECT A.table_name, A.column_name, IFNULL(B.has_index, 0) AS has_index
                FROM "gpkg_geometry_columns"
                AS A
                LEFT JOIN (
                    SELECT table_name, column_name, COUNT(*) AS has_index
                    FROM gpkg_extensions
                    WHERE LOWER(table_name) = LOWER('{table_name}')
                        AND extension_name = 'gpkg_rtree_index'
                ) AS B
                ON LOWER(A.table_name) = LOWER(B.table_name)
                WHERE LOWER(A.table_name) = LOWER('{table_name}');
            )
table_namezSELECT *
                FROM geometry_columns
                WHERE f_table_name = '{}'
                ORDER BY f_table_name, f_geometry_column;c                     g | ]
}|d          S namer(   .0is     r*   
<listcomp>zR_monkey_patch_get_indexes_for_sqlite.<locals>.spatial_behavior.<locals>.<listcomp>b       ">">">1V9">">">r)      r   _column_flagTr4   column_namesuniquedialect_options)_get_indexes_normal_behaviordialectr4   exec_driver_sqlformatfetchallAttributeErrorr   executesetr   boolappendadd)self
connectionr1   r.   kwindexesis_gpkgis_spatial_dbspatial_index_queryspatial_indexesreflected_namesidxidx_colidx_names                 r*   spatial_behaviorz>_monkey_patch_get_indexes_for_sqlite.<locals>.spatial_behavior2   s   3$3J
^^SW^[]^^$)\9
	&66077/6N++<N   hjj	 
 !  	 	 	NNN	  	"& )   # #" #'= >DV> >	# # %,,-@AAJJLL 	.!">">g">">">??O& . .a&,ZAACG}} O(C(C ()0	"#,:D+A	     ##H----s   AA& &A54A5N)r   get_indexesr&   rA   normal_behaviorrX   s     r*   $_monkey_patch_get_indexes_for_sqliter]   .   sG    #/O@ @ @ @D  /6 0M1@M...r)   c                  n    t           j        } dd}| j        |_        |t           _        | t           _        dS )r,   Nc                     | j         ||fdd i|}d                    |          }||d                    |          z  }|                    t          |                                                    }|rmt          d |D                       }|D ]Q}	|	d         }
t          ||
          }||v r|                    ||
gdddid           |                    |           R|S )	Nr.   zSELECT DISTINCT
                COLUMN_NAME
            FROM INFORMATION_SCHEMA.STATISTICS
            WHERE TABLE_NAME = '{}' AND INDEX_TYPE = 'SPATIAL'z AND TABLE_SCHEMA = '{}'c                     g | ]
}|d          S r3   r(   r5   s     r*   r8   zQ_monkey_patch_get_indexes_for_mysql.<locals>.spatial_behavior.<locals>.<listcomp>   r9   r)   r   r<   Tr=   )	rA   rD   rG   r   rE   rH   r   rJ   rK   )rL   rM   r1   r.   rN   rO   has_index_queryrS   rT   rU   rV   rW   s               r*   rX   z=_monkey_patch_get_indexes_for_mysql.<locals>.spatial_behavior   s:   3$3J
^^SW^[]^^B CI&C
 C
 	 =DDVLLLO$,,T/-B-BCCLLNN 	.!">">g">">">??O& . .a&,ZAA.. ()0	"#,:D+A	     ##H----r)   rY   )r   rZ   r&   rA   r[   s     r*   #_monkey_patch_get_indexes_for_mysqlrb   |   sC    ".O   B  /6/L0?L---r)   c                     | dk    rPt          |t          t          t          f          r.|j        j        }|j                            d|            d|z  S dS )z%Add proper imports for spatial types.typezfrom geoalchemy2 import z%rF)
isinstancer   r   r   	__class__r#   importsrK   )obj_typeobjautogen_contextimport_names       r*   render_itemrl      s^    6jxF.KLLm,##$L{$L$LMMMcz 5r)   c                    |dk    r|                     d          s|                     d          s|                     d          s~|                     d          si|                     d          sT|                     d          s?|                     d          s*|                     d	          s|                     d
          rdS dS )a  Do not include internal tables of spatial extensions.

    .. warning::
        This function only checks the table names, so it might exclude tables that should not be.
        In such case, you should create your own function to handle your specific table names.

    tabler0   spatial_ref_sysspatialite_historysqlite_sequenceviews_geometry_columnsvirts_geometry_columnsidx_gpkg_vgpkg_FT)
startswith)ri   r4   rh   	reflected
compare_tos        r*   include_objectrz      s     7*++ ??,--  ??/00  ??,--	 
 ??344  ??344  ??6""  ??7##  ??8$$  u4r)   add_geospatial_columnbatch_add_geospatial_columnc                   L    e Zd ZdZedd            Zd Ze	 	 dd            ZdS )AddGeospatialColumnOpzAdd a Geospatial Column in an Alembic migration context.

    This method originates from:
    https://alembic.sqlalchemy.org/en/latest/api/operations.html#operation-plugins
    Nc                 H     | |||          }|                     |          S )zNHandle the different situations arising from adding geospatial column to a DB.r.   invoke)cls
operationsr1   columnr.   ops         r*   r{   z+AddGeospatialColumnOp.add_geospatial_column   s.     SVF333  $$$r)   c                 b    t                               | j        | j        | j        j                  S ,Used to autogenerate the downgrade function.)DropGeospatialColumnOpfrom_column_and_tablenamer.   r1   r   r4   rL   s    r*   reversezAddGeospatialColumnOp.reverse   s*    %??K$+*:
 
 	
r)   c                     i }|r||d<   |r||d<    | |j         j        |fd|j         j        i|}|                    |          S )zLIssue an "add column" instruction using the current batch migration context.insert_beforeinsert_afterr.   implr1   r.   r   )r   r   r   r   r   rN   r   s          r*   r|   z1AddGeospatialColumnOp.batch_add_geospatial_column   s}      	0"/B 	.!-B~SO&
 
 ?)
 	
 
   $$$r)   rY   )NN)r#   r$   r%   r&   classmethodr{   r   r|   r(   r)   r*   r~   r~      su          % % % [%

 
 
 
 % % % [% % %r)   r~   drop_geospatial_columnbatch_drop_geospatial_columnc                   F    e Zd ZdZedd            Zd Zed             ZdS )r   z9Drop a Geospatial Column in an Alembic migration context.Nc                 D     | ||fd|i|}|                     |          S )zRHandle the different situations arising from dropping geospatial column from a DB.r.   r   )r   r   r1   column_namer.   rN   r   s          r*   r   z-DropGeospatialColumnOp.drop_geospatial_column   s6     S[>>>2>>  $$$r)   c                 X    t                               | j        | j        | j                  S r   )r~   r   r.   r1   r   r   s    r*   r   zDropGeospatialColumnOp.reverse  s'    $>>K$+
 
 	
r)   c                 l     | |j         j        |fd|j         j        i|}|                    |          S )zLIssue a "drop column" instruction using the current batch migration context.r.   r   )r   r   r   rN   r   s        r*   r   z3DropGeospatialColumnOp.batch_drop_geospatial_column	  sT     SO&
 
 ?)
 	
 
   $$$r)   rY   )r#   r$   r%   r&   r   r   r   r   r(   r)   r*   r   r      se         DC% % % [%

 
 
 % % [% % %r)   r   c           
         |j         }|j        j        }|                                 j        }|j        dk    rt          |j        t                    r |j        j                            |          }n|j        j        }| 	                    t          j        |||j        |j        |j        |j                              dS d|j        v r)| j                            ||j        |j                   dS dS )aB  Handle the actual column addition according to the dialect backend.

    Args:
        operations: Operations object from alembic base, defining high level migration operations.
        operation: AddGeospatialColumnOp call, with attributes for table_name, column_name,
            column_type, and optional keywords.
    sqlite
postgresqlr   N)r1   r   r4   get_bindrB   re   r   rd   load_dialect_implrG   r   AddGeometryColumnsridgeometry_type	dimensionnullabler   
add_columnr.   )r   	operationr1   r   rB   geospatial_core_types         r*   r{   r{     s    %J"'K!!##+G|xi&66 	9 $-#3#8#J#J7#S#S  #,#3#8 "$)$2$.(11 		
 		
 		
 		
 		
 
	%	%""# 	# 	
 	
 	
 	
 	
 
&	%r)   c                    |j         }|                    | j                  }|                                 j        }|j        dk    rt                              |            | j        j	        ||fd|j
        i|j         dS )aA  Handle the actual column removal according to the dialect backend.

    Args:
        operations: Operations object from alembic base, defining high level migration operations.
        operation: AddGeospatialColumnOp call, with attributes for table_name, column_name,
            column_type, and optional keywords.
    r   r.   N)r1   	to_columnmigration_contextr   rB   r4   _SPATIAL_TABLESrK   r   drop_columnr.   rN   )r   r   r1   r   rB   s        r*   r   r   <  s     %J  !=>>F!!##+G|xJ'''JO
F\\9;K\y|\\\\\r)   r   c                     | j         t          v }| j        t          v }|s|r;dt          || j         | j                  dt          || j        | j                  dS t          | |fi |S )zGSpecific compilation rule to rename spatial tables with SQLite dialect.zSELECT RenameTable(NULL, 'z', ''))r1   r   new_table_namer   r.   r   )elementcompilerrN   table_is_spatialnew_table_is_spatials        r*   visit_rename_geospatial_tabler   O  s     )_<"1_D ;/ ; h(:GNKKKKh(>OOOO
 	

 "'8::r:::r)   c                     | j         j        t          v }|rdt          || j         j        d          dS  |j        | fi |S )zESpecific compilation rule to drop spatial tables with SQLite dialect.zSELECT DropTable(NULL, 'Nr   )r   r4   r   r   visit_drop_table)r   r   rN   r   s       r*   visit_drop_geospatial_tabler   `  sd     +> 8 8 h(<dCCCC
 	
 )x(77B777r)   c                 N    t          | |          }|                    dd          S )z?Render the add_geospatial_column operation in migration script.z.add_column(z.add_geospatial_column()r   replacerj   r   
col_renders      r*   render_add_geo_columnr   n  s*     _b11Jn.GHHHr)   c                 N    t          | |          }|                    dd          S )z@Render the drop_geospatial_column operation in migration script.z.drop_column(z.drop_geospatial_column()r   r   r   s      r*   render_drop_geo_columnr   u  s*     or22Jo/IJJJr)   c                 Z   |j         j        }t          |t                    r!| j        j        }|                    |          }t          |t          t          t          f          rDd|j         j        _
        d|j         j        _        t          |j        |j         |j                  }n|}|S )z=Replace the default AddColumnOp by a geospatial-specific one.FNr   )r   rd   re   r   bindrB   r   r   r   r   spatial_index_spatial_index_reflectedr~   r1   r.   contextrevisionr   col_typerB   new_ops         r*   add_geo_columnr   |  s     y~H(M** 7,&--g66(Xy&9:: ',	$26	/&r}bi	RRRMr)   c                 0   |                                 j        }t          |t                    r!| j        j        }|                    |          }t          |t          t          t          f          r"t          |j        |j        |j                  }n|}|S )z>Replace the default DropColumnOp by a geospatial-specific one.r   )r   rd   re   r   r   rB   r   r   r   r   r   r1   r   r.   r   s         r*   drop_geo_columnr     s     ||~~"H(M** 7,&--g66(Xy&9:: 'r~biXXXMr)   create_geospatial_tablec                   \     e Zd ZdZed             Zd Zed fd	            Zd fd	Z xZ	S )CreateGeospatialTableOpzCreate a Geospatial Table in an Alembic migration context.

    This method originates from:
    https://alembic.sqlalchemy.org/en/latest/api/operations.html#operation-plugins
    c                 @     | ||fi |}|                     |          S )zOHandle the different situations arising from creating geospatial table to a DB.r   )r   r   r1   columnsrN   r   s         r*   r   z/CreateGeospatialTableOp.create_geospatial_table  s1     SW++++  $$$r)   c                 h    t                               |                                 | j                  S r   )_namespace_metadata)r   
from_tableto_tabler   r   s    r*   r   zCreateGeospatialTableOp.reverse  s0    %00MMOO $ 8 1 
 
 	
r)   Nc                 L    t                                          ||          }|S rY   superr   r   rn   r   ri   rf   s       r*   r   z"CreateGeospatialTableOp.from_table  "    gg  (;<<
r)   c                     t                                          |          }|j        D ]+}	 |j        j        rd|j        _        # t
          $ r Y (w xY w|S NF)r   r   r   rd   r   rF   )rL   r   rn   colrf   s       r*   r   z CreateGeospatialTableOp.to_table  sp      !233 = 	 	C8) 3-2CH*!   s   A
AArY   )
r#   r$   r%   r&   r   r   r   r   r   __classcell__rf   s   @r*   r   r     s          % % [%

 
 
      [
 
 
 
 
 
 
 
 
 
r)   r   drop_geospatial_tablec                   Z     e Zd Zedd            Zd Zed fd	            Zd fd	Z xZS )DropGeospatialTableOpNc                 H     | |||          }|                     |          S )zQHandle the different situations arising from dropping geospatial table from a DB.)r.   table_kwr   )r   r   r1   r.   rN   r   s         r*   r   z+DropGeospatialTableOp.drop_geospatial_table  s.     SFR888  $$$r)   c                 h    t                               |                                 | j                  S r   )r   r   r   r   r   s    r*   r   zDropGeospatialTableOp.reverse  s0    &11MMOO $ 8 2 
 
 	
r)   c                 L    t                                          ||          }|S rY   r   r   s       r*   r   z DropGeospatialTableOp.from_table  r   r)   c                 J    t                                          |          }|S rY   )r   r   )rL   r   rn   rf   s      r*   r   zDropGeospatialTableOp.to_table  s       !233r)   rY   )	r#   r$   r%   r   r   r   r   r   r   r   s   @r*   r   r     s        % % % [%

 
 
      [         r)   r   c                     |j         }|                                 } | j        |g|j        R d|j        i|j         |j        j        dk    rt          	                    |           dS dS )aC  Handle the actual table creation according to the dialect backend.

    Args:
        operations: Operations object from alembic base, defining high level migration operations.
        operation: CreateGeospatialTableOp call, with attributes for table_name, column_name,
            column_type, and optional keywords.
    r.   r   N)
r1   r   create_tabler   r.   rN   rB   r4   r   rK   )r   r   r1   r   s       r*   r   r     s     %J  D JJd):ddd9CSdW`Wcddd|H$$J''''' %$r)   c                     |j         }|                                 }|j        }|j        dk    rt                              |            | j        |fd|j        i|j         dS )a@  Handle the actual table removal according to the dialect backend.

    Args:
        operations: Operations object from alembic base, defining high level migration operations.
        operation: DropGeospatialTableOp call, with attributes for table_name, column_name,
            column_type, and optional keywords.
    r   r.   N)	r1   r   rB   r4   r   rK   
drop_tabler.   r   )r   r   r1   r   rB   s        r*   r   r     sq     %J  DlG|xJ'''J*TTY-=TASTTTTTr)   c                 N    t          | |          }|                    dd          S )zARender the create_geospatial_table operation in migration script.z.create_table(z.create_geospatial_table()r   r   rj   r   table_renders      r*   render_create_geo_tabler     s+     or22L 02MNNNr)   c                 N    t          | |          }|                    dd          S )z?Render the drop_geospatial_table operation in migration script.z.drop_table(z.drop_geospatial_table()r
   r   r   s      r*   render_drop_geo_tabler     s*     33L0IJJJr)   c                     | j         j        }t          |t          t          t
          f|          }|r1t          |j        |j        f|j	        |j
        |j        d|j        }n|}|S )z?Replace the default CreateTableOp by a geospatial-specific one.)r.   r   _constraints_included)r   rB   r   r   r   r   r   r1   r   r.   r   r   rN   )r   r   r   rB   gis_colsr   s         r*   create_geo_tabler     s~     l"GR(Iv!>HHH 
(MJ
 9 " 6"$":
 
 e
 
 Mr)   c                     | j         j        }|                                }t          |t          t
          t          f|          }|rt          |j        |j	                  }n|}|S )z=Replace the default DropTableOp by a geospatial-specific one.r   )
r   rB   r   r   r   r   r   r   r1   r.   )r   r   r   rB   rn   r   r   s          r*   drop_geo_tabler   "  s]     l"GKKMMEUXy&$A7KKH &r}RYGGGMr)   create_geospatial_indexbatch_create_geospatial_indexc                   F    e Zd Ze	 	 dd            Zd Zed             ZdS )CreateGeospatialIndexOpNFc                 H     | |||f||d|}|                     |          S )zQHandle the different situations arising from creating geospatial index into a DB.r.   r?   r   )	r   r   
index_namer1   r   r.   r?   rN   r   s	            r*   r   z/CreateGeospatialIndexOp.create_geospatial_index4  s;     SZUUURTUU  $$$r)   c                 f    t          | j        | j        | j        d         j        | j                  S )r   r   )r   r.   )DropGeospatialIndexOpr   r1   r   r4   r.   r   s    r*   r   zCreateGeospatialIndexOp.reverseC  s4    $OOQ,;	
 
 
 	
r)   c                 n     | ||j         j        |fd|j         j        i|}|                    |          S )zMIssue a "create index" instruction using the current batch migration context.r.   r   )r   r   r   r   rN   r   s         r*   r   z5CreateGeospatialIndexOp.batch_create_geospatial_indexL  sW     SO&
 
 ?)	

 
 
   $$$r)   r   )r#   r$   r%   r   r   r   r   r(   r)   r*   r   r   1  sf          % % % [%
 
 
 % % [% % %r)   r   drop_geospatial_indexbatch_drop_geospatial_indexc                   l     e Zd Z fdZe	 	 dd            Zd Zed             Zed             Z xZ	S )	r   c                H     t                      j        |i | || _        d S rY   )r   __init__r   )rL   r   argskwargsrf   s       r*   r  zDropGeospatialIndexOp.__init__b  s-    $)&)))&r)   NFc                 H     | |f||||d|}|                     |          S )zQHandle the different situations arising from dropping geospatial index from a DB.)r1   r   r.   r?   r   )	r   r   r   r1   r   r.   r?   rN   r   s	            r*   r  z+DropGeospatialIndexOp.drop_geospatial_indexf  sN     S
!#
 
 
 
   $$$r)   c                 X    t          | j        | j        f| j        | j        | d| j        S )r   r   r.   _reverse)r   r   r1   r   r.   rN   r   s    r*   r   zDropGeospatialIndexOp.reverse|  sD    &OO
 (;
 
 g
 
 	
r)   c                     |j         J t          |j                  dk    s
J d             | |j        |j         j        f|j        d         j        |j         j        t
                              |          d|j        S )Nr:   .A spatial index must be set on one column onlyr   r
  )rn   lenr   r4   r.   r   
from_indexr  )r   indexs     r*   r  z DropGeospatialIndexOp.from_index  s    {&&&5=!!Q&&&(X&&&sJK
 a(-;%,77>>
 
 l
 
 	
r)   c                 l     | |f|j         j        |j         j        d|}|                    |          S )zKIssue a "drop index" instruction using the current batch migration context.)r1   r.   r   )r   r   r   rN   r   s        r*   r  z1DropGeospatialIndexOp.batch_drop_geospatial_index  sR     S
!1?)
 
 	
 
   $$$r)   r   )
r#   r$   r%   r  r   r  r   r  r  r   r   s   @r*   r   r   _  s        ' ' ' ' '  % % % [%*	
 	
 	
 

 

 [

 % % [% % % % %r)   r   c                 r   |                                  }|j        }|j        dk    r\t          |j                  dk    s
J d            |                     t          j        |j        |j        d                              dS |	                    | j
                  }| j                            |           dS )aC  Handle the actual index creation according to the dialect backend.

    Args:
        operations: Operations object from alembic base, defining high level migration operations.
        operation: CreateGeospatialIndexOp call, with attributes for table_name, column_name,
            column_type, and optional keywords.
    r   r:   r  r   N)r   rB   r4   r  r   rG   r   CreateSpatialIndexr1   to_indexr   r   create_index)r   r   r   rB   rU   s        r*   r   r     s       DlG|x9$%%***,\***4293GIZ[\I]^^_____  !=>>$$S)))))r)   c                    |                                  }|j        }|j        dk    r4|                     t	          j        |j        |j                             dS | j        	                    |
                    | j                             dS )a=  Handle the actual index drop according to the dialect backend.

    Args:
        operations: Operations object from alembic base, defining high level migration operations.
        operation: DropGeospatialIndexOp call, with attributes for table_name, column_name,
            column_type, and optional keywords.
    r   N)r   rB   r4   rG   r   DisableSpatialIndexr1   r   r   
drop_indexr  r   )r   r   r   rB   s       r*   r  r    s       DlG|x43I4H)J_``aaaaa""9#5#5j6R#S#STTTTTr)   c                 N    t          | |          }|                    dd          S )zARender the create_geospatial_index operation in migration script.z.create_index(z.create_geospatial_index()r   r   )rj   r   
idx_renders      r*   render_create_geo_indexr    s+     OR00J.0KLLLr)   c                 ~    t          | |          }|                    dd          }|dd         d|j        dz   }|S )z?Render the drop_geospatial_index operation in migration script.z.drop_index(z.drop_geospatial_index(Nr;   z, column_name='r   )r	   r   r   )rj   r   r  r   s       r*   render_drop_geo_indexr    sO     _b11J n.GHHD 99@@DKr)   c                    | j         j        }t          |j                  dk    r|j        d         }t	          |t
                    rt          |j        t          t          t          f|          r|j                            dd          |j        d<   |j        j        r
|j        di}ni }|j                            d|          |j        d<   t          |j        |j        |j        f|j        |j        d|j        S |S )z?Replace the default CreateIndexOp by a geospatial-specific one.r:   r   postgresql_usinggistgist_geometry_ops_ndpostgresql_opsr   )r   rB   r  r   re   r   r   rd   r   r   r   rN   getuse_N_D_indexr4   r   r   r1   r.   r?   )r   r   r   rB   r   r"  s         r*   create_geo_indexr%    s	    l"G
2:!jmc6"" 	':HxF3W(
 (
 	 )+		2Df(M(MBE$%x% $"%(,B!C!#&(eii0@.&Q&QBE"#*
 yy  %   Ir)   c                 ^   | j         j        }|                                }t          |j                  dk    rt|j        d         }t          |t                    rRt          |j        t          t          t          f|          r*t          |j        f|j        |j        |j        d|j        S |S )z=Replace the default DropIndexOp by a geospatial-specific one.r:   r   )r1   r   r.   )r   rB   r  r  r   re   r   r   rd   r   r   r   r   r   r1   r4   r.   rN   )r   r   r   rB   rU   r   s         r*   drop_geo_indexr'    s     l"G
++--C
3;1k!nc6"" 		':HxF3W(
 (
 		 )=Hy	 
 %   Ir)   N)Yr&   alembic.autogenerater   r   alembic.autogenerate.renderr   r   r   r   r	   r
   alembic.ddl.baser   r   r   alembic.ddl.sqliter   alembic.operationsr   r   r   
sqlalchemyr   r   sqlalchemy.dialects.mysql.baser   sqlalchemy.dialects.sqlite.baser   sqlalchemy.ext.compilerr   sqlalchemy.schemar   sqlalchemy.sqlr   sqlalchemy.typesr   geoalchemy2r   r   r   !geoalchemy2.admin.dialects.commonr   r   r   RewriterwriterrH   r   r!   r]   rb   rl   rz   register_operationAddColumnOpr~   DropColumnOpr   implementation_forr{   r   r   r   dispatch_forr   r   rewritesr   r   CreateTableOpr   DropTableOpr   r   r   r   r   r   r   CreateIndexOpr   DropIndexOpr   r   r  r  r  r%  r'  r(   r)   r*   <module>rB     sU   6 6 * * * * * * ) ) ) ) ) ) 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 ( ( ( ( ( ( . . . . . . / / / / / / ) ) ) ) ) ) . . . . . . ) ) ) ) ) ) " " " " " "             7 7 7 7 7 7 9 9 9 9 9 9 , , , , , , ' ' ' ' ' '       * * * * * * ! ! ! ! ! !                   A A A A A A ; ; ; ; ; ; ? ? ? ? ? ?				 "#%%    Z   HA HA HAV % $ & & &'@ '@ '@T $ # % % %    . 677##$;=Z[[(% (% (% (% (%CO (% (% \[ 87(%V 788##$<>\]]% % % % %S- % % ^] 98%6 455#
 #
 65#
L 566] ] 76]$ 
+x  ; ; ! ;  
)X
8 
8 
8 -..I I /.I .//K K 0/K !!  "! !""
 
 #"
 899# # # # #c/ # # :9#L 677    CO   870 677( ( 87($ 455U U 65U" /00O O 10O -..K K /.K "##  $#( !!  "! 899##$=?^__)% )% )% )% )%c/ )% )% `_ :9)%X 677##$;=Z[[<% <% <% <% <%CO <% <% \[ 87<%~ 677* * 87*& 455U U 65U" /00M M 10M -..
 
 /.
 "##  $#: !!  "!  r)   