Skip to content

Commit c1010b2

Browse files
committed
feat: Store portal title and URL
OpenDataServices/oc4ids-registry#20
1 parent 1a2372e commit c1010b2

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""add_portals
2+
3+
Revision ID: cde761a59c2f
4+
Revises: b21b5de6ee2d
5+
Create Date: 2025-07-08 07:51:48.954914
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = 'cde761a59c2f'
16+
down_revision: Union[str, None] = 'b21b5de6ee2d'
17+
branch_labels: Union[str, Sequence[str], None] = None
18+
depends_on: Union[str, Sequence[str], None] = None
19+
20+
21+
def upgrade() -> None:
22+
# ### commands auto generated by Alembic - please adjust! ###
23+
op.add_column('dataset', sa.Column('portal_url', sa.String(), nullable=True))
24+
op.add_column('dataset', sa.Column('portal_title', sa.String(), nullable=True))
25+
# ### end Alembic commands ###
26+
27+
28+
def downgrade() -> None:
29+
# ### commands auto generated by Alembic - please adjust! ###
30+
op.drop_column('dataset', 'portal_title')
31+
op.drop_column('dataset', 'portal_url')
32+
# ### end Alembic commands ###

oc4ids_datastore_pipeline/database.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class Dataset(Base):
3636
csv_url: Mapped[Optional[str]] = mapped_column(String, nullable=True)
3737
xlsx_url: Mapped[Optional[str]] = mapped_column(String, nullable=True)
3838
updated_at: Mapped[datetime.datetime] = mapped_column(DateTime(timezone=True))
39+
portal_url: Mapped[Optional[str]] = mapped_column(String, nullable=True)
40+
portal_title: Mapped[Optional[str]] = mapped_column(String, nullable=True)
3941

4042

4143
def get_engine() -> Engine:

oc4ids_datastore_pipeline/pipeline.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def save_dataset_metadata(
111111
json_url: Optional[str],
112112
csv_url: Optional[str],
113113
xlsx_url: Optional[str],
114+
portal_title: Optional[str],
115+
portal_url: Optional[str],
114116
) -> None:
115117
logger.info(f"Saving metadata for dataset {dataset_id}")
116118
try:
@@ -127,6 +129,8 @@ def save_dataset_metadata(
127129
license_url=license_url,
128130
license_title=license_title,
129131
license_title_short=license_title_short,
132+
portal_title=portal_title,
133+
portal_url=portal_url,
130134
json_url=json_url,
131135
csv_url=csv_url,
132136
xlsx_url=xlsx_url,
@@ -157,6 +161,8 @@ def process_dataset(dataset_id: str, registry_metadata: dict[str, str]) -> None:
157161
json_url=json_public_url,
158162
csv_url=csv_public_url,
159163
xlsx_url=xlsx_public_url,
164+
portal_title=registry_metadata["portal_title"],
165+
portal_url=registry_metadata["portal_url"],
160166
)
161167
logger.info(f"Processed dataset {dataset_id}")
162168

oc4ids_datastore_pipeline/registry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def fetch_registered_datasets() -> dict[str, dict[str, str]]:
2424
registered_datasets[key] = {
2525
"source_url": r_data_json["fields"]["url"]["value"],
2626
"country": r_data_json["fields"]["country"]["value"],
27+
"portal_title": r_data_json["fields"]["portal_title"]["value"],
28+
"portal_url": r_data_json["fields"]["portal_url"]["value"],
2729
}
2830
registered_datasets_count = len(registered_datasets)
2931
logger.info(f"Fetched URLs for {registered_datasets_count} datasets")

tests/test_registry.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def test_fetch_registered_datasets(mocker: MockerFixture) -> None:
2828
"fields": {
2929
"url": {"value": "https://test_dataset.json"},
3030
"country": {"value": "ab"},
31+
"portal_title": {"value": "Our Portal"},
32+
"portal_url": {"value": "https://our.portal"},
3133
}
3234
},
3335
]
@@ -37,7 +39,12 @@ def test_fetch_registered_datasets(mocker: MockerFixture) -> None:
3739
result = fetch_registered_datasets()
3840

3941
assert result == {
40-
"test_dataset": {"source_url": "https://test_dataset.json", "country": "ab"}
42+
"test_dataset": {
43+
"source_url": "https://test_dataset.json",
44+
"country": "ab",
45+
"portal_title": "Our Portal",
46+
"portal_url": "https://our.portal",
47+
}
4148
}
4249

4350

0 commit comments

Comments
 (0)