Skip to content

Commit

Permalink
Add JSON info field to geostore records
Browse files Browse the repository at this point in the history
  • Loading branch information
dmannarino committed Feb 11, 2025
1 parent 3c58c8f commit 6c443f3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
7 changes: 2 additions & 5 deletions app/crud/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
from ..models.orm.versions import Version as ORMVersion
from ..utils.generators import list_to_async_generator
from . import datasets, update_data
from .metadata import (
create_version_metadata,
update_version_metadata,
)
from .metadata import create_version_metadata, update_version_metadata


async def get_versions(dataset: str) -> List[ORMVersion]:
Expand Down Expand Up @@ -114,7 +111,7 @@ async def create_version(dataset: str, version: str, **data) -> ORMVersion:
async def update_version(dataset: str, version: str, **data) -> ORMVersion:
"""Update fields of version."""
row: ORMVersion = await get_version(dataset, version)
metadata_data = data.pop("metadata", None)
metadata_data = data.pop("metadata", None) # FIXME: Shouldn't we default to {}?
row = await update_data(row, data)

if metadata_data:
Expand Down
2 changes: 2 additions & 0 deletions app/models/orm/geostore.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Geostore(Base):
gfw_area__ha = db.Column(db.Numeric)
gfw_bbox = db.Column(db.ARRAY(db.Numeric))

info = db.Column(db.JSON)

_geostore_gfw_geostore_id_idx = db.Index(
"geostore_gfw_geostore_id_idx", "gfw_geostore_id", postgresql_using="hash"
)
27 changes: 27 additions & 0 deletions app/models/orm/migrations/versions/1082340f8ce1_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Empty message.
Revision ID: 1082340f8ce1
Revises: 3e524ef0525f
Create Date: 2025-02-11 15:38:36.460512
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "1082340f8ce1" # pragma: allowlist secret
down_revision = "3e524ef0525f" # pragma: allowlist secret
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("geostore", sa.Column("info", sa.JSON(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("geostore", "info")
# ### end Alembic commands ###
15 changes: 15 additions & 0 deletions app/models/pydantic/geostore.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,27 @@ class FeatureCollection(StrictBaseModel):
type: str


class GeostoreInfo(StrictBaseModel):
country: str # iso
name: str # name of the most specific region
region: str # gid1
subregion: str # gid2
gadm: str # GADM version, for backwards compat
adminProvider: str # e.g. "gadm"
adminVersion: str # e.g. "4.1"
simplify: bool
simplifyThresh: Optional[float]
use: Dict[str, str]


class Geostore(BaseRecord):
gfw_geostore_id: UUID
gfw_geojson: Geometry
gfw_area__ha: float
gfw_bbox: List[float]

info: Optional[GeostoreInfo]

@validator("gfw_geojson", pre=True)
def convert_to_dict(cls, v):
if isinstance(v, str):
Expand Down

0 comments on commit 6c443f3

Please sign in to comment.