hapi-schema 0.8.0__tar.gz → 0.8.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/PKG-INFO +1 -1
  2. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/changelog.md +27 -4
  3. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/_version.py +2 -2
  4. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_admin1.py +3 -17
  5. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_admin2.py +3 -20
  6. hapi_schema-0.8.3/src/hapi_schema/db_currency.py +21 -0
  7. hapi_schema-0.8.3/src/hapi_schema/db_food_price.py +126 -0
  8. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_food_security.py +2 -37
  9. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_funding.py +6 -3
  10. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_humanitarian_needs.py +0 -37
  11. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_location.py +4 -0
  12. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_national_risk.py +11 -29
  13. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_operational_presence.py +0 -31
  14. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_org.py +0 -8
  15. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_patch.py +25 -7
  16. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_population.py +0 -28
  17. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_refugees.py +2 -1
  18. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_resource.py +0 -18
  19. hapi_schema-0.8.3/src/hapi_schema/db_views_as_tables.py +302 -0
  20. hapi_schema-0.8.3/src/hapi_schema/db_wfp_commodity.py +25 -0
  21. hapi_schema-0.8.3/src/hapi_schema/db_wfp_market.py +63 -0
  22. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/utils/constraints.py +14 -0
  23. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/utils/enums.py +23 -1
  24. hapi_schema-0.8.3/src/hapi_schema/utils/hapi_views_code_generator.py +213 -0
  25. hapi_schema-0.8.3/src/hapi_schema/utils/view_as_table_code_generator.py +191 -0
  26. hapi_schema-0.8.3/src/hapi_schema/utils/view_as_table_definitions.toml +159 -0
  27. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/conftest.py +14 -0
  28. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_admin1.py +1 -0
  29. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_admin2.py +3 -0
  30. hapi_schema-0.8.3/tests/sample_data/data_currency.py +10 -0
  31. hapi_schema-0.8.3/tests/sample_data/data_food_price.py +30 -0
  32. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_location.py +1 -0
  33. hapi_schema-0.8.3/tests/sample_data/data_wfp_commodity.py +12 -0
  34. hapi_schema-0.8.3/tests/sample_data/data_wfp_market.py +9 -0
  35. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/test_admin1.py +10 -10
  36. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/test_admin2.py +10 -13
  37. hapi_schema-0.8.3/tests/test_currency.py +15 -0
  38. hapi_schema-0.8.3/tests/test_food_price.py +78 -0
  39. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/test_food_security.py +0 -19
  40. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/test_humanitarian_needs.py +0 -19
  41. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/test_location.py +12 -0
  42. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/test_national_risk.py +0 -18
  43. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/test_operational_presence.py +0 -27
  44. hapi_schema-0.8.3/tests/test_org.py +15 -0
  45. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/test_patch.py +1 -3
  46. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/test_population.py +0 -25
  47. hapi_schema-0.8.3/tests/test_resource.py +15 -0
  48. hapi_schema-0.8.3/tests/test_views_as_tables.py +312 -0
  49. hapi_schema-0.8.3/tests/test_wfp_commodity.py +18 -0
  50. hapi_schema-0.8.3/tests/test_wfp_market.py +61 -0
  51. hapi_schema-0.8.0/src/hapi_schema/utils/view_as_table_code_generator.py +0 -125
  52. hapi_schema-0.8.0/tests/test_org.py +0 -32
  53. hapi_schema-0.8.0/tests/test_resource.py +0 -33
  54. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/.config/coveragerc +0 -0
  55. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/.config/pre-commit-config.yaml +0 -0
  56. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/.config/pytest.ini +0 -0
  57. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/.config/ruff.toml +0 -0
  58. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/.github/workflows/publish.yaml +0 -0
  59. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/.github/workflows/run-python-tests.yaml +0 -0
  60. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/.gitignore +0 -0
  61. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/LICENSE +0 -0
  62. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/README.md +0 -0
  63. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/contributing.md +0 -0
  64. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/docker/docker-compose.yml +0 -0
  65. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/initialize_test_db.sh +0 -0
  66. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/pyproject.toml +0 -0
  67. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/requirements.txt +0 -0
  68. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/__init__.py +0 -0
  69. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_conflict_event.py +0 -0
  70. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_dataset.py +0 -0
  71. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_org_type.py +0 -0
  72. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_poverty_rate.py +0 -0
  73. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/db_sector.py +0 -0
  74. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/utils/__init__.py +0 -0
  75. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/utils/base.py +0 -0
  76. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/utils/view_params.py +0 -0
  77. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/src/hapi_schema/views.py +0 -0
  78. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/__init__.py +0 -0
  79. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_conflict_event.py +0 -0
  80. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_dataset.py +0 -0
  81. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_food_security.py +0 -0
  82. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_funding.py +0 -0
  83. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_humanitarian_needs.py +0 -0
  84. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_national_risk.py +0 -0
  85. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_operational_presence.py +0 -0
  86. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_org.py +0 -0
  87. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_org_type.py +0 -0
  88. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_patch.py +0 -0
  89. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_population.py +0 -0
  90. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_poverty_rate.py +0 -0
  91. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_refugees.py +0 -0
  92. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_resource.py +0 -0
  93. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/sample_data/data_sector.py +0 -0
  94. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/test_conflict_event.py +0 -0
  95. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/test_dataset.py +0 -0
  96. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/test_funding.py +0 -0
  97. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/test_org_type.py +0 -0
  98. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/test_poverty_rate.py +0 -0
  99. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/test_refugees.py +0 -0
  100. {hapi_schema-0.8.0 → hapi_schema-0.8.3}/tests/test_sector.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: hapi-schema
