hapi-schema 0.8.8__tar.gz → 0.8.10__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 (97) hide show
  1. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/PKG-INFO +1 -1
  2. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/changelog.md +25 -8
  3. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/_version.py +2 -2
  4. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_food_price.py +7 -4
  5. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_food_security.py +5 -4
  6. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_humanitarian_needs.py +7 -5
  7. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_national_risk.py +2 -3
  8. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_patch.py +7 -3
  9. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_population.py +4 -3
  10. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_refugees.py +9 -4
  11. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_views_as_tables.py +98 -33
  12. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_wfp_commodity.py +3 -3
  13. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/utils/enums.py +3 -3
  14. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_patch.py +1 -2
  15. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_views_as_tables.py +3 -2
  16. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/.config/coveragerc +0 -0
  17. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/.config/pre-commit-config.yaml +0 -0
  18. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/.config/pytest.ini +0 -0
  19. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/.config/ruff.toml +0 -0
  20. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/.github/workflows/publish.yaml +0 -0
  21. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/.github/workflows/run-python-tests.yaml +0 -0
  22. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/.gitignore +0 -0
  23. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/LICENSE +0 -0
  24. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/README.md +0 -0
  25. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/contributing.md +0 -0
  26. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/docker/docker-compose.yml +0 -0
  27. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/initialize_test_db.sh +0 -0
  28. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/pyproject.toml +0 -0
  29. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/requirements.txt +0 -0
  30. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/__init__.py +0 -0
  31. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_admin1.py +0 -0
  32. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_admin2.py +0 -0
  33. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_conflict_event.py +0 -0
  34. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_currency.py +0 -0
  35. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_dataset.py +0 -0
  36. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_funding.py +0 -0
  37. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_location.py +0 -0
  38. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_operational_presence.py +0 -0
  39. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_org.py +0 -0
  40. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_org_type.py +0 -0
  41. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_poverty_rate.py +0 -0
  42. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_resource.py +0 -0
  43. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_sector.py +0 -0
  44. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/db_wfp_market.py +0 -0
  45. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/utils/__init__.py +0 -0
  46. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/utils/base.py +0 -0
  47. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/utils/constraints.py +0 -0
  48. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/utils/hapi_views_code_generator.py +0 -0
  49. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/utils/view_as_table_code_generator.py +0 -0
  50. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/utils/view_as_table_definitions.toml +0 -0
  51. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/utils/view_params.py +0 -0
  52. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/src/hapi_schema/views.py +0 -0
  53. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/conftest.py +0 -0
  54. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/__init__.py +0 -0
  55. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_admin1.py +0 -0
  56. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_admin2.py +0 -0
  57. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_conflict_event.py +0 -0
  58. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_currency.py +0 -0
  59. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_dataset.py +0 -0
  60. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_food_price.py +0 -0
  61. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_food_security.py +0 -0
  62. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_funding.py +0 -0
  63. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_humanitarian_needs.py +0 -0
  64. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_location.py +0 -0
  65. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_national_risk.py +0 -0
  66. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_operational_presence.py +0 -0
  67. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_org.py +0 -0
  68. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_org_type.py +0 -0
  69. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_patch.py +0 -0
  70. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_population.py +0 -0
  71. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_poverty_rate.py +0 -0
  72. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_refugees.py +0 -0
  73. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_resource.py +0 -0
  74. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_sector.py +0 -0
  75. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_wfp_commodity.py +0 -0
  76. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/sample_data/data_wfp_market.py +0 -0
  77. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_admin1.py +0 -0
  78. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_admin2.py +0 -0
  79. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_conflict_event.py +0 -0
  80. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_currency.py +0 -0
  81. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_dataset.py +0 -0
  82. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_food_price.py +0 -0
  83. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_food_security.py +0 -0
  84. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_funding.py +0 -0
  85. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_humanitarian_needs.py +0 -0
  86. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_location.py +0 -0
  87. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_national_risk.py +0 -0
  88. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_operational_presence.py +0 -0
  89. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_org.py +0 -0
  90. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_org_type.py +0 -0
  91. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_population.py +0 -0
  92. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_poverty_rate.py +0 -0
  93. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_refugees.py +0 -0
  94. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_resource.py +0 -0
  95. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_sector.py +0 -0
  96. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_wfp_commodity.py +0 -0
  97. {hapi_schema-0.8.8 → hapi_schema-0.8.10}/tests/test_wfp_market.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: hapi-schema
3
- Version: 0.8.8
3
+ Version: 0.8.10
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,10 +5,23 @@ 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.8
8
+ ## 0.8.10
9
9
 
