# Alembic helpers

Some helpers to use with Alembic migration tool.

class geoalchemy2.alembic_helpers.AddGeospatialColumnOp(table_name: str, column: Column[Any], *, schema: str | None = None, if_not_exists: bool | None = None, **kw: Any)

  Bases: `AddColumnOp`

  Add a Geospatial Column in an Alembic migration context.

  This method originates from: https://alembic.sqlalchemy.org/en/latest/api/operations.html#operation-plugins

  classmethod add_geospatial_column(operations, table_name, column, schema=None)

    This method is proxied on the `Operations` class, via the `Operations.add_geospatial_column()` method.

  classmethod batch_add_geospatial_column(operations, column, insert_before=None, insert_after=None)

    This method is proxied on the `BatchOperations` class, via the `BatchOperations.add_geospatial_column()` method.

  reverse()

    Used to autogenerate the downgrade function.

class geoalchemy2.alembic_helpers.CreateGeospatialIndexOp(index_name: str | None, table_name: str, columns: Sequence[str | TextClause | ColumnElement[Any]], *, schema: str | None = None, unique: bool = False, if_not_exists: bool | None = None, **kw: Any)

  Bases: `CreateIndexOp`

  classmethod batch_create_geospatial_index(operations, index_name, columns, **kw)

    This method is proxied on the `BatchOperations` class, via the `BatchOperations.create_geospatial_index()` method.

  classmethod create_geospatial_index(operations, index_name, table_name, columns, schema=None, unique=False, **kw)

    This method is proxied on the `Operations` class, via the `Operations.create_geospatial_index()` method.

  reverse()

    Used to autogenerate the downgrade function.

class geoalchemy2.alembic_helpers.CreateGeospatialTableOp(table_name: str, columns: Sequence[SchemaItem], *, schema: str | None = None, if_not_exists: bool | None = None, _namespace_metadata: MetaData | None = None, _constraints_included: bool = False, **kw: Any)

  Bases: `CreateTableOp`

  Create a Geospatial Table in an Alembic migration context.

  This method originates from: https://alembic.sqlalchemy.org/en/latest/api/operations.html#operation-plugins

  classmethod create_geospatial_table(operations, table_name, *columns, **kw)

    This method is proxied on the `Operations` class, via the `Operations.create_geospatial_table()` method.

  reverse()

    Used to autogenerate the downgrade function.

class geoalchemy2.alembic_helpers.DropGeospatialColumnOp(table_name: str, column_name: str, *, schema: str | None = None, if_exists: bool | None = None, _reverse: AddColumnOp | None = None, **kw: Any)

  Bases: `DropColumnOp`

  Drop a Geospatial Column in an Alembic migration context.

  classmethod batch_drop_geospatial_column(operations, column_name, **kw)

    This method is proxied on the `BatchOperations` class, via the `BatchOperations.drop_geospatial_column()` method.

  classmethod drop_geospatial_column(operations, table_name, column_name, schema=None, **kw)

    This method is proxied on the `Operations` class, via the `Operations.drop_geospatial_column()` method.

  reverse()

    Used to autogenerate the downgrade function.

class geoalchemy2.alembic_helpers.DropGeospatialIndexOp(*args, column_name, **kwargs)

  Bases: `DropIndexOp`

  classmethod batch_drop_geospatial_index(operations, index_name, **kw)

    This method is proxied on the `BatchOperations` class, via the `BatchOperations.drop_geospatial_index()` method.

  classmethod drop_geospatial_index(operations, index_name, table_name, column_name, schema=None, unique=False, **kw)

    This method is proxied on the `Operations` class, via the `Operations.drop_geospatial_index()` method.

  reverse()

    Used to autogenerate the downgrade function.

class geoalchemy2.alembic_helpers.DropGeospatialTableOp(table_name: str, *, schema: str | None = None, if_exists: bool | None = None, table_kw: MutableMapping[Any, Any] | None = None, _reverse: CreateTableOp | None = None)

  Bases: `DropTableOp`

  classmethod drop_geospatial_table(operations, table_name, schema=None, **kw)

    This method is proxied on the `Operations` class, via the `Operations.drop_geospatial_table()` method.

  reverse()

    Used to autogenerate the downgrade function.