3
- Version: 0.8.0
3
+ Version: 0.8.3
4
4
  Summary: HAPI database schema specified in SQLAlchemy
5
5
  Project-URL: Homepage, https://github.com/OCHA-DAP/hapi-schemas
6
6
  Author-email: Simon Johnson <simon.johnson@un.org>
@@ -5,6 +5,30 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 0.8.3
9
+
10
+ ### Changed
11
+ - fixed WFP commodity enum
12
+ - change FLOAT to DECIMAL in funding, national\_risk, and food\_security
13
+
14
+ ## 0.8.2
15
+
16
+ Miscellaneous fixes for pipelines
17
+
18
+ ### Changed
19
+ - added from\_cods column to location, admin1, and admin2
20
+
21
+
22
+ ## 0.8.1
23
+
24
+ Implemented the Food Prices subcategory.
25
+
26
+ ### Added
27
+ - New tables and views: food\_price, wfp\_commodity, wfp\_market, currency
28
+ - New enums: PriceFlag, PriceType, CommodityCategory
29
+ - New constraints: non\_negative\_constraint, latlon\_constraint
30
+
31
+
8
32
  ## 0.8.0
9
33
 
10
34
  ### Changed
@@ -17,14 +41,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
17
41
  - Programmatically obtain views
18
42
 
19
43
  ### Added
20
- - New tables: humanitarian\_needs, funding, refugees, conflict\_events, poverty_rate
21
- - New enums: Gender, DisabledMarker, EventType, PopulationGroup, PopulationStatus, IPCPhase, PovertyClassification
22
- IPCType, and RiskClass
44
+ - New tables: humanitarian\_needs, funding, refugees, conflict\_event, poverty\_rate
45
+ - New enums: Gender, DisabledMarker, EventType, PopulationGroup, PopulationStatus, IPCPhase, PovertyClassification, IPCType, and RiskClass
23
46
  - Generalized constraints
24
47
 
25
48
  ### Removed
26
49
 
27
- - ipc_phase, ipc_type, age_range, and gender tables
50
+ - ipc\_phase, ipc\_type, age\_range, and gender tables
28
51
 
29
52
 
30
53
  ## [0.7.3]
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.8.0'
16
- __version_tuple__ = version_tuple = (0, 8, 0)
15
+ __version__ = version = '0.8.3'
16
+ __version_tuple__ = version_tuple = (0, 8, 3)
@@ -39,6 +39,9 @@ class DBAdmin1(Base):
39
39
  is_unspecified: Mapped[bool] = mapped_column(
40
40
  Boolean, server_default=text("FALSE"), nullable=False
41
41
  )
42
+ from_cods: Mapped[bool] = mapped_column(
43
+ Boolean, nullable=False, server_default=text("TRUE")
44
+ )
42
45
  reference_period_start: Mapped[datetime] = mapped_column(
43
46
  DateTime, nullable=True, server_default=text("NULL"), index=True
44
47
  )
@@ -64,20 +67,3 @@ view_params_admin1 = ViewParams(
64
67
  )
65
68
  ),
66
69
  )
