Alembic helpers

Some helpers to use with Alembic migration tool.

class geoalchemy2.alembic_helpers.AddGeospatialColumnOp(table_name: str, column: Column, schema: Optional[str] = None, **kw)[source]

Bases: alembic.operations.ops.AddColumnOp

Add a Geospatial Column in an Alembic migration context. This methodology originates from: https://alembic.sqlalchemy.org/en/latest/api/operations.html#operation-plugins

classmethod add_geospatial_column(operations, table_name, column, schema=None)[source]

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)[source]

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

reverse()[source]

Used to autogenerate the downgrade function.

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

Bases: alembic.operations.ops.CreateIndexOp

classmethod batch_create_geospatial_index(operations, index_name, columns, **kw)[source]

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)[source]

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

reverse()[source]

Used to autogenerate the downgrade function.

class geoalchemy2.alembic_helpers.CreateGeospatialTableOp(table_name: str, columns: Sequence[Union[Column, Constraint]], schema: Optional[str] = None, _namespace_metadata: Optional[MetaData] = None, _constraints_included: bool = False, **kw)[source]

Bases: alembic.operations.ops.CreateTableOp

Create a Geospatial Table in an Alembic migration context. This methodology originates from: https://alembic.sqlalchemy.org/en/latest/api/operations.html#operation-plugins

classmethod create_geospatial_table(operations, table_name, *columns, **kw)[source]

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

reverse()[source]

Used to autogenerate the downgrade function.

class geoalchemy2.alembic_helpers.DropGeospatialColumnOp(table_name: str, column_name: str, schema: Optional[str] = None, _reverse: Optional[AddColumnOp] = None, **kw)[source]

Bases: alembic.operations.ops.DropColumnOp

Drop a Geospatial Column in an Alembic migration context.

classmethod batch_drop_geospatial_column(operations, column_name, **kw)[source]

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)[source]

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

reverse()[source]

Used to autogenerate the downgrade function.

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

Bases: alembic.operations.ops.DropIndexOp

classmethod batch_drop_geospatial_index(operations, index_name, **kw)[source]

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)[source]

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

reverse()[source]

Used to autogenerate the downgrade function.

class geoalchemy2.alembic_helpers.DropGeospatialTableOp(table_name: str, schema: Optional[str] = None, table_kw: Optional[MutableMapping[Any, Any]] = None, _reverse: Optional[CreateTableOp] = None)[source]

Bases: alembic.operations.ops.DropTableOp

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

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

reverse()[source]

Used to autogenerate the downgrade function.

geoalchemy2.alembic_helpers.add_geo_column(context, revision, op)[source]

Replace the default AddColumnOp by a geospatial-specific one.

geoalchemy2.alembic_helpers.add_geospatial_column(operations, operation)[source]

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)[source]

Replace the default CreateIndexOp by a geospatial-specific one.

geoalchemy2.alembic_helpers.create_geo_table(context, revision, op)[source]

Replace the default CreateTableOp by a geospatial-specific one.

geoalchemy2.alembic_helpers.create_geospatial_index(operations, operation)[source]

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)[source]

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)[source]

Replace the default DropColumnOp by a geospatial-specific one.

geoalchemy2.alembic_helpers.drop_geo_index(context, revision, op)[source]

Replace the default DropIndexOp by a geospatial-specific one.

geoalchemy2.alembic_helpers.drop_geo_table(context, revision, op)[source]

Replace the default DropTableOp by a geospatial-specific one.

geoalchemy2.alembic_helpers.drop_geospatial_column(operations, operation)[source]

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)[source]

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)[source]

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.render_add_geo_column(autogen_context, op)[source]

Render the add_geospatial_column operation in migration script.

geoalchemy2.alembic_helpers.render_create_geo_index(autogen_context, op)[source]

Render the create_geospatial_index operation in migration script.

geoalchemy2.alembic_helpers.render_create_geo_table(autogen_context, op)[source]

Render the create_geospatial_table operation in migration script.

geoalchemy2.alembic_helpers.render_drop_geo_column(autogen_context, op)[source]

Render the drop_geospatial_column operation in migration script.

geoalchemy2.alembic_helpers.render_drop_geo_index(autogen_context, op)[source]

Render the drop_geospatial_index operation in migration script.

geoalchemy2.alembic_helpers.render_drop_geo_table(autogen_context, op)[source]

Render the drop_geospatial_table operation in migration script.

geoalchemy2.alembic_helpers.render_item(obj_type, obj, autogen_context)[source]

Add proper imports for spatial types.

geoalchemy2.alembic_helpers.visit_drop_geospatial_table(element, compiler, **kw)[source]

Specific compilation rule to drop spatial tables with SQLite dialect.

geoalchemy2.alembic_helpers.visit_rename_geospatial_table(element, compiler, **kw)[source]

Specific compilation rule to rename spatial tables with SQLite dialect.