From 41608a708d5fe8f9c0c0034dded61303b5513862 Mon Sep 17 00:00:00 2001 From: Monica Turner Date: Tue, 17 Sep 2024 11:07:38 +0200 Subject: [PATCH 1/5] HDXDSYS-843 add idp ref period pk --- src/hapi_schema/db_idps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hapi_schema/db_idps.py b/src/hapi_schema/db_idps.py index 1f1957a..73075bb 100644 --- a/src/hapi_schema/db_idps.py +++ b/src/hapi_schema/db_idps.py @@ -53,7 +53,7 @@ class DBIDPs(Base): ) reference_period_start: Mapped[datetime] = mapped_column( - DateTime, nullable=False, index=True + DateTime, primary_key=True ) reference_period_end: Mapped[datetime] = mapped_column( From ebadebde25b4beb8973cdff71870b37a9428dd7a Mon Sep 17 00:00:00 2001 From: Monica Turner Date: Tue, 17 Sep 2024 11:44:33 +0200 Subject: [PATCH 2/5] HDXDSYS-843 add op and round pk --- src/hapi_schema/db_idps.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/hapi_schema/db_idps.py b/src/hapi_schema/db_idps.py index 73075bb..88cced8 100644 --- a/src/hapi_schema/db_idps.py +++ b/src/hapi_schema/db_idps.py @@ -6,6 +6,7 @@ DateTime, ForeignKey, Integer, + String, select, ) from sqlalchemy.orm import Mapped, mapped_column, relationship @@ -46,7 +47,8 @@ class DBIDPs(Base): build_enum_using_values(DTMAssessmentType), primary_key=True ) - reporting_round: Mapped[int] = mapped_column(Integer, nullable=True) + reporting_round: Mapped[int] = mapped_column(Integer, primary_key=True) + operation: Mapped[str] = mapped_column(String, primary_key=True) population: Mapped[int] = mapped_column( Integer, nullable=False, index=True From 4b5ca7222091e53e9bf018203fec68c0ff3d1bf5 Mon Sep 17 00:00:00 2001 From: Monica Turner Date: Tue, 17 Sep 2024 15:19:50 +0200 Subject: [PATCH 3/5] HDXDSYS-843 fix tests --- tests/sample_data/data_idps.py | 1 + tests/test_idps.py | 1 + tests/test_views_as_tables.py | 2 ++ 3 files changed, 4 insertions(+) diff --git a/tests/sample_data/data_idps.py b/tests/sample_data/data_idps.py index 7004330..48a1fe3 100644 --- a/tests/sample_data/data_idps.py +++ b/tests/sample_data/data_idps.py @@ -6,6 +6,7 @@ admin2_ref=2, assessment_type="BA", reporting_round=18, + operation="Operation", population=25000, reference_period_start=datetime(2024, 1, 1), reference_period_end=datetime(2024, 12, 31), diff --git a/tests/test_idps.py b/tests/test_idps.py index 196c191..ec7174f 100644 --- a/tests/test_idps.py +++ b/tests/test_idps.py @@ -21,6 +21,7 @@ def test_idps_view(run_view_test): view_idps.c.admin2_ref == 2, view_idps.c.assessment_type == "BA", view_idps.c.reporting_round == 18, + view_idps.c.operation == "Operation", view_idps.c.population == 25000, view_idps.c.admin2_code == "FOO-001-XXX", view_idps.c.admin1_code == "FOO-001", diff --git a/tests/test_views_as_tables.py b/tests/test_views_as_tables.py index db97c95..1f1171f 100644 --- a/tests/test_views_as_tables.py +++ b/tests/test_views_as_tables.py @@ -225,6 +225,8 @@ def test_idps_vat(run_indexes_test, run_columns_test, run_primary_keys_test): expected_primary_keys = [ "admin2_ref", "assessment_type", + "reporting_round", + "operation", "reference_period_start", ] expected_indexes = [ From 7ec1c3e8f94fb53265e59671a942b7c5de394b0e Mon Sep 17 00:00:00 2001 From: Monica Turner Date: Tue, 17 Sep 2024 15:32:44 +0200 Subject: [PATCH 4/5] HDXDSYS-843 actually fix tests --- initialize_test_db.sh | 2 +- src/hapi_schema/db_views_as_tables.py | 3 ++- tests/conftest.py | 2 ++ tests/test_idps.py | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/initialize_test_db.sh b/initialize_test_db.sh index c3ac026..a0258a1 100644 --- a/initialize_test_db.sh +++ b/initialize_test_db.sh @@ -1,5 +1,5 @@ #!/bin/sh cd docker -docker-compose up -d +docker compose up -d cd .. diff --git a/src/hapi_schema/db_views_as_tables.py b/src/hapi_schema/db_views_as_tables.py index 09c4573..9a7803d 100644 --- a/src/hapi_schema/db_views_as_tables.py +++ b/src/hapi_schema/db_views_as_tables.py @@ -275,7 +275,8 @@ class DBIDPsVAT(Base): resource_hdx_id: Mapped[str] = mapped_column(String(36)) admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True) assessment_type: Mapped[str] = mapped_column(String(32), primary_key=True) - reporting_round: Mapped[int] = mapped_column(Integer, nullable=True) + reporting_round: Mapped[int] = mapped_column(Integer, primary_key=True) + operation: Mapped[str] = mapped_column(String, primary_key=True) population: Mapped[int] = mapped_column(Integer, index=True) reference_period_start: Mapped[datetime] = mapped_column( DateTime, primary_key=True diff --git a/tests/conftest.py b/tests/conftest.py index 9fd272e..d0f338e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -173,6 +173,8 @@ def _run_primary_keys_test(target_table: str, expected_primary_keys: str): if column.primary_key: found_primary_keys.append(column.name) + print(expected_primary_keys) + print(found_primary_keys) assert set(expected_primary_keys) == set(found_primary_keys) return _run_primary_keys_test diff --git a/tests/test_idps.py b/tests/test_idps.py index ec7174f..f8fb03c 100644 --- a/tests/test_idps.py +++ b/tests/test_idps.py @@ -52,6 +52,7 @@ def base_parameters(): admin2_ref=2, assessment_type="BA", reporting_round=18, + operation="operation", population=25000, reference_period_start=datetime(2020, 1, 1), reference_period_end=datetime(2020, 1, 2), From 4b0081ce3138dedbb6c1f00897701afe9c9daeb0 Mon Sep 17 00:00:00 2001 From: Monica Turner Date: Thu, 19 Sep 2024 13:49:55 +0200 Subject: [PATCH 5/5] HDXDSYS-843 update changelog --- changelog.md | 6 ++++++ initialize_test_db.sh | 2 +- tests/conftest.py | 2 -- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index dd50ae1..1903371 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.8.17 + +### Added + +- `operation` and additional primary keys to `idps` table + ## 0.8.16 ### Added diff --git a/initialize_test_db.sh b/initialize_test_db.sh index a0258a1..c3ac026 100644 --- a/initialize_test_db.sh +++ b/initialize_test_db.sh @@ -1,5 +1,5 @@ #!/bin/sh cd docker -docker compose up -d +docker-compose up -d cd .. diff --git a/tests/conftest.py b/tests/conftest.py index d0f338e..9fd272e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -173,8 +173,6 @@ def _run_primary_keys_test(target_table: str, expected_primary_keys: str): if column.primary_key: found_primary_keys.append(column.name) - print(expected_primary_keys) - print(found_primary_keys) assert set(expected_primary_keys) == set(found_primary_keys) return _run_primary_keys_test