67
-
68
-
69
- class DBAdmin1VAT(Base):
70
- __tablename__ = "admin1_vat"
71
- id: Mapped[int] = mapped_column(Integer, primary_key=True)
72
- location_ref: Mapped[int] = mapped_column(Integer)
73
- code: Mapped[str] = mapped_column(String(128))
74
- name: Mapped[str] = mapped_column(String(512))
75
- is_unspecified: Mapped[bool] = mapped_column(Boolean)
76
- reference_period_start: Mapped[datetime] = mapped_column(
77
- DateTime, index=True
78
- )
79
- reference_period_end: Mapped[datetime] = mapped_column(
80
- DateTime, index=True
81
- )
82
- location_code: Mapped[str] = mapped_column(String(128), index=True)
83
- location_name: Mapped[str] = mapped_column(String(512), index=True)
@@ -40,6 +40,9 @@ class DBAdmin2(Base):
40
40
  is_unspecified: Mapped[bool] = mapped_column(
41
41
  Boolean, server_default=text("FALSE"), nullable=False
42
42
  )
43
+ from_cods: Mapped[bool] = mapped_column(
44
+ Boolean, nullable=False, server_default=text("TRUE")
45
+ )
43
46
  reference_period_start: Mapped[datetime] = mapped_column(
44
47
  DateTime, nullable=True, server_default=text("NULL"), index=True
45
48
  )
@@ -72,23 +75,3 @@ view_params_admin2 = ViewParams(
72
75
  ),
73
76
  ),
74
77
  )
