hapi-schema 0.7.1__tar.gz → 0.7.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 (82) hide show
  1. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/PKG-INFO +1 -1
  2. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/changelog.md +13 -2
  3. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/contributing.md +12 -0
  4. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/_version.py +2 -2
  5. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_admin2.py +1 -1
  6. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_ipc_type.py +1 -1
  7. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_location.py +1 -1
  8. hapi_schema-0.7.1/src/hapi_schema/db_patches.py → hapi_schema-0.7.3/src/hapi_schema/db_patch.py +22 -10
  9. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/conftest.py +3 -3
  10. hapi_schema-0.7.1/tests/sample_data/data_patches.py → hapi_schema-0.7.3/tests/sample_data/data_patch.py +1 -1
  11. hapi_schema-0.7.3/tests/test_patch.py +41 -0
  12. hapi_schema-0.7.1/tests/test_patches.py +0 -28
  13. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/.config/coveragerc +0 -0
  14. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/.config/pre-commit-config.yaml +0 -0
  15. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/.config/pytest.ini +0 -0
  16. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/.config/ruff.toml +0 -0
  17. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/.github/workflows/publish.yaml +0 -0
  18. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/.github/workflows/run-python-tests.yaml +0 -0
  19. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/.gitignore +0 -0
  20. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/LICENSE +0 -0
  21. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/README.md +0 -0
  22. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/pyproject.toml +0 -0
  23. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/requirements.txt +0 -0
  24. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/__init__.py +0 -0
  25. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_admin1.py +0 -0
  26. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_age_range.py +0 -0
  27. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_dataset.py +0 -0
  28. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_food_security.py +0 -0
  29. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_gender.py +0 -0
  30. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_humanitarian_needs.py +0 -0
  31. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_ipc_phase.py +0 -0
  32. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_national_risk.py +0 -0
  33. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_operational_presence.py +0 -0
  34. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_org.py +0 -0
  35. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_org_type.py +0 -0
  36. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_population.py +0 -0
  37. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_population_group.py +0 -0
  38. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_population_status.py +0 -0
  39. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_resource.py +0 -0
  40. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_sector.py +0 -0
  41. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/utils/__init__.py +0 -0
  42. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/utils/base.py +0 -0
  43. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/utils/view_params.py +0 -0
  44. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/__init__.py +0 -0
  45. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_admin1.py +0 -0
  46. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_admin2.py +0 -0
  47. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_age_range.py +0 -0
  48. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_dataset.py +0 -0
  49. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_food_security.py +0 -0
  50. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_gender.py +0 -0
  51. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_humanitarian_needs.py +0 -0
  52. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_ipc_phase.py +0 -0
  53. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_ipc_type.py +0 -0
  54. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_location.py +0 -0
  55. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_national_risk.py +0 -0
  56. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_operational_presence.py +0 -0
  57. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_org.py +0 -0
  58. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_org_type.py +0 -0
  59. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_population.py +0 -0
  60. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_population_group.py +0 -0
  61. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_population_status.py +0 -0
  62. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_resource.py +0 -0
  63. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_sector.py +0 -0
  64. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_admin1.py +0 -0
  65. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_admin2.py +0 -0
  66. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_age_range.py +0 -0
  67. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_dataset.py +0 -0
  68. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_food_security.py +0 -0
  69. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_gender.py +0 -0
  70. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_humanitarian_needs.py +0 -0
  71. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_ipc_phase.py +0 -0
  72. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_ipc_type.py +0 -0
  73. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_location.py +0 -0
  74. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_national_risk.py +0 -0
  75. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_operational_presence.py +0 -0
  76. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_org.py +0 -0
  77. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_org_type.py +0 -0
  78. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_population.py +0 -0
  79. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_population_group.py +0 -0
  80. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_population_status.py +0 -0
  81. {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_resource.py +0 -0
  82. {hapi_schema-0.7.1 → hapi_schema-0.7.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.7.1
3
+ Version: 0.7.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,14 +5,25 @@ 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.7.3]
9
+
10
+ ### Fixed
11
+
12
+ - Incorrect constraint quotes in IPC type
13
+ - Clashing unique constraint names in admins
14
+
15
+ ## [0.7.2]
16
+
17
+ ### Added
18
+
19
+ - Patches table
20
+
8
21
  ## [0.7.1]
9
22
 
10
23
  ### Changed
11
24
 
12
25
  - Removed constraint from food security
13
26
 
14
- ## [0.7.0]
15
-
16
27
  ### Added
17
28
  - Missing constraints
18
29
  - Tests on the constraints
@@ -62,3 +62,15 @@ Any changes to the dependencies will be automatically reflected in
62
62
  the file without committing by executing:
63
63
 
64
64
  pre-commit run pip-compile --all-files --config=.config/pre-commit-config.yaml
65
+
66
+ ## Adding a new table
67
+
68
+ To add a new table to the schema:
69
+
70
+ 1. Add a `db_[table_name].py` file to `src/hapi_schema` which implements the table as a class derived from `hapi_schema.utils.base.Base`
71
+ 2. Add a file `data_[table_name].py` to `tests/sample_data` which contains three rows of data for the new table as a list of dictionaries.
72
+ 3. Add the table to the `tests/conftest.py` with an import like:
73
+ `from sample_data.data_[table_name] import data_[table_name]`
74
+ and data inserted with:
75
+ `session.execute(insert(DBPatch), data_patch)`
76
+ 4. Add a test file for the new table as `tests/test_[table_name].py`
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.7.1'
16
- __version_tuple__ = version_tuple = (0, 7, 1)
15
+ __version__ = version = '0.7.3'
16
+ __version_tuple__ = version_tuple = (0, 7, 3)
@@ -32,7 +32,7 @@ class DBAdmin2(Base):
32
32
  "(hapi_replaced_date IS NULL) OR (hapi_replaced_date >= hapi_updated_date)",
33
33
  name="hapi_dates",
34
34
  ),