10
10
  ### Changes
11
11
 
12
+ - Adapted primary keys and make columsn nullable in the VAT tables
13
+ - Use the enum casting util in the patch table
14
+
15
+ ## 0.8.9
16
+
17
+ ### Fixed
18
+
19
+ - Some enums missing built from values
20
+
21
+ ## 0.8.8
22
+
23
+ ### Changed
24
+
12
25
  - Rewrite enums to use values rather than variable names
13
26
  - Switch from "*" to "all" for rollup in enums
14
27
  - Add "intersectoral" to sample sector data (distinct from "all")
@@ -16,12 +29,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
16
29
 
17
30
  ## 0.8.7
18
31
 
19
- ## Changes
32
+ ### Changed
33
+
20
34
  - Add unit to food\_price table primary key
21
35
 
22
36
  ## 0.8.6
23
37
 
24
- ## Changes
38
+ ### Changed
39
+
25
40
  - Added food\_price view as tables by updating the toml parameter file
26
41
  - Updated poverty\_rate view as table
27
42
  - Updated operational\_presence view as table by updating the toml parameter file
@@ -29,11 +44,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
29
44
 
30
45
  ## 0.8.5
31
46
 
32
- ## Changes
47
+ ### Changed
48
+
33
49
  - refactor DBPovertyRate to wide instead of narrow
34
50
  - added org\_type\_description to operational\_presence\_view
35
51
 
36
52
  ## Removed
53
+
37
54
  - rate\_constraint and `PovertyClassification` enum
38
55
 
39
56
  ## 0.8.4
@@ -42,7 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
42
59
 
43
60
  - New constraints: rate\_constraint
44
61
 
45
- ### CHanged
62
+ ### Changed
46
63
 
47
64
  - refactor DBPovertyRate to track rates rather than population, and link to
48
65
  location (with admin1\_name as a text field)
@@ -60,19 +77,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
60
77
  Miscellaneous fixes for pipelines
61
78
 
62
79
  ### Changed
63
- - added from\_cods column to location, admin1, and admin2
64
80
 
81
+ - added from\_cods column to location, admin1, and admin2
65
82
 
66
83
  ## 0.8.1
67
84
 
68
85
  Implemented the Food Prices subcategory.
69
86
 
70
87
  ### Added
88
+
71
89
  - New tables and views: food\_price, wfp\_commodity, wfp\_market, currency
72
90
  - New enums: PriceFlag, PriceType, CommodityCategory
73
91
  - New constraints: non\_negative\_constraint, latlon\_constraint
74
92
 
75
-
76
93
  ## 0.8.0
77
94
 
78
95
  ### Changed
@@ -85,6 +102,7 @@ Implemented the Food Prices subcategory.
85
102
  - Programmatically obtain views
86
103
 
87
104
  ### Added
105
+
88
106
  - New tables: humanitarian\_needs, funding, refugees, conflict\_event, poverty\_rate
89
107
  - New enums: Gender, DisabledMarker, EventType, PopulationGroup, PopulationStatus, IPCPhase, PovertyClassification, IPCType, and RiskClass
90
108
  - Generalized constraints
@@ -93,7 +111,6 @@ Implemented the Food Prices subcategory.
93
111
 
94
112
  - ipc\_phase, ipc\_type, age\_range, and gender tables
95
113
 
96
-
97
114
  ## [0.7.3]
98
115
 
99
116
  ### Fixed
@@ -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.8'
16
- __version_tuple__ = version_tuple = (0, 8, 8)
15
+ __version__ = version = '0.8.10'
16
+ __version_tuple__ = version_tuple = (0, 8, 10)
@@ -5,7 +5,6 @@ from decimal import Decimal
5
5
 
6
6
  from sqlalchemy import (
7
7
  DateTime,
8
- Enum,
9
8
  ForeignKey,
10
9
  String,
11
10
  select,
@@ -22,7 +21,11 @@ from hapi_schema.utils.constraints import (
22
21
  non_negative_constraint,
23
22
  reference_period_constraint,
24
23
  )
25
- from hapi_schema.utils.enums import PriceFlag, PriceType
24
+ from hapi_schema.utils.enums import (
25
+ PriceFlag,
26
+ PriceType,
27
+ build_enum_using_values,
28
+ )
26
29
  from hapi_schema.utils.view_params import ViewParams
27
30
 
28
31
  # normalised table
@@ -52,10 +55,10 @@ class DBFoodPrice(Base):
52
55
  )
