hapi-schema 0.8.8__tar.gz → 0.8.9__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.9}/PKG-INFO +1 -1
  2. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/changelog.md +18 -8
  3. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/_version.py +2 -2
  4. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_food_price.py +7 -4
  5. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_food_security.py +5 -4
  6. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_humanitarian_needs.py +7 -5
  7. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_national_risk.py +2 -3
  8. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_population.py +4 -3
  9. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_refugees.py +9 -4
  10. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_wfp_commodity.py +3 -3
  11. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/utils/enums.py +3 -3
  12. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/.config/coveragerc +0 -0
  13. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/.config/pre-commit-config.yaml +0 -0
  14. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/.config/pytest.ini +0 -0
  15. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/.config/ruff.toml +0 -0
  16. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/.github/workflows/publish.yaml +0 -0
  17. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/.github/workflows/run-python-tests.yaml +0 -0
  18. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/.gitignore +0 -0
  19. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/LICENSE +0 -0
  20. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/README.md +0 -0
  21. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/contributing.md +0 -0
  22. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/docker/docker-compose.yml +0 -0
  23. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/initialize_test_db.sh +0 -0
  24. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/pyproject.toml +0 -0
  25. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/requirements.txt +0 -0
  26. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/__init__.py +0 -0
  27. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_admin1.py +0 -0
  28. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_admin2.py +0 -0
  29. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_conflict_event.py +0 -0
  30. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_currency.py +0 -0
  31. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_dataset.py +0 -0
  32. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_funding.py +0 -0
  33. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_location.py +0 -0
  34. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_operational_presence.py +0 -0
  35. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_org.py +0 -0
  36. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_org_type.py +0 -0
  37. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_patch.py +0 -0
  38. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_poverty_rate.py +0 -0
  39. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_resource.py +0 -0
  40. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_sector.py +0 -0
  41. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_views_as_tables.py +0 -0
  42. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/db_wfp_market.py +0 -0
  43. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/utils/__init__.py +0 -0
  44. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/utils/base.py +0 -0
  45. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/utils/constraints.py +0 -0
  46. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/utils/hapi_views_code_generator.py +0 -0
  47. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/utils/view_as_table_code_generator.py +0 -0
  48. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/utils/view_as_table_definitions.toml +0 -0
  49. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/utils/view_params.py +0 -0
  50. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/src/hapi_schema/views.py +0 -0
  51. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/conftest.py +0 -0
  52. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/__init__.py +0 -0
  53. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_admin1.py +0 -0
  54. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_admin2.py +0 -0
  55. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_conflict_event.py +0 -0
  56. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_currency.py +0 -0
  57. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_dataset.py +0 -0
  58. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_food_price.py +0 -0
  59. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_food_security.py +0 -0
  60. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_funding.py +0 -0
  61. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_humanitarian_needs.py +0 -0
  62. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_location.py +0 -0
  63. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_national_risk.py +0 -0
  64. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_operational_presence.py +0 -0
  65. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_org.py +0 -0
  66. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_org_type.py +0 -0
  67. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_patch.py +0 -0
  68. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_population.py +0 -0
  69. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_poverty_rate.py +0 -0
  70. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_refugees.py +0 -0
  71. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_resource.py +0 -0
  72. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_sector.py +0 -0
  73. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_wfp_commodity.py +0 -0
  74. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/sample_data/data_wfp_market.py +0 -0
  75. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_admin1.py +0 -0
  76. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_admin2.py +0 -0
  77. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_conflict_event.py +0 -0
  78. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_currency.py +0 -0
  79. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_dataset.py +0 -0
  80. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_food_price.py +0 -0
  81. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_food_security.py +0 -0
  82. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_funding.py +0 -0
  83. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_humanitarian_needs.py +0 -0
  84. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_location.py +0 -0
  85. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_national_risk.py +0 -0
  86. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_operational_presence.py +0 -0
  87. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_org.py +0 -0
  88. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_org_type.py +0 -0
  89. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_patch.py +0 -0
  90. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_population.py +0 -0
  91. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_poverty_rate.py +0 -0
  92. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_refugees.py +0 -0
  93. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_resource.py +0 -0
  94. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_sector.py +0 -0
  95. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_views_as_tables.py +0 -0
  96. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/tests/test_wfp_commodity.py +0 -0
  97. {hapi_schema-0.8.8 → hapi_schema-0.8.9}/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.9
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,9 +5,15 @@ 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.9
9
+
10
+ ### Fixed
11
+
12
+ - Some enums missing built from values
13
+
8
14
  ## 0.8.8