35
- UniqueConstraint("code", "hapi_updated_date", name="code_date_unique"),
35
+ UniqueConstraint("code", "hapi_updated_date"),
36
36
  )
37
37
 
38
38
  id: Mapped[int] = mapped_column(Integer, primary_key=True)
@@ -11,7 +11,7 @@ class DBIpcType(Base):
11
11
  __tablename__ = "ipc_type"
12
12
  __table_args__ = (
13
13
  CheckConstraint(
14
- 'code IN ("current", "first projection", "second projection")',
14
+ "code IN ('current', 'first projection', 'second projection')",
15
15
  name="ipc_phase_type",
16
16
  ),
17
17
  )
@@ -28,7 +28,7 @@ class DBLocation(Base):
28
28
  "(hapi_replaced_date IS NULL) OR (hapi_replaced_date >= hapi_updated_date)",
29
29
  name="hapi_dates",
30
30
  ),
31
- UniqueConstraint("code", "hapi_updated_date", name="code_date_unique"),
31
+ UniqueConstraint("code", "hapi_updated_date"),
32
32
  )
33
33
 
34
34
  id: Mapped[int] = mapped_column(Integer, primary_key=True)
@@ -1,22 +1,32 @@
1
- """Patches table"""
1
+ """Patch table"""
2
2
 
3
+ import enum
3
4
  from datetime import datetime
4
5
 
5
- from sqlalchemy import (
6
- DateTime,
7
- Integer,
8
- String,
9
- )
6
+ from sqlalchemy import DateTime, Enum, Integer, String
10
7
  from sqlalchemy.orm import Mapped, mapped_column
11
8
 
12
9
  from hapi_schema.utils.base import Base
13
10
 
14
11
 
15
- class DBPatches(Base):
16
- __tablename__ = "patches"
12
+ class StateEnum(str, enum.Enum):
13
+ discovered = 1
14
+ executed = 2
15
+ failed = 3
16
+ canceled = 4
17
+
18
+
19
+ class DBPatch(Base):
20
+ __tablename__ = "patch"
21
+ # __table_args__ = (
22
+ # Index(None, "patch_sequence_number"),
23
+ # Index(None, "state"),
24
+ # )
17
25
 
18
26
  id: Mapped[int] = mapped_column(Integer, primary_key=True)
19
- patch_sequence_number: Mapped[int] = mapped_column(Integer, nullable=False)
27
+ patch_sequence_number: Mapped[int] = mapped_column(
28
+ Integer, nullable=False, index=True
29
+ )
20
30
  commit_hash: Mapped[str] = mapped_column(
21
31
  String(48), unique=True, nullable=False
22
32
  )
@@ -25,7 +35,9 @@ class DBPatches(Base):
25
35
  permanent_download_url: Mapped[str] = mapped_column(
26
36
  String(1024), nullable=False, unique=True
27
37
  )
28
- state: Mapped[str] = mapped_column(String(16), nullable=False)
38
+ state: Mapped[StateEnum] = mapped_column(
39
+ Enum(StateEnum), nullable=False, index=True
40
+ )
29
41
  # discovered -> it was found in the patch repo
30
42
  # executed -> the patch was executed successfully
31
43
  # failed -> HWA tried to execute the patch but it failed (either pre-conditions
@@ -22,7 +22,7 @@ from hapi_schema.db_operational_presence import (
22
22
  )