53
56
  unit: Mapped[str] = mapped_column(String(32), primary_key=True)
54
57
  price_flag: Mapped[PriceFlag] = mapped_column(
55
- Enum(PriceFlag), primary_key=True
58
+ build_enum_using_values(PriceFlag), primary_key=True
56
59
  )
57
60
  price_type: Mapped[PriceType] = mapped_column(
58
- Enum(PriceType), primary_key=True
61
+ build_enum_using_values(PriceType), primary_key=True
59
62
  )
60
63
  price: Mapped[Decimal] = mapped_column(nullable=False)
61
64
  reference_period_start: Mapped[datetime] = mapped_column(
@@ -5,7 +5,6 @@ from decimal import Decimal
5
5
 
6
6
  from sqlalchemy import (
7
7
  DateTime,
8
- Enum,
9
8
  Float,
10
9
  ForeignKey,
11
10
  Integer,
@@ -22,7 +21,7 @@ from hapi_schema.utils.constraints import (
22
21
  population_constraint,
23
22
  reference_period_constraint,
24
23
  )
25
- from hapi_schema.utils.enums import IPCPhase, IPCType
24
+ from hapi_schema.utils.enums import IPCPhase, IPCType, build_enum_using_values
26
25
  from hapi_schema.utils.view_params import ViewParams
27
26
 
28
27
 
@@ -41,9 +40,11 @@ class DBFoodSecurity(Base):
41
40
  ForeignKey("admin2.id", onupdate="CASCADE"), primary_key=True
42
41
  )
43
42
  ipc_phase: Mapped[IPCPhase] = mapped_column(
44
- Enum(IPCPhase), primary_key=True
43
+ build_enum_using_values(IPCPhase), primary_key=True
44
+ )
45
+ ipc_type: Mapped[IPCType] = mapped_column(
46
+ build_enum_using_values(IPCType), primary_key=True
45
47
  )
46
- ipc_type: Mapped[IPCType] = mapped_column(Enum(IPCType), primary_key=True)
47
48
  population_in_phase: Mapped[int] = mapped_column(
48
49
  Integer, nullable=False, index=True
49
50
  )
@@ -4,7 +4,6 @@ from datetime import datetime
4
4
 
5
5
  from sqlalchemy import (
6
6
  DateTime,
7
- Enum,
8
7
  ForeignKey,
9
8
  Integer,
10
9
  String,
@@ -28,6 +27,7 @@ from hapi_schema.utils.enums import (
28
27
  Gender,
29
28
  PopulationGroup,
30
29
  PopulationStatus,
30
+ build_enum_using_values,
31
31
  )
32
32
  from hapi_schema.utils.view_params import ViewParams
33
33
 
@@ -49,7 +49,9 @@ class DBHumanitarianNeeds(Base):
49
49
  ForeignKey("admin2.id", onupdate="CASCADE"),
50
50
  primary_key=True,
51
51
  )
52
- gender: Mapped[Gender] = mapped_column(Enum(Gender), primary_key=True)
52
+ gender: Mapped[Gender] = mapped_column(
53
+ build_enum_using_values(Gender), primary_key=True
54
+ )
53
55
  age_range: Mapped[str] = mapped_column(String(32), primary_key=True)
54
56
  min_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
55
57
  max_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
@@ -58,17 +60,17 @@ class DBHumanitarianNeeds(Base):
58
60
  primary_key=True,
59
61
  )
60
62
  population_group: Mapped[PopulationGroup] = mapped_column(
61
- Enum(PopulationGroup),
63
+ build_enum_using_values(PopulationGroup),
62
64
  primary_key=True,
63
65
  )
64
66
 
65
67
  population_status: Mapped[PopulationStatus] = mapped_column(
66
- Enum(PopulationStatus),
68
+ build_enum_using_values(PopulationStatus),
67
69
  primary_key=True,
68
70
  )
69
71
 
70
72
  disabled_marker: Mapped[DisabledMarker] = mapped_column(
71
- Enum(DisabledMarker), primary_key=True
73
+ build_enum_using_values(DisabledMarker), primary_key=True
72
74
  )
73
75
  population: Mapped[int] = mapped_column(Integer, nullable=False)