9
15
 
10
- ### Changes
16
+ ### Changed
11
17
 
12
18
  - Rewrite enums to use values rather than variable names
13
19
  - Switch from "*" to "all" for rollup in enums
@@ -16,12 +22,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
16
22
 
17
23
  ## 0.8.7
18
24
 
19
- ## Changes
25
+ ### Changed
26
+
20
27
  - Add unit to food\_price table primary key
21
28
 
22
29
  ## 0.8.6
23
30
 
24
- ## Changes
31
+ ### Changed
32
+
25
33
  - Added food\_price view as tables by updating the toml parameter file
26
34
  - Updated poverty\_rate view as table
27
35
  - Updated operational\_presence view as table by updating the toml parameter file
@@ -29,11 +37,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
29
37
 
30
38
  ## 0.8.5
31
39
 
32
- ## Changes
40
+ ### Changed
41
+
33
42
  - refactor DBPovertyRate to wide instead of narrow
34
43
  - added org\_type\_description to operational\_presence\_view
35
44
 
36
45
  ## Removed
46
+
37
47
  - rate\_constraint and `PovertyClassification` enum
38
48
 
39
49
  ## 0.8.4
@@ -42,7 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
42
52
 
43
53
  - New constraints: rate\_constraint
44
54
 
45
- ### CHanged
55
+ ### Changed
46
56
 
47
57
  - refactor DBPovertyRate to track rates rather than population, and link to
48
58
  location (with admin1\_name as a text field)
@@ -60,19 +70,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
60
70
  Miscellaneous fixes for pipelines
61
71
 
62
72
  ### Changed
63
- - added from\_cods column to location, admin1, and admin2
64
73
 
74
+ - added from\_cods column to location, admin1, and admin2
65
75
 
66
76
  ## 0.8.1
67
77
 
68
78
  Implemented the Food Prices subcategory.
69
79
 
70
80
  ### Added
81
+
71
82
  - New tables and views: food\_price, wfp\_commodity, wfp\_market, currency
72
83
  - New enums: PriceFlag, PriceType, CommodityCategory
73
84
  - New constraints: non\_negative\_constraint, latlon\_constraint
74
85
 
75
-
76
86
  ## 0.8.0
77
87
 
78
88
  ### Changed
@@ -85,6 +95,7 @@ Implemented the Food Prices subcategory.
85
95
  - Programmatically obtain views
86
96
 
87
97
  ### Added
98
+
88
99
  - New tables: humanitarian\_needs, funding, refugees, conflict\_event, poverty\_rate
89
100
  - New enums: Gender, DisabledMarker, EventType, PopulationGroup, PopulationStatus, IPCPhase, PovertyClassification, IPCType, and RiskClass
90
101
  - Generalized constraints
@@ -93,7 +104,6 @@ Implemented the Food Prices subcategory.
93
104
 
94
105
  - ipc\_phase, ipc\_type, age\_range, and gender tables
95
106
 
96
-
97
107
  ## [0.7.3]
98
108
 
99
109
  ### 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.9'
16
+ __version_tuple__ = version_tuple = (0, 8, 9)
@@ -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)
@@ -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)
@@ -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
 
File without changes
File without changes
File without changes
File without changes
File without changes