23
23
  from hapi_schema.db_org import DBOrg
24
24
  from hapi_schema.db_org_type import DBOrgType
25
- from hapi_schema.db_patches import DBPatches
25
+ from hapi_schema.db_patch import DBPatch
26
26
  from hapi_schema.db_population import DBPopulation
27
27
  from hapi_schema.db_population_group import DBPopulationGroup
28
28
  from hapi_schema.db_population_status import DBPopulationStatus
@@ -43,7 +43,7 @@ from sample_data.data_national_risk import data_national_risk
43
43
  from sample_data.data_operational_presence import data_operational_presence
44
44
  from sample_data.data_org import data_org
45
45
  from sample_data.data_org_type import data_org_type
46
- from sample_data.data_patches import data_patches
46
+ from sample_data.data_patch import data_patch
47
47
  from sample_data.data_population import data_population
48
48
  from sample_data.data_population_group import data_population_group
49
49
  from sample_data.data_population_status import data_population_status
@@ -87,7 +87,7 @@ def engine():
87
87
  session.execute(insert(DBFoodSecurity), data_food_security)
88
88
  session.execute(insert(DBHumanitarianNeeds), data_humanitarian_needs)
89
89
 
90
- session.execute(insert(DBPatches), data_patches)
90
+ session.execute(insert(DBPatch), data_patch)
91
91
 
92
92
  session.commit()
93
93
 
@@ -1,6 +1,6 @@
1
1
  from datetime import datetime
2
2
 
3
- data_patches = [
3
+ data_patch = [
4
4
  dict(
5
5
  id=1,
6
6
  patch_sequence_number=1,
@@ -0,0 +1,41 @@
1
+ import string
2
+
3
+ from sqlalchemy import create_engine
4
+
5
+ from hapi_schema.utils.base import Base
6
+
7
+
8
+ def test_db_patch(capfd):
9
+ engine = create_engine("sqlite://", echo=True)
10
+ Base.metadata.create_all(engine)
11
+
12
+ sql_table_creation_code = """CREATE TABLE patch (
13
+ id INTEGER NOT NULL,
14
+ patch_sequence_number INTEGER NOT NULL,
15
+ commit_hash VARCHAR(48) NOT NULL,
16
+ commit_date DATETIME NOT NULL,
17
+ patch_path VARCHAR(128) NOT NULL,
18
+ permanent_download_url VARCHAR(1024) NOT NULL,
19
+ state VARCHAR(10) NOT NULL,
20
+ PRIMARY KEY (id),
21
+ UNIQUE (commit_hash),
22
+ UNIQUE (permanent_download_url)
23
+ )
24
+ """
25
+ sql_patch_sequence_number_index_creation = """
26
+ CREATE INDEX ix_patch_patch_sequence_number ON patch (patch_sequence_number)
27
+ """
28
+ sql_state_index_creation = (
29
+ """CREATE INDEX ix_patch_state ON patch (state)"""
30
+ )
31
+
32
+ captured_sql, _ = capfd.readouterr()
33
+
34
+ for sql_statements in [
35
+ sql_table_creation_code,
36
+ sql_patch_sequence_number_index_creation,
37
+ sql_state_index_creation,
38
+ ]:
39
+ assert sql_statements.translate(
40
+ str.maketrans("", "", string.whitespace)
41
+ ) in captured_sql.translate(str.maketrans("", "", string.whitespace))
@@ -1,28 +0,0 @@
1
- import string
2
-
3
- from sqlalchemy import create_engine
4
-
5
- from hapi_schema.utils.base import Base
6
-
7
-
8
- def test_db_patches(capfd):
9
- engine = create_engine("sqlite://", echo=True)
10
- Base.metadata.create_all(engine)
11
-
12
- sql_table_creation_code = """CREATE TABLE patches (
13
- id INTEGER NOT NULL,
14
- patch_sequence_number INTEGER NOT NULL,
15
- commit_hash VARCHAR(48) NOT NULL,
16
- commit_date DATETIME NOT NULL,
17
- patch_path VARCHAR(128) NOT NULL,
18
- permanent_download_url VARCHAR(1024) NOT NULL,
19
- state VARCHAR(16) NOT NULL,
20
- PRIMARY KEY (id),
21
- UNIQUE (commit_hash),
22
- UNIQUE (permanent_download_url)
23
- )
24
- """
25
- captured_sql, _ = capfd.readouterr()
26
- assert sql_table_creation_code.translate(
27
- str.maketrans("", "", string.whitespace)
28
- ) in captured_sql.translate(str.maketrans("", "", string.whitespace))
File without changes
File without changes
File without changes
File without changes