Skip to content

Commit

Permalink
Merge pull request #13 from OCHA-DAP/sector_higher
Browse files Browse the repository at this point in the history
Move sector up as logically it precedes other attributes
  • Loading branch information
mcarans authored Dec 22, 2023
2 parents e332bed + f4eefbb commit b178a87
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/hapi_schema/db_humanitarian_needs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class DBHumanitarianNeeds(Base):
admin2_ref: Mapped[int] = mapped_column(
ForeignKey("admin2.id", onupdate="CASCADE"), nullable=False
)
sector_code: Mapped[str] = mapped_column(
ForeignKey("sector.code", onupdate="CASCADE"), nullable=True
)
gender_code: Mapped[str] = mapped_column(
ForeignKey("gender.code", onupdate="CASCADE"), nullable=True
)
Expand All @@ -42,9 +45,6 @@ class DBHumanitarianNeeds(Base):
disabled_marker: Mapped[bool] = mapped_column(
Boolean, nullable=True, server_default=text("NULL")
)
sector_code: Mapped[str] = mapped_column(
ForeignKey("sector.code", onupdate="CASCADE"), nullable=True
)
population_group_code: Mapped[str] = mapped_column(
ForeignKey("population_group.code", onupdate="CASCADE"), nullable=True
)
Expand All @@ -65,9 +65,9 @@ class DBHumanitarianNeeds(Base):

resource = relationship("DBResource")
admin2 = relationship("DBAdmin2")
sector = relationship("DBSector")
gender = relationship("DBGender")
age_range = relationship("DBAgeRange")
sector = relationship("DBSector")
population_group = relationship("DBPopulationGroup")
population_status = relationship("DBPopulationStatus")

Expand Down
24 changes: 12 additions & 12 deletions src/hapi_schema/db_operational_presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ class DBOperationalPresence(Base):
admin2_ref: Mapped[int] = mapped_column(
ForeignKey("admin2.id", onupdate="CASCADE"), nullable=False
)
org_ref: Mapped[str] = mapped_column(
ForeignKey("org.id", onupdate="CASCADE"), nullable=False
)
sector_code: Mapped[str] = mapped_column(
ForeignKey("sector.code", onupdate="CASCADE"), nullable=False
)
org_ref: Mapped[str] = mapped_column(
ForeignKey("org.id", onupdate="CASCADE"), nullable=False
)
reference_period_start: Mapped[datetime] = mapped_column(
DateTime, nullable=False, index=True
)
Expand All @@ -50,8 +50,8 @@ class DBOperationalPresence(Base):

resource = relationship("DBResource")
admin2 = relationship("DBAdmin2")
org = relationship("DBOrg")
sector = relationship("DBSector")
org = relationship("DBOrg")


view_params_operational_presence = ViewParams(
Expand All @@ -75,11 +75,11 @@ class DBOperationalPresence(Base):
DBAdmin2.code.label("admin2_code"),
DBAdmin2.name.label("admin2_name"),
DBAdmin2.is_unspecified.label("admin2_is_unspecified"),
DBSector.name.label("sector_name"),
DBOrg.acronym.label("org_acronym"),
DBOrg.name.label("org_name"),
DBOrg.org_type_code.label("org_type_code"),
DBOrgType.description.label("org_type_description"),
DBSector.name.label("sector_name")
DBOrgType.description.label("org_type_description")
).select_from(
# Join op to admin2 to admin1 to loc
DBOperationalPresence.__table__.join(
Expand Down Expand Up @@ -108,6 +108,12 @@ class DBOperationalPresence(Base):
DBResource.dataset_ref == DBDataset.id,
isouter=True,
)
# Join op to sector
.join(
DBSector.__table__,
DBOperationalPresence.sector_code == DBSector.code,
isouter=True,
)
# Join op to org to org type
.join(
DBOrg.__table__,
Expand All @@ -119,11 +125,5 @@ class DBOperationalPresence(Base):
DBOrg.org_type_code == DBOrgType.code,
isouter=True,
)
# Join op to sector
.join(
DBSector.__table__,
DBOperationalPresence.sector_code == DBSector.code,
isouter=True,
)
),
)
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def engine():
session.execute(insert(DBLocation), data_location)
session.execute(insert(DBAdmin1), data_admin1)
session.execute(insert(DBAdmin2), data_admin2)
session.execute(insert(DBSector), data_sector)
session.execute(insert(DBGender), data_gender)
session.execute(insert(DBAgeRange), data_age_range)
session.execute(insert(DBSector), data_sector)
session.execute(insert(DBOrg), data_org)
session.execute(insert(DBOrgType), data_org_type)
session.execute(insert(DBPopulationGroup), data_population_group)
Expand Down

0 comments on commit b178a87

Please sign in to comment.