diff --git a/app/models/orm/migrations/versions/ef3392e8e054_.py b/app/models/orm/migrations/versions/ef3392e8e054_.py new file mode 100644 index 000000000..05360d4fe --- /dev/null +++ b/app/models/orm/migrations/versions/ef3392e8e054_.py @@ -0,0 +1,35 @@ +"""update resolution metadata fields + +Revision ID: ef3392e8e054 +Revises: d767b6dd2c4c +Create Date: 2024-09-10 14:19:43.424752 + +""" +from alembic import op +import sqlalchemy as sa +import sqlalchemy_utils +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = 'ef3392e8e054' +down_revision = 'd767b6dd2c4c' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column('dataset_metadata', 'resolution', nullable=True, new_column_name='spatial_resolution') + op.add_column('dataset_metadata', sa.Column('resolution_description', sa.String(), nullable=True)) + op.alter_column('version_metadata', 'resolution', nullable=True, new_column_name='spatial_resolution') + op.add_column('version_metadata', sa.Column('resolution_description', sa.String(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column('dataset_metadata', 'spatial_resolution', nullable=True, new_column_name='resolution') + op.drop_column('version_metadata', 'resolution_description') + op.alter_column('version_metadata', 'spatial_resolution', nullable=True, new_column_name='resolution') + op.drop_column('dataset_metadata', 'resolution_description') + # ### end Alembic commands ### diff --git a/app/models/orm/mixins.py b/app/models/orm/mixins.py index 7577a77ac..c1cf744db 100644 --- a/app/models/orm/mixins.py +++ b/app/models/orm/mixins.py @@ -3,7 +3,8 @@ class MetadataMixin: title = db.Column(db.String) - resolution = db.Column(db.Numeric) + spatial_resolution = db.Column(db.Numeric) + resolution_description = db.Column(db.String) geographic_coverage = db.Column(db.String) update_frequency = db.Column(db.String) citation = db.Column(db.String) diff --git a/app/models/pydantic/metadata.py b/app/models/pydantic/metadata.py index f17d44b6d..01f5a7308 100644 --- a/app/models/pydantic/metadata.py +++ b/app/models/pydantic/metadata.py @@ -11,7 +11,8 @@ class CommonMetadata(BaseModel): - resolution: Optional[Union[int, float]] + spatial_resolution: Optional[Union[int, float]] + resolution_description: Optional[str] geographic_coverage: Optional[str] update_frequency: Optional[str] scale: Optional[str] @@ -21,7 +22,8 @@ class Config: schema_extra = { "examples": [ { - "resolution": 10, + "spatial_resolution": 10, + "resolution_description": "10 meters", "geographic_coverage": "Amazon Basin", "update_frequency": "Updated daily, image revisit time every 5 days", "scale": "regional", diff --git a/tests/crud/test_versions.py b/tests/crud/test_versions.py index 673c1f8ad..4dbf28d86 100644 --- a/tests/crud/test_versions.py +++ b/tests/crud/test_versions.py @@ -115,7 +115,7 @@ async def test_versions(app): metadata=metadata.dict(by_alias=True), change_log=[logs.dict(by_alias=True)], ) - assert row.metadata.resolution == version_metadata["resolution"] + assert row.metadata.spatial_resolution == version_metadata["spatial_resolution"] assert row.change_log[0]["date_time"] == json.loads(logs.json())["date_time"] assert row.change_log[0]["status"] == logs.dict(by_alias=True)["status"] assert row.change_log[0]["message"] == logs.dict(by_alias=True)["message"] diff --git a/tests/routes/datasets/test_versions.py b/tests/routes/datasets/test_versions.py index 2fbd1b3d9..0c3b084f9 100755 --- a/tests/routes/datasets/test_versions.py +++ b/tests/routes/datasets/test_versions.py @@ -56,8 +56,11 @@ async def test_versions(async_client: AsyncClient): assert version_data["data"]["dataset"] == dataset assert version_data["data"]["version"] == version assert ( - version_data["data"]["metadata"]["resolution"] == version_metadata["resolution"] + version_data["data"]["metadata"]["spatial_resolution"] == version_metadata["spatial_resolution"] ) + assert ( + version_data["data"]["metadata"]["resolution_description"] == version_metadata["resolution_description"] + ) assert ( version_data["data"]["metadata"]["content_date_range"]["start_date"] == version_metadata["content_date_range"]["start_date"] @@ -180,8 +183,8 @@ async def test_version_metadata(async_client: AsyncClient): assert response.status_code == 201 assert ( - response.json()["data"]["metadata"]["resolution"] - == version_metadata["resolution"] + response.json()["data"]["metadata"]["spatial_resolution"] + == version_metadata["spatial_resolution"] ) assert ( response.json()["data"]["metadata"]["content_date_range"] diff --git a/tests/utils.py b/tests/utils.py index c3dba73e6..a9a4075a0 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -32,7 +32,8 @@ version_metadata = { "content_date_range": {"start_date": "2000-01-01", "end_date": "2021-01-01"}, "last_update": "2020-01-03", - "resolution": 10, + "spatial_resolution": 10, + "resolution_description": "10 meters", } asset_metadata = { diff --git a/tests_v2/fixtures/metadata/version.py b/tests_v2/fixtures/metadata/version.py index c05f4e274..63a81369c 100644 --- a/tests_v2/fixtures/metadata/version.py +++ b/tests_v2/fixtures/metadata/version.py @@ -1,5 +1,6 @@ VERSION_METADATA = { "content_date_range": {"start_date": "2000-01-01", "end_date": "2021-01-01"}, "last_update": "2020-01-03", - "resolution": 10, + "spatial_resolution": 10, + "resolution_description": "10 meters", }