75
-
76
-
77
- class DBAdmin2VAT(Base):
78
- __tablename__ = "admin2_vat"
79
- id: Mapped[int] = mapped_column(Integer, primary_key=True)
80
- admin1_ref: Mapped[int] = mapped_column(Integer)
81
- code: Mapped[str] = mapped_column(String(128), index=True)
82
- name: Mapped[str] = mapped_column(String(512), index=True)
83
- is_unspecified: Mapped[bool] = mapped_column(Boolean)
84
- reference_period_start: Mapped[datetime] = mapped_column(
85
- DateTime, index=True
86
- )
87
- reference_period_end: Mapped[datetime] = mapped_column(
88
- DateTime, index=True
89
- )
90
- admin1_code: Mapped[str] = mapped_column(String(128))
91
- admin1_name: Mapped[str] = mapped_column(String(512))
92
- admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
93
- location_code: Mapped[str] = mapped_column(String(128), index=True)
94
- location_name: Mapped[str] = mapped_column(String(512), index=True)
@@ -0,0 +1,21 @@
1
+ """Currency table and view."""
2
+
3
+ from sqlalchemy import String, select
4
+ from sqlalchemy.orm import Mapped, mapped_column
5
+
6
+ from hapi_schema.utils.base import Base
7
+ from hapi_schema.utils.view_params import ViewParams
8
+
9
+
10
+ class DBCurrency(Base):
11
+ __tablename__ = "currency"
12
+
13
+ code: Mapped[str] = mapped_column(String(32), primary_key=True)
14
+ name: Mapped[str] = mapped_column(String(512), nullable=False, index=True)
15
+
16
+
17
+ view_params_currency = ViewParams(
18
+ name="currency_view",
19
+ metadata=Base.metadata,
20
+ selectable=select(*DBCurrency.__table__.columns),
21
+ )
@@ -0,0 +1,126 @@
1
+ """FoodPrice table and view."""
2
+
3
+ from datetime import datetime
4
+ from decimal import Decimal
5
+
6
+ from sqlalchemy import (
7
+ DateTime,
8
+ Enum,
9
+ ForeignKey,
10
+ String,
11
+ select,
12
+ )
13
+ from sqlalchemy.orm import Mapped, mapped_column, relationship
14
+
15
+ from hapi_schema.db_admin2 import DBAdmin1, DBAdmin2, DBLocation
16
+ from hapi_schema.db_currency import DBCurrency
17
+ from hapi_schema.db_resource import DBResource
18
+ from hapi_schema.db_wfp_commodity import DBWFPCommodity
19
+ from hapi_schema.db_wfp_market import DBWFPMarket
20
+ from hapi_schema.utils.base import Base
21
+ from hapi_schema.utils.constraints import (
22
+ non_negative_constraint,
23
+ reference_period_constraint,
24
+ )
25
+ from hapi_schema.utils.enums import PriceFlag, PriceType
26
+ from hapi_schema.utils.view_params import ViewParams
27
+
28
+ # normalised table
29
+
30
+
31
+ class DBFoodPrice(Base):
32
+ __tablename__ = "food_price"
33
+ __table_args__ = (
34
+ non_negative_constraint(var_name="price"),
35
+ reference_period_constraint(),
36
+ )
37
+
38
+ resource_hdx_id: Mapped[str] = mapped_column(
39
+ ForeignKey("resource.hdx_id", onupdate="CASCADE", ondelete="CASCADE"),
40
+ nullable=False,
41
+ )
42
+ market_code: Mapped[str] = mapped_column(
43
+ ForeignKey("wfp_market.code"), primary_key=True
44
+ )
45
+ commodity_code: Mapped[str] = mapped_column(
46
+ ForeignKey("wfp_commodity.code"), primary_key=True
47
+ )
48
+ currency_code: Mapped[str] = mapped_column(
49
+ ForeignKey("currency.code", onupdate="CASCADE"),
50
+ nullable=False,
51
+ index=True,
52
+ )
53
+ unit: Mapped[str] = mapped_column(String(32), nullable=False)
54
+ price_flag: Mapped[PriceFlag] = mapped_column(
55
+ Enum(PriceFlag), primary_key=True
56
+ )
57
+ price_type: Mapped[PriceType] = mapped_column(
58
+ Enum(PriceType), primary_key=True
59
+ )
60
+ price: Mapped[Decimal] = mapped_column(nullable=False)
61
+ reference_period_start: Mapped[datetime] = mapped_column(
62
+ DateTime, primary_key=True
63
+ )
64
+ reference_period_end: Mapped[datetime] = mapped_column(
65
+ DateTime, nullable=False, index=True
66
+ )
67
+
68
+ resource = relationship(DBResource)
69
+ market = relationship(DBWFPMarket)
70
+ commodity = relationship(DBWFPCommodity)
71
+ currency = relationship(DBCurrency)
72
+
73
+
74
+ # denormalised view
75
+
76
+
77
+ view_params_food_price = ViewParams(
78
+ name="food_price_view",
79
+ metadata=Base.metadata,
80
+ selectable=select(
81
+ *DBFoodPrice.__table__.columns,
82
+ DBWFPMarket.admin2_ref.label("admin2_ref"),
83
+ DBWFPMarket.name.label("market_name"),
84
+ DBWFPMarket.lat.label("lat"),
85
+ DBWFPMarket.lon.label("lon"),
86
+ DBWFPCommodity.category.label("commodity_category"),
87
+ DBWFPCommodity.name.label("commodity_name"),
88
+ DBLocation.code.label("location_code"),
89
+ DBLocation.name.label("location_name"),
90
+ DBAdmin1.location_ref.label("location_ref"),
91
+ DBAdmin1.code.label("admin1_code"),
92
+ DBAdmin1.name.label("admin1_name"),
93
+ DBAdmin1.is_unspecified.label("admin1_is_unspecified"),
94
+ DBAdmin2.admin1_ref.label("admin1_ref"),
95
+ DBAdmin2.code.label("admin2_code"),
96
+ DBAdmin2.name.label("admin2_name"),
97
+ DBAdmin2.is_unspecified.label("admin2_is_unspecified"),
98
+ ).select_from(
99
+ # the admin2 comes from wfp_market
100
+ DBFoodPrice.__table__.join(
101
+ DBWFPMarket.__table__,
102
+ DBFoodPrice.market_code == DBWFPMarket.code,
103
+ isouter=True,
104
+ )
105
+ .join(
106
+ DBAdmin2.__table__,
107
+ DBWFPMarket.admin2_ref == DBAdmin2.id,
108
+ isouter=True,
109
+ )
110
+ .join(
111
+ DBAdmin1.__table__,
112
+ DBAdmin2.admin1_ref == DBAdmin1.id,
113
+ isouter=True,
114
+ )
115
+ .join(
116
+ DBLocation.__table__,
117
+ DBAdmin1.location_ref == DBLocation.id,
118
+ isouter=True,
119
+ )
120
+ .join(
121
+ DBWFPCommodity.__table__,
122
+ DBFoodPrice.commodity_code == DBWFPCommodity.code,
123
+ isouter=True,
124
+ )
125
+ ),
126
+ )
@@ -1,15 +1,14 @@
1
1
  """Food security table and view."""
2
2
 
3
3
  from datetime import datetime
4
+ from decimal import Decimal
4
5
 
5
6
  from sqlalchemy import (
6
- Boolean,
7
7
  DateTime,
8
8
  Enum,
9
9
  Float,
10
10
  ForeignKey,
11
11
  Integer,
12
- String,
13
12
  select,
14
13
  )
15
14
  from sqlalchemy.orm import Mapped, mapped_column, relationship
@@ -48,7 +47,7 @@ class DBFoodSecurity(Base):
48
47
  population_in_phase: Mapped[int] = mapped_column(
49
48
  Integer, nullable=False, index=True
50
49
  )