74
76
  reference_period_start: Mapped[datetime] = mapped_column(
@@ -6,7 +6,6 @@ from decimal import Decimal
6
6
  from sqlalchemy import (
7
7
  CheckConstraint,
8
8
  DateTime,
9
- Enum,
10
9
  Float,
11
10
  ForeignKey,
12
11
  Integer,
@@ -20,7 +19,7 @@ from hapi_schema.utils.constraints import (
20
19
  general_risk_constraint,
21
20
  reference_period_constraint,
22
21
  )
23
- from hapi_schema.utils.enums import RiskClass
22
+ from hapi_schema.utils.enums import RiskClass, build_enum_using_values
24
23
  from hapi_schema.utils.view_params import ViewParams
25
24
 
26
25
 
@@ -54,7 +53,7 @@ class DBNationalRisk(Base):
54
53
  ForeignKey("location.id", onupdate="CASCADE"), primary_key=True
55
54
  )
56
55
  risk_class: Mapped[RiskClass] = mapped_column(
57
- Enum(RiskClass), nullable=False
56
+ build_enum_using_values(RiskClass), nullable=False
58
57
  )
59
58
  global_rank: Mapped[int] = mapped_column(Integer, nullable=False)
60
59
  overall_risk: Mapped[Decimal] = mapped_column(Float, nullable=False)
@@ -25,16 +25,20 @@ class DBPatch(Base):
25
25
  patch_sequence_number: Mapped[int] = mapped_column(
26
26
  Integer, nullable=False, index=True
27
27
  )
28
- commit_hash: Mapped[str] = mapped_column(String(48), nullable=False)
28
+ commit_hash: Mapped[str] = mapped_column(
29
+ String(48), unique=False, nullable=False
30
+ )
29
31
  commit_date: Mapped[datetime] = mapped_column(DateTime, nullable=False)
30
32
  patch_path: Mapped[str] = mapped_column(
31
33
  String(512), nullable=False, index=True
32
34
  )
33
35
  patch_permalink_url: Mapped[str] = mapped_column(
34
- String(1024), nullable=False, unique=True
36
+ String(1024), nullable=False, unique=False
35
37
  )
36
38
  patch_target: Mapped[str] = mapped_column(String(128), nullable=False)
37
- patch_hash: Mapped[str] = mapped_column(String(48), nullable=False)
39
+ patch_hash: Mapped[str] = mapped_column(
40
+ String(48), unique=False, nullable=False
41
+ )
38
42
  state: Mapped[StateEnum] = mapped_column(
39
43
  Enum(StateEnum), nullable=False, index=True
40
44
  )
@@ -4,7 +4,6 @@ from datetime import datetime
4
4
 
5
5
  from sqlalchemy import (
6
6
  DateTime,
7
- Enum,
8
7
  ForeignKey,
9
8
  Integer,
10
9
  String,
@@ -22,7 +21,7 @@ from hapi_schema.utils.constraints import (
22
21
  population_constraint,
23
22
  reference_period_constraint,
24
23
  )
25
- from hapi_schema.utils.enums import Gender
24
+ from hapi_schema.utils.enums import Gender, build_enum_using_values
26
25
  from hapi_schema.utils.view_params import ViewParams
27
26
 
28
27
 
@@ -43,7 +42,9 @@ class DBPopulation(Base):
43
42
  ForeignKey("admin2.id", onupdate="CASCADE"),
44
43
  primary_key=True,
45
44
  )
46
- gender: Mapped[Gender] = mapped_column(Enum(Gender), primary_key=True)
45
+ gender: Mapped[Gender] = mapped_column(
46
+ build_enum_using_values(Gender), primary_key=True
47
+ )
47
48
  age_range: Mapped[str] = mapped_column(String(32), primary_key=True)
48
49
  min_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
49
50
  max_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
@@ -7,7 +7,6 @@ from datetime import datetime
7
7
 
8
8
  from sqlalchemy import (
9
9
  DateTime,
10
- Enum,
11
10
  ForeignKey,
12
11
  Integer,
13
12
  String,
@@ -23,7 +22,11 @@ from hapi_schema.utils.constraints import (
23
22
  population_constraint,
24
23
  reference_period_constraint,
25
24
  )
26
- from hapi_schema.utils.enums import Gender, PopulationGroup
25
+ from hapi_schema.utils.enums import (
26
+ Gender,
27
+ PopulationGroup,
28
+ build_enum_using_values,
29
+ )
27
30
  from hapi_schema.utils.view_params import ViewParams
28
31
 
29
32
 
@@ -48,9 +51,11 @@ class DBRefugees(Base):
48
51
  )
49
52
  # population_group is broader than we need, but it will do
50
53
  population_group: Mapped[PopulationGroup] = mapped_column(
51
- Enum(PopulationGroup), primary_key=True
54
+ build_enum_using_values(PopulationGroup), primary_key=True
55
+ )
56
+ gender: Mapped[Gender] = mapped_column(
57
+ build_enum_using_values(Gender), primary_key=True
52
58
  )
53
- gender: Mapped[Gender] = mapped_column(Enum(Gender), primary_key=True)
54
59
  age_range: Mapped[str] = mapped_column(String(32), primary_key=True)
55
60
  min_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
56
61
  max_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
@@ -11,6 +11,20 @@ from sqlalchemy import (
11
11
  from sqlalchemy.orm import Mapped, mapped_column
12
12
 
13
13
  from hapi_schema.utils.base import Base
14
+ from hapi_schema.utils.enums import (
15
+ CommodityCategory,
16
+ DisabledMarker,
17
+ EventType,
18
+ Gender,
19
+ IPCPhase,
20
+ IPCType,
21
+ PopulationGroup,
22
+ PopulationStatus,
23
+ PriceFlag,
24
+ PriceType,
25
+ RiskClass,
26
+ build_enum_using_values,
27
+ )
14
28
 
15
29
 
16
30
  class DBAdmin1VAT(Base):
@@ -25,7 +39,9 @@ class DBAdmin1VAT(Base):
25
39
  DateTime, index=True
26
40
  )
27
41
  reference_period_end: Mapped[datetime] = mapped_column(
28
- DateTime, index=True
42
+ DateTime,
43
+ index=True,
44
+ nullable=True,
29
45
  )
30
46
  location_code: Mapped[str] = mapped_column(String(128), index=True)
31
47
  location_name: Mapped[str] = mapped_column(String(512), index=True)
@@ -43,7 +59,9 @@ class DBAdmin2VAT(Base):
43
59
  DateTime, nullable=True, index=True
44
60
  )