class geoalchemy2.alembic_helpers.GeoPackageImpl(dialect: Dialect, connection: Connection | None, as_sql: bool, transactional_ddl: bool | None, output_buffer: TextIO | None, context_opts: Dict[str, Any])

  Bases: `SQLiteImpl`

  Class to copy the Alembic implementation from SQLite to GeoPackage.

geoalchemy2.alembic_helpers.add_geo_column(context, revision, op)

  Replace the default AddColumnOp by a geospatial-specific one.

geoalchemy2.alembic_helpers.add_geospatial_column(operations, operation)

  Handle the actual column addition according to the dialect backend.

  Parameters:

    - 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.

geoalchemy2.alembic_helpers.create_geo_index(context, revision, op)

  Replace the default CreateIndexOp by a geospatial-specific one.

geoalchemy2.alembic_helpers.create_geo_table(context, revision, op)

  Replace the default CreateTableOp by a geospatial-specific one.

geoalchemy2.alembic_helpers.create_geospatial_index(operations, operation)

  Handle the actual index creation according to the dialect backend.

  Parameters:

    - 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.

geoalchemy2.alembic_helpers.create_geospatial_table(operations, operation)

  Handle the actual table creation according to the dialect backend.

  Parameters:

    - 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.

geoalchemy2.alembic_helpers.drop_geo_column(context, revision, op)

  Replace the default DropColumnOp by a geospatial-specific one.

geoalchemy2.alembic_helpers.drop_geo_index(context, revision, op)

  Replace the default DropIndexOp by a geospatial-specific one.

geoalchemy2.alembic_helpers.drop_geo_table(context, revision, op)

  Replace the default DropTableOp by a geospatial-specific one.

geoalchemy2.alembic_helpers.drop_geospatial_column(operations, operation)

  Handle the actual column removal according to the dialect backend.

  Parameters:

    - 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.

geoalchemy2.alembic_helpers.drop_geospatial_index(operations, operation)

  Handle the actual index drop according to the dialect backend.

  Parameters:

    - 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.

geoalchemy2.alembic_helpers.drop_geospatial_table(operations, operation)

  Handle the actual table removal according to the dialect backend.

  Parameters:

    - 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.

geoalchemy2.alembic_helpers.include_object(obj, name, obj_type, reflected, compare_to)

  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.

geoalchemy2.alembic_helpers.render_add_geo_column(autogen_context, op)

  Render the add_geospatial_column operation in migration script.

geoalchemy2.alembic_helpers.render_create_geo_index(autogen_context, op)

  Render the create_geospatial_index operation in migration script.

geoalchemy2.alembic_helpers.render_create_geo_table(autogen_context, op)

  Render the create_geospatial_table operation in migration script.

geoalchemy2.alembic_helpers.render_drop_geo_column(autogen_context, op)

  Render the drop_geospatial_column operation in migration script.

geoalchemy2.alembic_helpers.render_drop_geo_index(autogen_context, op)

  Render the drop_geospatial_index operation in migration script.

geoalchemy2.alembic_helpers.render_drop_geo_table(autogen_context, op)

  Render the drop_geospatial_table operation in migration script.

geoalchemy2.alembic_helpers.render_item(obj_type, obj, autogen_context)

  Add proper imports for spatial types.

geoalchemy2.alembic_helpers.visit_drop_geospatial_table(element, compiler, **kw)

  Specific compilation rule to drop spatial tables with SQLite dialect.

geoalchemy2.alembic_helpers.visit_rename_geospatial_table(element, compiler, **kw)

  Specific compilation rule to rename spatial tables with SQLite dialect.

geoalchemy2.alembic_helpers.writer = <alembic.autogenerate.rewriter.Rewriter object>

  Rewriter object for Alembic.