51
- population_fraction_in_phase: Mapped[float] = mapped_column(
50
+ population_fraction_in_phase: Mapped[Decimal] = mapped_column(
52
51
  Float, nullable=False, index=True
53
52
  )
54
53
  reference_period_start: Mapped[datetime] = mapped_column(
@@ -96,37 +95,3 @@ view_params_food_security = ViewParams(
96
95
  )
97
96
  ),
98
97
  )
99
-
100
-
101
- class DBFoodSecurityVAT(Base):
102
- __tablename__ = "food_security_vat"
103
- resource_hdx_id: Mapped[str] = mapped_column(String(36))
104
- admin2_ref: Mapped[int] = mapped_column(
105
- Integer, index=True, primary_key=True
106
- )
107
- ipc_phase: Mapped[IPCPhase] = mapped_column(
108
- Enum(IPCPhase), index=True, primary_key=True
109
- )
110
- ipc_type: Mapped[IPCType] = mapped_column(
111
- Enum(IPCType), index=True, primary_key=True
112
- )
113
- population_in_phase: Mapped[int] = mapped_column(Integer, primary_key=True)
114
- population_fraction_in_phase: Mapped[float] = mapped_column(
115
- Float, index=True, primary_key=True
116
- )
117
- reference_period_start: Mapped[datetime] = mapped_column(
118
- DateTime, index=True
119
- )
120
- reference_period_end: Mapped[datetime] = mapped_column(
121
- DateTime, index=True
122
- )
123
- location_code: Mapped[str] = mapped_column(String(128))
124
- location_name: Mapped[str] = mapped_column(String(512), index=True)
125
- admin1_code: Mapped[str] = mapped_column(String(128))
126
- admin1_name: Mapped[str] = mapped_column(String(512))
127
- admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
128
- location_ref: Mapped[int] = mapped_column(Integer)
129
- admin2_code: Mapped[str] = mapped_column(String(128), index=True)
130
- admin2_name: Mapped[str] = mapped_column(String(512), index=True)
131
- admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
132
- admin1_ref: Mapped[int] = mapped_column(Integer)
@@ -1,6 +1,7 @@
1
1
  """Funding subcategory table and view."""
2
2
 
3
3
  from datetime import datetime
4
+ from decimal import Decimal
4
5
 