45
61
  reference_period_end: Mapped[datetime] = mapped_column(
46
- DateTime, nullable=True, index=True
62
+ DateTime,
63
+ nullable=True,
64
+ index=True,
47
65
  )
48
66
  admin1_code: Mapped[str] = mapped_column(String(128))
49
67
  admin1_name: Mapped[str] = mapped_column(String(512))
@@ -56,14 +74,18 @@ class DBConflictEventVAT(Base):
56
74
  __tablename__ = "conflict_event_vat"
57
75
  resource_hdx_id: Mapped[str] = mapped_column(String(36))
58
76
  admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
59
- event_type: Mapped[str] = mapped_column(String(18), primary_key=True)
77
+ event_type: Mapped[EventType] = mapped_column(
78
+ build_enum_using_values(EventType), primary_key=True
79
+ )
60
80
  events: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
61
81
  fatalities: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
62
82
  reference_period_start: Mapped[datetime] = mapped_column(
63
83
  DateTime, primary_key=True
64
84
  )
65
85
  reference_period_end: Mapped[datetime] = mapped_column(
66
- DateTime, index=True
86
+ DateTime,
87
+ index=True,
88
+ nullable=True,
67
89
  )
68
90
  location_code: Mapped[str] = mapped_column(String(128), index=True)
69
91
  location_name: Mapped[str] = mapped_column(String(512), index=True)
@@ -98,22 +120,28 @@ class DBFoodPriceVAT(Base):
98
120
  market_code: Mapped[str] = mapped_column(String(32), primary_key=True)
99
121
  commodity_code: Mapped[str] = mapped_column(String(32), primary_key=True)
100
122
  currency_code: Mapped[str] = mapped_column(String(32), index=True)
101
- unit: Mapped[str] = mapped_column(String(32))
102
- price_flag: Mapped[str] = mapped_column(String(16), primary_key=True)
103
- price_type: Mapped[str] = mapped_column(String(9), primary_key=True)
123
+ unit: Mapped[str] = mapped_column(String(32), primary_key=True)
124
+ price_flag: Mapped[PriceFlag] = mapped_column(
125
+ build_enum_using_values(PriceFlag), primary_key=True
126
+ )
127
+ price_type: Mapped[PriceType] = mapped_column(
128
+ build_enum_using_values(PriceType), primary_key=True
129
+ )
104
130
  price: Mapped[Decimal] = mapped_column()
105
131
  reference_period_start: Mapped[datetime] = mapped_column(
106
132
  DateTime, primary_key=True
107
133
  )
108
134
  reference_period_end: Mapped[datetime] = mapped_column(
109
- DateTime, index=True
135
+ DateTime,
136
+ index=True,
137
+ nullable=True,
110
138
  )
111
139
  admin2_ref: Mapped[int] = mapped_column(Integer)
112
140
  market_name: Mapped[str] = mapped_column(String(512), index=True)
