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.
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/PKG-INFO +1 -1
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/changelog.md +13 -2
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/contributing.md +12 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/_version.py +2 -2
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_admin2.py +1 -1
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_ipc_type.py +1 -1
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_location.py +1 -1
- hapi_schema-0.7.1/src/hapi_schema/db_patches.py → hapi_schema-0.7.3/src/hapi_schema/db_patch.py +22 -10
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/conftest.py +3 -3
- hapi_schema-0.7.1/tests/sample_data/data_patches.py → hapi_schema-0.7.3/tests/sample_data/data_patch.py +1 -1
- hapi_schema-0.7.3/tests/test_patch.py +41 -0
- hapi_schema-0.7.1/tests/test_patches.py +0 -28
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/.config/coveragerc +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/.config/pre-commit-config.yaml +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/.config/pytest.ini +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/.config/ruff.toml +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/.github/workflows/publish.yaml +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/.github/workflows/run-python-tests.yaml +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/.gitignore +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/LICENSE +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/README.md +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/pyproject.toml +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/requirements.txt +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/__init__.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_admin1.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_age_range.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_dataset.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_food_security.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_gender.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_humanitarian_needs.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_ipc_phase.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_national_risk.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_operational_presence.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_org.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_org_type.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_population.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_population_group.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_population_status.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_resource.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/db_sector.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/utils/__init__.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/utils/base.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/src/hapi_schema/utils/view_params.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/__init__.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_admin1.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_admin2.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_age_range.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_dataset.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_food_security.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_gender.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_humanitarian_needs.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_ipc_phase.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_ipc_type.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_location.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_national_risk.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_operational_presence.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_org.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_org_type.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_population.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_population_group.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_population_status.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_resource.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/sample_data/data_sector.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_admin1.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_admin2.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_age_range.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_dataset.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_food_security.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_gender.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_humanitarian_needs.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_ipc_phase.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_ipc_type.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_location.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_national_risk.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_operational_presence.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_org.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_org_type.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_population.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_population_group.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_population_status.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_resource.py +0 -0
- {hapi_schema-0.7.1 → hapi_schema-0.7.3}/tests/test_sector.py +0 -0
|
@@ -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`
|
|
@@ -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"
|
|
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
|
-
|
|
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"
|
|
31
|
+
UniqueConstraint("code", "hapi_updated_date"),
|
|
32
32
|
)
|
|
33
33
|
|
|
34
34
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
hapi_schema-0.7.1/src/hapi_schema/db_patches.py → hapi_schema-0.7.3/src/hapi_schema/db_patch.py
RENAMED
|
@@ -1,22 +1,32 @@
|
|
|
1
|
-
"""
|
|
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
|
|
16
|
-
|
|
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(
|
|
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[
|
|
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.
|
|
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.
|
|
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(
|
|
90
|
+
session.execute(insert(DBPatch), data_patch)
|
|
91
91
|
|
|
92
92
|
session.commit()
|
|
93
93
|
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|