5
6
  from sqlalchemy import (
6
7
  CheckConstraint,
@@ -55,11 +56,13 @@ class DBFunding(Base):
55
56
 
56
57
  appeal_type: Mapped[str] = mapped_column(String(32), nullable=False)
57
58
 
58
- requirements_usd: Mapped[float] = mapped_column(nullable=False, index=True)
59
+ requirements_usd: Mapped[Decimal] = mapped_column(
60
+ nullable=False, index=True
61
+ )
59
62
 
60
- funding_usd: Mapped[float] = mapped_column(nullable=False, index=True)
63
+ funding_usd: Mapped[Decimal] = mapped_column(nullable=False, index=True)
61
64
 
62
- funding_pct: Mapped[float] = mapped_column(nullable=False, index=True)
65
+ funding_pct: Mapped[Decimal] = mapped_column(nullable=False, index=True)
63
66
 
64
67
  reference_period_start: Mapped[datetime] = mapped_column(
65
68
  DateTime,
@@ -3,7 +3,6 @@
3
3
  from datetime import datetime
4
4
 
5
5
  from sqlalchemy import (
6
- Boolean,
7
6
  DateTime,
8
7
  Enum,
9
8
  ForeignKey,
@@ -126,39 +125,3 @@ view_params_humanitarian_needs = ViewParams(
126
125
  )
127
126
  ),
128
127
  )
129
-
130
-
131
- class DBHumanitarianNeedsVAT(Base):
132
- __tablename__ = "humanitarian_needs_vat"
133
- resource_hdx_id: Mapped[str] = mapped_column(String(36))
134
- admin2_ref: Mapped[int] = mapped_column(
135
- Integer, index=True, primary_key=True
136
- )
137
- gender: Mapped[str] = mapped_column(String(11), primary_key=True)
138
- age_range: Mapped[str] = mapped_column(String(32), primary_key=True)
139
- min_age: Mapped[int] = mapped_column(Integer, index=True)
140
- max_age: Mapped[int] = mapped_column(Integer, index=True)
141
- sector_code: Mapped[str] = mapped_column(String(32), primary_key=True)
142
- population_group: Mapped[str] = mapped_column(String(14), primary_key=True)
143
- population_status: Mapped[str] = mapped_column(
144
- String(10), primary_key=True
145
- )
146
- disabled_marker: Mapped[str] = mapped_column(String(3), primary_key=True)
147
- population: Mapped[int] = mapped_column(Integer, primary_key=True)
148
- reference_period_start: Mapped[datetime] = mapped_column(
149
- DateTime, primary_key=True
150
- )
151
- reference_period_end: Mapped[datetime] = mapped_column(
152
- DateTime, index=True
153
- )
154
- sector_name: Mapped[str] = mapped_column(String(512))
155
- location_code: Mapped[str] = mapped_column(String(128))
156
- location_name: Mapped[str] = mapped_column(String(512), index=True)
157
- location_ref: Mapped[int] = mapped_column(Integer)
158
- admin1_code: Mapped[str] = mapped_column(String(128))
159
- admin1_name: Mapped[str] = mapped_column(String(512))
160
- admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
161
- admin2_code: Mapped[str] = mapped_column(String(128), index=True)
162
- admin2_name: Mapped[str] = mapped_column(String(512), index=True)
163
- admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
164
- admin1_ref: Mapped[int] = mapped_column(Integer)
@@ -3,6 +3,7 @@
3
3
  from datetime import datetime
4
4
 
5
5
  from sqlalchemy import (
6
+ Boolean,
6
7
  DateTime,
7
8
  Integer,
8
9
  String,
@@ -29,6 +30,9 @@ class DBLocation(Base):
29
30
  id: Mapped[int] = mapped_column(Integer, primary_key=True)
30
31
  code: Mapped[str] = mapped_column(String(128), nullable=False, index=True)
31
32
  name: Mapped[str] = mapped_column(String(512), nullable=False, index=True)
33
+ from_cods: Mapped[bool] = mapped_column(
34
+ Boolean, nullable=False, server_default=text("TRUE")
35
+ )
32
36
  reference_period_start: Mapped[datetime] = mapped_column(
33
37
  DateTime, nullable=True, server_default=text("NULL"), index=True
34
38
  )
@@ -1,6 +1,7 @@
1
1
  """NationalRisk table and view."""
2
2
 
3
3
  from datetime import datetime
4
+ from decimal import Decimal
4
5
 
5
6
  from sqlalchemy import (
6
7
  CheckConstraint,
@@ -9,7 +10,6 @@ from sqlalchemy import (
9
10
  Float,
10
11
  ForeignKey,
11
12
  Integer,
12
- String,
13
13
  select,
14
14
  )
15
15
  from sqlalchemy.orm import Mapped, mapped_column, relationship
@@ -56,14 +56,18 @@ class DBNationalRisk(Base):
56
56
  Enum(RiskClass), nullable=False
57
57
  )
58
58
  global_rank: Mapped[int] = mapped_column(Integer, nullable=False)
59
- overall_risk: Mapped[float] = mapped_column(Float, nullable=False)
60
- hazard_exposure_risk: Mapped[float] = mapped_column(Float, nullable=False)
61
- vulnerability_risk: Mapped[float] = mapped_column(Float, nullable=False)
62
- coping_capacity_risk: Mapped[float] = mapped_column(Float, nullable=False)
63
- meta_missing_indicators_pct: Mapped[float] = mapped_column(
59
+ overall_risk: Mapped[Decimal] = mapped_column(Float, nullable=False)
60
+ hazard_exposure_risk: Mapped[Decimal] = mapped_column(
61
+ Float, nullable=False
62
+ )
63
+ vulnerability_risk: Mapped[Decimal] = mapped_column(Float, nullable=False)
64
+ coping_capacity_risk: Mapped[Decimal] = mapped_column(
65
+ Float, nullable=False
66
+ )
67
+ meta_missing_indicators_pct: Mapped[Decimal] = mapped_column(
64
68
  Float, nullable=True
65
69
  )
66
- meta_avg_recentness_years: Mapped[float] = mapped_column(
70
+ meta_avg_recentness_years: Mapped[Decimal] = mapped_column(
67
71
  Float, nullable=True
68
72
  )
69
73
  reference_period_start: Mapped[datetime] = mapped_column(
@@ -93,25 +97,3 @@ view_params_national_risk = ViewParams(
93
97
  )
94
98
  ),
95
99
  )
96
-
97
-
98
- class DBNationalRiskVAT(Base):
99
- __tablename__ = "national_risk_vat"
100
- resource_hdx_id: Mapped[str] = mapped_column(String(36))
101
- location_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
102
- risk_class: Mapped[str] = mapped_column(String(9))
103
- global_rank: Mapped[int] = mapped_column(Integer)
104
- overall_risk: Mapped[float] = mapped_column(Float)
105
- hazard_exposure_risk: Mapped[float] = mapped_column(Float)
106
- vulnerability_risk: Mapped[float] = mapped_column(Float)
107
- coping_capacity_risk: Mapped[float] = mapped_column(Float)
108
- meta_missing_indicators_pct: Mapped[float] = mapped_column(Float)
109
- meta_avg_recentness_years: Mapped[float] = mapped_column(Float)
110
- reference_period_start: Mapped[datetime] = mapped_column(
111
- DateTime, primary_key=True
112
- )
113
- reference_period_end: Mapped[datetime] = mapped_column(
114
- DateTime, primary_key=True
115
- )
116
- location_code: Mapped[str] = mapped_column(String(128))
117
- location_name: Mapped[str] = mapped_column(String(512))
@@ -3,11 +3,9 @@
3
3
  from datetime import datetime
4
4
 
5
5
  from sqlalchemy import (
6
- Boolean,
7
6
  DateTime,
8
7
  ForeignKey,
9
8
  ForeignKeyConstraint,
10
- Integer,
11
9
  String,
12
10
  select,
13
11
  text,
@@ -111,32 +109,3 @@ view_params_operational_presence = ViewParams(
111
109
  )
112
110
  ),
113
111
  )
114
-
115
-
116
- class DBOperationalPresenceVAT(Base):
117
- __tablename__ = "operational_presence_vat"
118
- resource_hdx_id: Mapped[str] = mapped_column(String(36))
119
- admin2_ref: Mapped[int] = mapped_column(
120
- Integer, primary_key=True, index=True
121
- )
122
- org_acronym: Mapped[str] = mapped_column(String, primary_key=True)
123
- org_name: Mapped[str] = mapped_column(String, primary_key=True)
124
- sector_code: Mapped[str] = mapped_column(String(32))
125
- reference_period_start: Mapped[datetime] = mapped_column(
126
- DateTime, primary_key=True
127
- )
128
- reference_period_end: Mapped[datetime] = mapped_column(
129
- DateTime, index=True
130
- )
131
- org_type_code: Mapped[str] = mapped_column(String(32))
132
- sector_name: Mapped[str] = mapped_column(String(512))
133
- location_code: Mapped[str] = mapped_column(String(128))
134
- location_name: Mapped[str] = mapped_column(String(512), index=True)
135
- admin1_code: Mapped[str] = mapped_column(String(128))
136
- admin1_name: Mapped[str] = mapped_column(String(512))
137
- admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
138
- location_ref: Mapped[int] = mapped_column(Integer)
139
- admin2_code: Mapped[str] = mapped_column(String(128), index=True)
140
- admin2_name: Mapped[str] = mapped_column(String(512), index=True)
141
- admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
142
- admin1_ref: Mapped[int] = mapped_column(Integer)
@@ -37,11 +37,3 @@ view_params_org = ViewParams(
37
37
  )
38
38
  ),
39
39
  )