113
141
  lat: Mapped[float] = mapped_column(Float, index=True)
114
142
  lon: Mapped[float] = mapped_column(Float, index=True)
115
- commodity_category: Mapped[str] = mapped_column(
116
- String(18), primary_key=True
143
+ commodity_category: Mapped[CommodityCategory] = mapped_column(
144
+ build_enum_using_values(CommodityCategory)
117
145
  )
118
146
  commodity_name: Mapped[str] = mapped_column(String(512), index=True)
119
147
  location_code: Mapped[str] = mapped_column(String(128), index=True)
@@ -132,15 +160,21 @@ class DBFoodSecurityVAT(Base):
132
160
  __tablename__ = "food_security_vat"
133
161
  resource_hdx_id: Mapped[str] = mapped_column(String(36))
134
162
  admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
135
- ipc_phase: Mapped[str] = mapped_column(String(12), primary_key=True)
136
- ipc_type: Mapped[str] = mapped_column(String(17), primary_key=True)
163
+ ipc_phase: Mapped[IPCPhase] = mapped_column(
164
+ build_enum_using_values(IPCPhase), primary_key=True
165
+ )
166
+ ipc_type: Mapped[IPCType] = mapped_column(
167
+ build_enum_using_values(IPCType), primary_key=True
168
+ )
137
169
  population_in_phase: Mapped[int] = mapped_column(Integer, index=True)
138
170
  population_fraction_in_phase: Mapped[Decimal] = mapped_column(index=True)
139
171
  reference_period_start: Mapped[datetime] = mapped_column(
140
172
  DateTime, primary_key=True
141
173
  )
142
174
  reference_period_end: Mapped[datetime] = mapped_column(
143
- DateTime, index=True
175
+ DateTime,
176
+ index=True,
177
+ nullable=True,
144
178
  )
145
179
  location_code: Mapped[str] = mapped_column(String(128), index=True)
146
180
  location_name: Mapped[str] = mapped_column(String(512), index=True)
@@ -168,7 +202,8 @@ class DBFundingVAT(Base):
168
202
  DateTime, index=True
169
203
  )
170
204
  reference_period_end: Mapped[datetime] = mapped_column(
171
- DateTime, nullable=True
205
+ DateTime,
206
+ nullable=True,
172
207
  )
173
208
  location_code: Mapped[str] = mapped_column(String(128), index=True)
174
209
  location_name: Mapped[str] = mapped_column(String(512), index=True)
@@ -178,22 +213,30 @@ class DBHumanitarianNeedsVAT(Base):
178
213
  __tablename__ = "humanitarian_needs_vat"
179
214
  resource_hdx_id: Mapped[str] = mapped_column(String(36))
180
215
  admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
181
- gender: Mapped[str] = mapped_column(String(11), primary_key=True)
216
+ gender: Mapped[Gender] = mapped_column(
217
+ build_enum_using_values(Gender), primary_key=True
218
+ )
182
219
  age_range: Mapped[str] = mapped_column(String(32), primary_key=True)
183
220
  min_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
184
221
  max_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
185
- sector_code: Mapped[str] = mapped_column(String(32))
186
- population_group: Mapped[str] = mapped_column(String(14), primary_key=True)
187
- population_status: Mapped[str] = mapped_column(
188
- String(10), primary_key=True
222
+ sector_code: Mapped[str] = mapped_column(String(32), primary_key=True)
223
+ population_group: Mapped[PopulationGroup] = mapped_column(
224
+ build_enum_using_values(PopulationGroup), primary_key=True
225
+ )
226
+ population_status: Mapped[PopulationStatus] = mapped_column(
227
+ build_enum_using_values(PopulationStatus), primary_key=True
189
228
  )
190
- disabled_marker: Mapped[str] = mapped_column(String(3), primary_key=True)
191
- population: Mapped[int] = mapped_column(Integer, primary_key=True)
229
+ disabled_marker: Mapped[DisabledMarker] = mapped_column(
230
+ build_enum_using_values(DisabledMarker), primary_key=True
231
+ )
232
+ population: Mapped[int] = mapped_column(Integer)
192
233
  reference_period_start: Mapped[datetime] = mapped_column(
193
234
  DateTime, primary_key=True
194
235
  )
195
236
  reference_period_end: Mapped[datetime] = mapped_column(
196
- DateTime, index=True
237
+ DateTime,
238
+ index=True,
239
+ nullable=True,
197
240
  )
198
241
  sector_name: Mapped[str] = mapped_column(String(512))
199
242
  location_code: Mapped[str] = mapped_column(String(128), index=True)
@@ -218,7 +261,9 @@ class DBLocationVAT(Base):
218
261
  DateTime, index=True
219
262
  )
