From 0f1d9d43e2b36281b5975e69e90083898c8a1b90 Mon Sep 17 00:00:00 2001 From: manukala6 Date: Fri, 6 Sep 2024 17:04:47 -0400 Subject: [PATCH 1/3] GTC-2898 Modify metadata fields --- .../orm/migrations/versions/e8a7dc28a874_.py | 39 +++++++++++++++++++ app/models/orm/mixins.py | 3 +- app/models/pydantic/metadata.py | 6 ++- tests/crud/test_versions.py | 2 +- tests/routes/datasets/test_versions.py | 9 +++-- tests/utils.py | 3 +- tests_v2/fixtures/metadata/version.py | 3 +- 7 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 app/models/orm/migrations/versions/e8a7dc28a874_.py diff --git a/app/models/orm/migrations/versions/e8a7dc28a874_.py b/app/models/orm/migrations/versions/e8a7dc28a874_.py new file mode 100644 index 000000000..8bcccbf2c --- /dev/null +++ b/app/models/orm/migrations/versions/e8a7dc28a874_.py @@ -0,0 +1,39 @@ +"""empty message + +Revision ID: e8a7dc28a874 +Revises: d767b6dd2c4c +Create Date: 2024-09-06 20:37:11.512231 + +""" +from alembic import op +import sqlalchemy as sa +import sqlalchemy_utils +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = 'e8a7dc28a874' +down_revision = 'd767b6dd2c4c' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('dataset_metadata', sa.Column('spatial_resolution', sa.Numeric(), nullable=True)) + op.add_column('dataset_metadata', sa.Column('resolution_description', sa.String(), nullable=True)) + op.drop_column('dataset_metadata', 'resolution') + op.add_column('version_metadata', sa.Column('spatial_resolution', sa.Numeric(), nullable=True)) + op.add_column('version_metadata', sa.Column('resolution_description', sa.String(), nullable=True)) + op.drop_column('version_metadata', 'resolution') + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('version_metadata', sa.Column('resolution', sa.NUMERIC(), autoincrement=False, nullable=True)) + op.drop_column('version_metadata', 'resolution_description') + op.drop_column('version_metadata', 'spatial_resolution') + op.add_column('dataset_metadata', sa.Column('resolution', sa.NUMERIC(), autoincrement=False, nullable=True)) + op.drop_column('dataset_metadata', 'resolution_description') + op.drop_column('dataset_metadata', 'spatial_resolution') + # ### 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", } From 786ab414dece874c2c8f82056906edfef275074d Mon Sep 17 00:00:00 2001 From: manukala6 Date: Tue, 10 Sep 2024 10:00:31 -0400 Subject: [PATCH 2/3] GTC-2898 Correct migration script --- .../{e8a7dc28a874_.py => ab98e958dc3b_.py} | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) rename app/models/orm/migrations/versions/{e8a7dc28a874_.py => ab98e958dc3b_.py} (52%) diff --git a/app/models/orm/migrations/versions/e8a7dc28a874_.py b/app/models/orm/migrations/versions/ab98e958dc3b_.py similarity index 52% rename from app/models/orm/migrations/versions/e8a7dc28a874_.py rename to app/models/orm/migrations/versions/ab98e958dc3b_.py index 8bcccbf2c..5ceca4ec2 100644 --- a/app/models/orm/migrations/versions/e8a7dc28a874_.py +++ b/app/models/orm/migrations/versions/ab98e958dc3b_.py @@ -1,8 +1,8 @@ -"""empty message +"""update resolution metadata fields -Revision ID: e8a7dc28a874 +Revision ID: ab98e958dc3b Revises: d767b6dd2c4c -Create Date: 2024-09-06 20:37:11.512231 +Create Date: 2024-09-10 13:49:58.066058 """ from alembic import op @@ -11,7 +11,7 @@ from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. -revision = 'e8a7dc28a874' +revision = 'ab98e958dc3b' down_revision = 'd767b6dd2c4c' branch_labels = None depends_on = None @@ -19,21 +19,17 @@ def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('dataset_metadata', sa.Column('spatial_resolution', sa.Numeric(), nullable=True)) + op.alter_column('dataset_metadata', 'resolution', nullable=False, new_column_name='spatial_resolution') op.add_column('dataset_metadata', sa.Column('resolution_description', sa.String(), nullable=True)) - op.drop_column('dataset_metadata', 'resolution') - op.add_column('version_metadata', sa.Column('spatial_resolution', sa.Numeric(), nullable=True)) + op.alter_column('version_metadata', 'resolution', nullable=False, new_column_name='spatial_resolution') op.add_column('version_metadata', sa.Column('resolution_description', sa.String(), nullable=True)) - op.drop_column('version_metadata', 'resolution') # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('version_metadata', sa.Column('resolution', sa.NUMERIC(), autoincrement=False, nullable=True)) + op.alter_column('dataset_metadata', 'spatial_resolution', nullable=False, new_column_name='resolution') op.drop_column('version_metadata', 'resolution_description') - op.drop_column('version_metadata', 'spatial_resolution') - op.add_column('dataset_metadata', sa.Column('resolution', sa.NUMERIC(), autoincrement=False, nullable=True)) + op.alter_column('version_metadata', 'spatial_resolution', nullable=False, new_column_name='resolution') op.drop_column('dataset_metadata', 'resolution_description') - op.drop_column('dataset_metadata', 'spatial_resolution') # ### end Alembic commands ### From ba03419cec6150171e43a2d7a99a266fc12c1a47 Mon Sep 17 00:00:00 2001 From: manukala6 Date: Tue, 10 Sep 2024 10:46:45 -0400 Subject: [PATCH 3/3] GTC-2898 Allow nullable resolution fields --- .../{ab98e958dc3b_.py => ef3392e8e054_.py} | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) rename app/models/orm/migrations/versions/{ab98e958dc3b_.py => ef3392e8e054_.py} (71%) diff --git a/app/models/orm/migrations/versions/ab98e958dc3b_.py b/app/models/orm/migrations/versions/ef3392e8e054_.py similarity index 71% rename from app/models/orm/migrations/versions/ab98e958dc3b_.py rename to app/models/orm/migrations/versions/ef3392e8e054_.py index 5ceca4ec2..05360d4fe 100644 --- a/app/models/orm/migrations/versions/ab98e958dc3b_.py +++ b/app/models/orm/migrations/versions/ef3392e8e054_.py @@ -1,8 +1,8 @@ """update resolution metadata fields -Revision ID: ab98e958dc3b +Revision ID: ef3392e8e054 Revises: d767b6dd2c4c -Create Date: 2024-09-10 13:49:58.066058 +Create Date: 2024-09-10 14:19:43.424752 """ from alembic import op @@ -11,7 +11,7 @@ from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. -revision = 'ab98e958dc3b' +revision = 'ef3392e8e054' down_revision = 'd767b6dd2c4c' branch_labels = None depends_on = None @@ -19,17 +19,17 @@ def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.alter_column('dataset_metadata', 'resolution', nullable=False, new_column_name='spatial_resolution') + 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=False, new_column_name='spatial_resolution') + 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=False, new_column_name='resolution') + 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=False, new_column_name='resolution') + op.alter_column('version_metadata', 'spatial_resolution', nullable=True, new_column_name='resolution') op.drop_column('dataset_metadata', 'resolution_description') # ### end Alembic commands ###