40
-
41
-
42
- class DBOrgVAT(Base):
43
- __tablename__ = "org_vat"
44
- acronym: Mapped[str] = mapped_column(String(32), primary_key=True)
45
- name: Mapped[str] = mapped_column(String(512), primary_key=True)
46
- org_type_code: Mapped[str] = mapped_column(String(32))
47
- org_type_description: Mapped[str] = mapped_column(String(512))
@@ -3,10 +3,11 @@
3
3
  import enum
4
4
  from datetime import datetime
5
5
 
6
- from sqlalchemy import DateTime, Enum, Integer, String
6
+ from sqlalchemy import DateTime, Enum, Integer, String, select
7
7
  from sqlalchemy.orm import Mapped, mapped_column
8
8
 
9
9
  from hapi_schema.utils.base import Base
10
+ from hapi_schema.utils.view_params import ViewParams
10
11
 
11
12
 
12
13
  class StateEnum(str, enum.Enum):
@@ -24,9 +25,7 @@ class DBPatch(Base):
24
25
  patch_sequence_number: Mapped[int] = mapped_column(
25
26
  Integer, nullable=False, index=True
26
27
  )
27
- commit_hash: Mapped[str] = mapped_column(
28
- String(48), unique=True, nullable=False
29
- )
28
+ commit_hash: Mapped[str] = mapped_column(String(48), nullable=False)
30
29
  commit_date: Mapped[datetime] = mapped_column(DateTime, nullable=False)