220
263
  reference_period_end: Mapped[datetime] = mapped_column(
221
- DateTime, index=True
264
+ DateTime,
265
+ index=True,
266
+ nullable=True,
222
267
  )
223
268
 
224
269
 
@@ -226,7 +271,9 @@ class DBNationalRiskVAT(Base):
226
271
  __tablename__ = "national_risk_vat"
227
272
  resource_hdx_id: Mapped[str] = mapped_column(String(36))
228
273
  location_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
229
- risk_class: Mapped[str] = mapped_column(String(9))
274
+ risk_class: Mapped[RiskClass] = mapped_column(
275
+ build_enum_using_values(RiskClass)
276
+ )
230
277
  global_rank: Mapped[int] = mapped_column(Integer)
231
278
  overall_risk: Mapped[Decimal] = mapped_column()
232
279
  hazard_exposure_risk: Mapped[Decimal] = mapped_column()
@@ -238,7 +285,9 @@ class DBNationalRiskVAT(Base):
238
285
  DateTime, primary_key=True
239
286
  )
240
287
  reference_period_end: Mapped[datetime] = mapped_column(
241
- DateTime, index=True
288
+ DateTime,
289
+ index=True,
290
+ nullable=True,
242
291
  )
243
292
  location_code: Mapped[str] = mapped_column(String(128), index=True)
244
293
  location_name: Mapped[str] = mapped_column(String(512), index=True)
@@ -255,7 +304,9 @@ class DBOperationalPresenceVAT(Base):
255
304
  DateTime, primary_key=True
256
305
  )
257
306
  reference_period_end: Mapped[datetime] = mapped_column(
258
- DateTime, index=True
307
+ DateTime,
308
+ index=True,
309
+ nullable=True,
259
310
  )
260
311
  org_type_code: Mapped[str] = mapped_column(String(32))
261
312
  org_type_description: Mapped[str] = mapped_column(String(512), index=True)
@@ -292,7 +343,9 @@ class DBPopulationVAT(Base):
292
343
  __tablename__ = "population_vat"
293
344
  resource_hdx_id: Mapped[str] = mapped_column(String(36))
294
345
  admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
295
- gender: Mapped[str] = mapped_column(String(11), primary_key=True)
346
+ gender: Mapped[Gender] = mapped_column(
347
+ build_enum_using_values(Gender), primary_key=True
348
+ )
296
349
  age_range: Mapped[str] = mapped_column(String(32), primary_key=True)
297
350
  min_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
298
351
  max_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
@@ -301,7 +354,9 @@ class DBPopulationVAT(Base):
301
354
  DateTime, index=True
302
355
  )
303
356
  reference_period_end: Mapped[datetime] = mapped_column(
304
- DateTime, index=True
357
+ DateTime,
358
+ index=True,
359
+ nullable=True,
305
360
  )
306
361
  location_code: Mapped[str] = mapped_column(String(128), index=True)
307
362
  location_name: Mapped[str] = mapped_column(String(512), index=True)
@@ -331,7 +386,9 @@ class DBPovertyRateVAT(Base):
331
386
  DateTime, primary_key=True
332
387
  )
333
388
  reference_period_end: Mapped[datetime] = mapped_column(
334
- DateTime, index=True
389
+ DateTime,
390
+ index=True,
391
+ nullable=True,
335
392
  )
336
393
  location_code: Mapped[str] = mapped_column(String(128), index=True)
337
394
  location_name: Mapped[str] = mapped_column(String(512), index=True)
@@ -345,8 +402,12 @@ class DBRefugeesVAT(Base):
345
402
  resource_hdx_id: Mapped[str] = mapped_column(String(36))
346
403
  origin_location_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
347
404
  asylum_location_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
348
- population_group: Mapped[str] = mapped_column(String(14))
349
- gender: Mapped[str] = mapped_column(String(11), primary_key=True)
405
+ population_group: Mapped[PopulationGroup] = mapped_column(
406
+ build_enum_using_values(PopulationGroup), primary_key=True
407
+ )
408
+ gender: Mapped[Gender] = mapped_column(
409
+ build_enum_using_values(Gender), primary_key=True
410
+ )
350
411
  age_range: Mapped[str] = mapped_column(String(32), primary_key=True)
351
412
  min_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
352
413
  max_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
@@ -355,7 +416,9 @@ class DBRefugeesVAT(Base):
355
416
  DateTime, primary_key=True
