From 69d7f64ead9b45eeaaebbbc59f455345c0374ab1 Mon Sep 17 00:00:00 2001 From: Paul Bienkowski Date: Sun, 26 Mar 2023 13:01:30 +0200 Subject: [PATCH] Add import_group columns for OSM data tables --- .../b8b0fbae50a4_add_import_groups.py | 39 +++++++++++++++++++ api/obs/api/db.py | 2 + 2 files changed, 41 insertions(+) create mode 100644 api/migrations/versions/b8b0fbae50a4_add_import_groups.py diff --git a/api/migrations/versions/b8b0fbae50a4_add_import_groups.py b/api/migrations/versions/b8b0fbae50a4_add_import_groups.py new file mode 100644 index 0000000..044eeda --- /dev/null +++ b/api/migrations/versions/b8b0fbae50a4_add_import_groups.py @@ -0,0 +1,39 @@ +"""add import groups + +Revision ID: b8b0fbae50a4 +Revises: 5c7755ead95d +Create Date: 2023-03-26 09:41:36.621203 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "b8b0fbae50a4" +down_revision = "5c7755ead95d" +branch_labels = None +depends_on = None + + +def upgrade(): + op.add_column( + "road", + sa.Column("import_group", sa.String(), nullable=True), + ) + op.add_column( + "region", + sa.Column("import_group", sa.String(), nullable=True), + ) + + # Set existing to "osm2pgsql" + road = sa.table("road", sa.column("import_group", sa.String)) + op.execute(road.update().values(import_group="osm2pgsql")) + + region = sa.table("region", sa.column("import_group", sa.String)) + op.execute(region.update().values(import_group="osm2pgsql")) + + +def downgrade(): + op.drop_column("road", "import_group") + op.drop_column("region", "import_group") diff --git a/api/obs/api/db.py b/api/obs/api/db.py index 6025300..43d0706 100644 --- a/api/obs/api/db.py +++ b/api/obs/api/db.py @@ -140,6 +140,7 @@ class Road(Base): geometry = Column(Geometry) directionality = Column(Integer) oneway = Column(Boolean) + import_group = Column(String) def to_dict(self): return { @@ -475,6 +476,7 @@ class Region(Base): name = Column(String) geometry = Column(Geometry) admin_level = Column(Integer) + import_group = Column(String) Comment.author = relationship("User", back_populates="authored_comments")