31
30
  patch_path: Mapped[str] = mapped_column(
32
31
  String(512), nullable=False, index=True
@@ -35,12 +34,31 @@ class DBPatch(Base):
35
34
  String(1024), nullable=False, unique=True
36
35
  )
37
36
  patch_target: Mapped[str] = mapped_column(String(128), nullable=False)
38
- patch_hash: Mapped[str] = mapped_column(
39
- String(48), unique=True, nullable=False
40
- )
37
+ patch_hash: Mapped[str] = mapped_column(String(48), nullable=False)
41
38
  state: Mapped[StateEnum] = mapped_column(
42
39
  Enum(StateEnum), nullable=False, index=True
43
40
  )
44
41
  execution_date: Mapped[datetime] = mapped_column(
45
42
  DateTime, nullable=True, index=True
46
43
  )
44
+
45
+
46
+ view_params_patch = ViewParams(
47
+ name="patch_view",
48
+ metadata=Base.metadata,
49
+ selectable=select(*DBPatch.__table__.columns),
50
+ )
51
+
52
+
53
+ class DBPatchVAT(Base):
54
+ __tablename__ = "patch_vat"
55
+ id: Mapped[int] = mapped_column(Integer, primary_key=True)
56
+ patch_sequence_number: Mapped[int] = mapped_column(Integer, index=True)
57
+ commit_hash: Mapped[str] = mapped_column(String(48))
58
+ commit_date: Mapped[datetime] = mapped_column(DateTime)
59
+ patch_path: Mapped[str] = mapped_column(String(512), index=True)
60
+ patch_permalink_url: Mapped[str] = mapped_column(String(1024))
61
+ patch_target: Mapped[str] = mapped_column(String(128))
62
+ patch_hash: Mapped[str] = mapped_column(String(48))
63
+ state: Mapped[str] = mapped_column(String(10), index=True)
64
+ execution_date: Mapped[datetime] = mapped_column(DateTime, index=True)
@@ -3,7 +3,6 @@
3
3
  from datetime import datetime
4
4
 
5
5
  from sqlalchemy import (
6
- Boolean,
7
6
  DateTime,
8
7
  Enum,
9
8
  ForeignKey,
@@ -96,30 +95,3 @@ view_params_population = ViewParams(
96
95
  )
97
96
  ),
98
97
  )
99
-
100
-
101
- class DBPopulationVAT(Base):
102
- __tablename__ = "population_vat"
103
- resource_hdx_id: Mapped[str] = mapped_column(String(36))
104
- admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
105
- gender: Mapped[str] = mapped_column(String(11), primary_key=True)
106
- age_range: Mapped[str] = mapped_column(String(32), primary_key=True)
107
- min_age: Mapped[int] = mapped_column(Integer, index=True)
108
- max_age: Mapped[int] = mapped_column(Integer, index=True)
109
- population: Mapped[int] = mapped_column(Integer)
110
- reference_period_start: Mapped[datetime] = mapped_column(
111
- DateTime, index=True
112
- )
113
- reference_period_end: Mapped[datetime] = mapped_column(
114
- DateTime, index=True
115
- )
116
- location_code: Mapped[str] = mapped_column(String(128))
117
- location_name: Mapped[str] = mapped_column(String(512))
118
- admin1_code: Mapped[str] = mapped_column(String(128))
119
- admin1_name: Mapped[str] = mapped_column(String(512))
120
- admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
121
- location_ref: Mapped[int] = mapped_column(Integer)
122
- admin2_code: Mapped[str] = mapped_column(String(128))
123
- admin2_name: Mapped[str] = mapped_column(String(512))
124
- admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
125
- admin1_ref: Mapped[int] = mapped_column(Integer)
@@ -64,7 +64,7 @@ class DBRefugees(Base):
64
64
  DateTime, nullable=False, index=True
65
65
  )
66
66
 
67
- resource = relationship("DBResource")
67
+ # resource = relationship("DBResource")
68
68
  origin_country = relationship(
69
69
  "DBLocation", foreign_keys=(origin_location_ref)
70
70
  )
@@ -76,6 +76,7 @@ class DBRefugees(Base):
76
76
  # Use aliases because we join to DBLocation twice
77
77
  origin_location = aliased(DBLocation)
78
78
  asylum_location = aliased(DBLocation)
79
+ resource = relationship("DBResource")
79
80
 
80
81
  view_params_refugees = ViewParams(
81
82
  name="refugees_view",