356
417
  )
357
418
  reference_period_end: Mapped[datetime] = mapped_column(
358
- DateTime, index=True
419
+ DateTime,
420
+ index=True,
421
+ nullable=True,
359
422
  )
360
423
  origin_location_code: Mapped[str] = mapped_column(String(128), index=True)
361
424
  origin_location_name: Mapped[str] = mapped_column(String(512), index=True)
@@ -392,7 +455,9 @@ class DBSectorVAT(Base):
392
455
  class DBWfpCommodityVAT(Base):
393
456
  __tablename__ = "wfp_commodity_vat"
394
457
  code: Mapped[str] = mapped_column(String(32), primary_key=True)
395
- category: Mapped[str] = mapped_column(String(18), index=True)
458
+ category: Mapped[CommodityCategory] = mapped_column(
459
+ build_enum_using_values(CommodityCategory), index=True
460
+ )
396
461
  name: Mapped[str] = mapped_column(String(512), index=True)
397
462
 
398
463
 
@@ -1,10 +1,10 @@
1
1
  """wfp_commodity table and view."""
2
2
 
3
- from sqlalchemy import Enum, String, select
3
+ from sqlalchemy import String, select
4
4
  from sqlalchemy.orm import Mapped, mapped_column
5
5
 
6
6
  from hapi_schema.utils.base import Base
7
- from hapi_schema.utils.enums import CommodityCategory
7
+ from hapi_schema.utils.enums import CommodityCategory, build_enum_using_values
8
8
  from hapi_schema.utils.view_params import ViewParams
9
9
 
10
10
 
@@ -13,7 +13,7 @@ class DBWFPCommodity(Base):
13
13
 
14
14
  code: Mapped[str] = mapped_column(String(32), primary_key=True)
15
15
  category: Mapped[CommodityCategory] = mapped_column(
16
- Enum(CommodityCategory), index=True
16
+ build_enum_using_values(CommodityCategory), index=True
17
17
  )
18
18
  name: Mapped[str] = mapped_column(String(512), nullable=False, index=True)
19
19
 
@@ -1,16 +1,16 @@
1
1
  from enum import Enum as PythonEnum
2
- from typing import List
2
+ from typing import List, Type
3
3
 
4
4
  from sqlalchemy import Enum as SQLAlchemyEnum
5
5
 
6
6
  """The two functions below create enums using the values rather than the keys"""
7
7
 
8
8
 
9
- def _get_list_of_values(enum_class: PythonEnum) -> List[str]:
9
+ def _get_list_of_values(enum_class: Type[PythonEnum]) -> List[str]:
10
10
  return [e.value for e in enum_class]
11
11
 
12
12
 
13
- def build_enum_using_values(enum_class: PythonEnum) -> SQLAlchemyEnum:
13
+ def build_enum_using_values(enum_class: Type[PythonEnum]) -> SQLAlchemyEnum:
14
14
  return SQLAlchemyEnum(enum_class, values_callable=_get_list_of_values)
15
15
 
16
16
 
@@ -20,8 +20,7 @@ def test_db_patch(capfd):
20
20
  patch_hash VARCHAR(48) NOT NULL,
21
21
  state VARCHAR(10) NOT NULL,
22
22
  execution_date DATETIME,
23
- PRIMARY KEY (id),
24
- UNIQUE (patch_permalink_url)
23
+ PRIMARY KEY (id)
25
24
  )
26
25
  """
27
26
  sql_patch_sequence_number_index_creation = """
@@ -112,7 +112,7 @@ def test_food_price_vat(
112
112
  expected_primary_keys = [
113
113
  "market_code",
114
114
  "commodity_code",
115
- "commodity_category",
115
+ "unit",
116
116
  "price_flag",
117
117
  "price_type",
118
118
  "reference_period_start",
@@ -192,10 +192,10 @@ def test_humanitarian_needs_vat(
192
192
  "admin2_ref",
193
193
  "gender",
194
194
  "age_range",
195
+ "sector_code",
195
196
  "population_group",
196
197
  "population_status",
197
198
  "disabled_marker",
198
- "population",
199
199
  "reference_period_start",
200
200
  ]
201
201
  expected_indexes = [
@@ -370,6 +370,7 @@ def test_refugees_vat(
370
370
  expected_primary_keys = [
371
371
  "origin_location_ref",
372
372
  "asylum_location_ref",
373
+ "population_group",
373
374
  "gender",
374
375
  "age_range",
375
376
  "reference_period_start",
File without changes
File without changes
File without changes
File without changes