Skip to content

Commit

Permalink
Fix create_geo_table() in alembic helpers to handle foreign keys (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-berchet authored Aug 10, 2022
1 parent 9d89df1 commit d6297d4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
8 changes: 7 additions & 1 deletion geoalchemy2/alembic_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,13 @@ def create_geo_table(context, revision, op):
)

if gis_cols:
new_op = CreateGeospatialTableOp(op.table_name, op.columns, op.schema)
new_op = CreateGeospatialTableOp(
op.table_name,
op.columns,
op.schema,
op._namespace_metadata,
op._constraints_included,
)
else:
new_op = op

Expand Down
29 changes: 25 additions & 4 deletions tests/test_alembic_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,28 @@ def test_migration_revision(
with test_script_path.open(mode="w", encoding="utf8") as f:
f.write(
"""
from sqlalchemy import MetaData
from geoalchemy2 import Geometry
from sqlalchemy import Column
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import String
from sqlalchemy import Table
from geoalchemy2 import Geometry
metadata = MetaData()
group_table = Table(
"new_groups",
metadata,
Column("id", Integer, primary_key=True, autoincrement=True),
Column("name", String),
)
new_table = Table(
"new_spatial_table",
metadata,
Column("id", Integer, primary_key=True),
Column("group_id", Integer, ForeignKey(group_table.c.id)),
Column(
"geom_with_idx",
Geometry(
Expand Down Expand Up @@ -371,18 +381,29 @@ def test_migration_revision(
with test_script_path.open(mode="w", encoding="utf8") as f:
f.write(
"""
from sqlalchemy import MetaData
from geoalchemy2 import Geometry
from sqlalchemy import Column
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import String
from sqlalchemy import Table
from geoalchemy2 import Geometry
metadata = MetaData()
group_table = Table(
"new_groups",
metadata,
Column("id", Integer, primary_key=True, autoincrement=True),
Column("name", String),
)
new_table = Table(
"new_spatial_table",
metadata,
Column("id", Integer, primary_key=True),
Column("group_id", Integer, ForeignKey(group_table.c.id)),
Column(
"geom_with_idx",
Geometry(
Expand Down

0 comments on commit d6297d4

Please sign in to comment.