hapi-schema 0.1.0__tar.gz → 0.2.0__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 (31) hide show
  1. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/.gitignore +3 -7
  2. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/PKG-INFO +3 -3
  3. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/changelog.md +14 -0
  4. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/pyproject.toml +2 -5
  5. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/requirements.txt +4 -18
  6. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/src/hapi_schema/_version.py +2 -2
  7. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/src/hapi_schema/db_admin1.py +3 -3
  8. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/src/hapi_schema/db_admin2.py +3 -3
  9. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/src/hapi_schema/db_age_range.py +3 -3
  10. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/src/hapi_schema/db_dataset.py +3 -3
  11. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/src/hapi_schema/db_gender.py +3 -3
  12. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/src/hapi_schema/db_location.py +3 -3
  13. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/src/hapi_schema/db_operational_presence.py +3 -3
  14. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/src/hapi_schema/db_org.py +3 -3
  15. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/src/hapi_schema/db_org_type.py +3 -3
  16. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/src/hapi_schema/db_population.py +3 -3
  17. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/src/hapi_schema/db_resource.py +3 -3
  18. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/src/hapi_schema/db_sector.py +3 -3
  19. hapi_schema-0.2.0/src/hapi_schema/utils/__init__.py +0 -0
  20. hapi_schema-0.2.0/src/hapi_schema/utils/base.py +8 -0
  21. hapi_schema-0.2.0/src/hapi_schema/utils/view_params.py +13 -0
  22. hapi_schema-0.1.0/src/hapi_schema/db_orgtype.py +0 -21
  23. hapi_schema-0.1.0/src/hapi_schema/view.py +0 -62
  24. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/.config/black.toml +0 -0
  25. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/.config/pre-commit-config.yaml +0 -0
  26. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/.config/ruff.toml +0 -0
  27. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/.github/workflows/publish.yaml +0 -0
  28. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/LICENSE +0 -0
  29. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/README.md +0 -0
  30. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/contributing.md +0 -0
  31. {hapi_schema-0.1.0 → hapi_schema-0.2.0}/src/hapi_schema/__init__.py +0 -0
@@ -161,13 +161,9 @@ cython_debug/
161
161
  .idea/
162
162
 
163
163
  ## Project
164
- # DB
165
- hapi.db
166
- # Version file
167
- src/hapi/pipelines/_version.py
168
164
 
169
- # Project YAML file
170
- src/hapi/pipelines/app/project_configuration.yaml
165
+ # Version file
166
+ src/hapi_schema/_version.py
171
167
 
172
- #OS Files
168
+ # OS Files
173
169
  *DS_Store
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hapi-schema
3
- Version: 0.1.0
3
+ Version: 0.2.0
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>
@@ -25,8 +25,8 @@ Classifier: Programming Language :: Python :: 3.12
25
25
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
26
  Requires-Python: >=3.8
27
27
  Requires-Dist: sqlalchemy
28
- Provides-Extra: timezones
29
- Requires-Dist: hdx-python-database; extra == 'timezones'
28
+ Provides-Extra: database
29
+ Requires-Dist: hdx-python-database>=1.2.8; extra == 'database'
30
30
  Description-Content-Type: text/markdown
31
31
 
32
32
  # hapi-sqlalchemy-schema
@@ -5,6 +5,20 @@ 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.2.0]
9
+
10
+ ### Changed
11
+
12
+ - Dependency on hdx-python-database is optional
13
+ - View definitions converted to parameter dicts
14
+
15
+ ## [0.1.1]
16
+
17
+ ### Fixed
18
+
19
+ - Compatability with `views` module moved to `hdx-python-database`
20
+ - Removed `timezone` extra which was not properly configured
21
+
8
22
  ## [0.1.0]
9
23
 
10
24
  ### Added
@@ -31,9 +31,7 @@ classifiers = [
31
31
  "Operating System :: Microsoft :: Windows",
32
32
  ]
33
33
  requires-python = ">=3.8"
34
- dependencies = [
35
- 'sqlalchemy'
36
- ]
34
+ dependencies = ['sqlalchemy']
37
35
  dynamic = ["version"]
38
36
 
39
37
  [project.readme]
@@ -44,8 +42,7 @@ content-type = "text/markdown"
44
42
  Homepage = "https://github.com/OCHA-DAP/hapi-schemas"
45
43
 
46
44
  [project.optional-dependencies]
47
- timezones = ["hdx-python-database"]
48
-
45
+ database = ["hdx-python-database>=1.2.8"]
49
46
 
50
47
  #########
51
48
  # Hatch #
@@ -4,27 +4,13 @@
4
4
  #
5
5
  # pip-compile --all-extras --output-file=requirements.txt pyproject.toml
6
6
  #
7
- bcrypt==4.0.1
8
- # via paramiko
9
- cffi==1.16.0
10
- # via
11
- # cryptography
12
- # pynacl
13
- cryptography==41.0.4
14
- # via paramiko
15
- hdx-python-database==1.2.7
7
+ greenlet==3.0.0
8
+ # via sqlalchemy
9
+ hdx-python-database==1.2.8
16
10
  # via hapi-schema (pyproject.toml)
17
- paramiko==3.3.1
18
- # via sshtunnel
19
- pycparser==2.21
20
- # via cffi
21
- pynacl==1.5.0
22
- # via paramiko
23
- sqlalchemy==2.0.21
11
+ sqlalchemy==2.0.22
24
12
  # via
25
13
  # hapi-schema (pyproject.toml)
26
14
  # hdx-python-database
27
- sshtunnel==0.4.0
28
- # via hdx-python-database
29
15
  typing-extensions==4.8.0
30
16
  # via sqlalchemy
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.1.0'
16
- __version_tuple__ = version_tuple = (0, 1, 0)
15
+ __version__ = version = '0.2.0'
16
+ __version_tuple__ = version_tuple = (0, 2, 0)
@@ -1,7 +1,6 @@
1
1
  """Admin1 table and view."""
2
2
  from datetime import datetime
3
3
 
4
- from hdx.database.no_timezone import Base
5
4
  from sqlalchemy import (
6
5
  Boolean,
7
6
  DateTime,
@@ -14,7 +13,8 @@ from sqlalchemy import (
14
13
  from sqlalchemy.orm import Mapped, mapped_column, relationship
15
14
 
16
15
  from hapi_schema.db_location import DBLocation
17
- from hapi_schema.view import view
16
+ from hapi_schema.utils.base import Base
17
+ from hapi_schema.utils.view_params import ViewParams
18
18
 
19
19
 
20
20
  class DBAdmin1(Base):
@@ -40,7 +40,7 @@ class DBAdmin1(Base):
40
40
  location = relationship("DBLocation")
41
41
 
42
42
 
43
- admin1_view = view(
43
+ view_params_admin1 = ViewParams(
44
44
  name="admin1_view",
45
45
  metadata=Base.metadata,
46
46
  selectable=select(
@@ -1,7 +1,6 @@
1
1
  """Admin2 table and view."""
2
2
  from datetime import datetime
3
3
 
4
- from hdx.database.no_timezone import Base
5
4
  from sqlalchemy import (
6
5
  Boolean,
7
6
  DateTime,
@@ -15,7 +14,8 @@ from sqlalchemy.orm import Mapped, mapped_column, relationship
15
14
 
16
15
  from hapi_schema.db_admin1 import DBAdmin1
17
16
  from hapi_schema.db_location import DBLocation
18
- from hapi_schema.view import view
17
+ from hapi_schema.utils.base import Base
18
+ from hapi_schema.utils.view_params import ViewParams
19
19
 
20
20
 
21
21
  class DBAdmin2(Base):
@@ -41,7 +41,7 @@ class DBAdmin2(Base):
41
41
  admin1 = relationship("DBAdmin1")
42
42
 
43
43
 
44
- admin2_view = view(
44
+ view_params_admin2 = ViewParams(
45
45
  name="admin2_view",
46
46
  metadata=Base.metadata,
47
47
  selectable=select(
@@ -1,10 +1,10 @@
1
1
  """Age range table and view."""
2
2
 
3
- from hdx.database.no_timezone import Base
4
3
  from sqlalchemy import Integer, String, select
5
4
  from sqlalchemy.orm import Mapped, mapped_column
6
5
 
7
- from hapi_schema.view import view
6
+ from hapi_schema.utils.base import Base
7
+ from hapi_schema.utils.view_params import ViewParams
8
8
 
9
9
 
10
10
  class DBAgeRange(Base):
@@ -15,7 +15,7 @@ class DBAgeRange(Base):
15
15
  age_max: Mapped[int] = mapped_column(Integer, nullable=True)
16
16
 
17
17
 
18
- age_range_view = view(
18
+ view_params_age_range = ViewParams(
19
19
  name="age_range_view",
20
20
  metadata=Base.metadata,
21
21
  selectable=select(*DBAgeRange.__table__.columns),
@@ -1,10 +1,10 @@
1
1
  """Dataset table and view."""
2
2
 
3
- from hdx.database.no_timezone import Base
4
3
  from sqlalchemy import Integer, String, select
5
4
  from sqlalchemy.orm import Mapped, mapped_column
6
5
 
7
- from hapi_schema.view import view
6
+ from hapi_schema.utils.base import Base
7
+ from hapi_schema.utils.view_params import ViewParams
8
8
 
9
9
 
10
10
  class DBDataset(Base):
@@ -26,7 +26,7 @@ class DBDataset(Base):
26
26
  )
27
27
 
28
28
 
29
- dataset_view = view(
29
+ view_params_dataset = ViewParams(
30
30
  name="dataset_view",
31
31
  metadata=Base.metadata,
32
32
  selectable=select(*DBDataset.__table__.columns),
@@ -1,10 +1,10 @@
1
1
  """Gender table and view."""
2
2
 
3
- from hdx.database.no_timezone import Base
4
3
  from sqlalchemy import CHAR, String, select
5
4
  from sqlalchemy.orm import Mapped, mapped_column
6
5
 
7
- from hapi_schema.view import view
6
+ from hapi_schema.utils.base import Base
7
+ from hapi_schema.utils.view_params import ViewParams
8
8
 
9
9
 
10
10
  class DBGender(Base):
@@ -14,7 +14,7 @@ class DBGender(Base):
14
14
  description: Mapped[str] = mapped_column(String(256), nullable=False)
15
15
 
16
16
 
17
- gender_view = view(
17
+ view_params_gender = ViewParams(
18
18
  name="gender_view",
19
19
  metadata=Base.metadata,
20
20
  selectable=select(*DBGender.__table__.columns),
@@ -1,11 +1,11 @@
1
1
  """Location table and view."""
2
2
  from datetime import datetime
3
3
 
4
- from hdx.database.no_timezone import Base
5
4
  from sqlalchemy import DateTime, Integer, String, select, text
6
5
  from sqlalchemy.orm import Mapped, mapped_column
7
6
 
8
- from hapi_schema.view import view
7
+ from hapi_schema.utils.base import Base
8
+ from hapi_schema.utils.view_params import ViewParams
9
9
 
10
10
 
11
11
  class DBLocation(Base):
@@ -22,7 +22,7 @@ class DBLocation(Base):
22
22
  )
23
23
 
24
24
 
25
- location_view = view(
25
+ view_params_location = ViewParams(
26
26
  name="location_view",
27
27
  metadata=Base.metadata,
28
28
  selectable=select(*DBLocation.__table__.columns),
@@ -1,7 +1,6 @@
1
1
  """OperationalPresence table and view."""
2
2
  from datetime import datetime
3
3
 
4
- from hdx.database.no_timezone import Base
5
4
  from sqlalchemy import (
6
5
  DateTime,
7
6
  ForeignKey,
@@ -20,7 +19,8 @@ from hapi_schema.db_org import DBOrg
20
19
  from hapi_schema.db_org_type import DBOrgType
21
20
  from hapi_schema.db_resource import DBResource
22
21
  from hapi_schema.db_sector import DBSector
23
- from hapi_schema.view import view
22
+ from hapi_schema.utils.base import Base
23
+ from hapi_schema.utils.view_params import ViewParams
24
24
 
25
25
 
26
26
  class DBOperationalPresence(Base):
@@ -54,7 +54,7 @@ class DBOperationalPresence(Base):
54
54
  admin2 = relationship("DBAdmin2")
55
55
 
56
56
 
57
- operational_presence_view = view(
57
+ view_params_operational_presence = ViewParams(
58
58
  name="operational_presence_view",
59
59
  metadata=Base.metadata,
60
60
  selectable=select(
@@ -1,7 +1,6 @@
1
1
  """Org table and view."""
2
2
  from datetime import datetime
3
3
 
4
- from hdx.database.no_timezone import Base
5
4
  from sqlalchemy import (
6
5
  DateTime,
7
6
  ForeignKey,
@@ -13,7 +12,8 @@ from sqlalchemy import (
13
12
  from sqlalchemy.orm import Mapped, mapped_column, relationship
14
13
 
15
14
  from hapi_schema.db_org_type import DBOrgType
16
- from hapi_schema.view import view
15
+ from hapi_schema.utils.base import Base
16
+ from hapi_schema.utils.view_params import ViewParams
17
17
 
18
18
 
19
19
  class DBOrg(Base):
@@ -36,7 +36,7 @@ class DBOrg(Base):
36
36
  org_type = relationship("DBOrgType")
37
37
 
38
38
 
39
- org_view = view(
39
+ view_params_org = ViewParams(
40
40
  name="org_view",
41
41
  metadata=Base.metadata,
42
42
  selectable=select(
@@ -1,10 +1,10 @@
1
1
  """OrgType table and view."""
2
2
 
3
- from hdx.database.no_timezone import Base
4
3
  from sqlalchemy import String, select
5
4
  from sqlalchemy.orm import Mapped, mapped_column
6
5
 
7
- from hapi_schema.view import view
6
+ from hapi_schema.utils.base import Base
7
+ from hapi_schema.utils.view_params import ViewParams
8
8
 
9
9
 
10
10
  class DBOrgType(Base):
@@ -14,7 +14,7 @@ class DBOrgType(Base):
14
14
  description: Mapped[str] = mapped_column(String(512), nullable=False)
15
15
 
16
16
 
17
- org_type_view = view(
17
+ view_params_org_type = ViewParams(
18
18
  name="org_type_view",
19
19
  metadata=Base.metadata,
20
20
  selectable=select(*DBOrgType.__table__.columns),
@@ -1,7 +1,6 @@
1
1
  """Population table and view."""
2
2
  from datetime import datetime
3
3
 
4
- from hdx.database.no_timezone import Base
5
4
  from sqlalchemy import (
6
5
  DateTime,
7
6
  ForeignKey,
@@ -19,7 +18,8 @@ from hapi_schema.db_dataset import DBDataset
19
18
  from hapi_schema.db_gender import DBGender
20
19
  from hapi_schema.db_location import DBLocation
21
20
  from hapi_schema.db_resource import DBResource
22
- from hapi_schema.view import view
21
+ from hapi_schema.utils.base import Base
22
+ from hapi_schema.utils.view_params import ViewParams
23
23
 
24
24
 
25
25
  class DBPopulation(Base):
@@ -56,7 +56,7 @@ class DBPopulation(Base):
56
56
  gender = relationship("DBGender")
57
57
 
58
58
 
59
- population_view = view(
59
+ view_params_population = ViewParams(
60
60
  name="population_view",
61
61
  metadata=Base.metadata,
62
62
  selectable=select(
@@ -1,6 +1,5 @@
1
1
  """Resource table and view."""
2
2
 
3
- from hdx.database.no_timezone import Base
4
3
  from sqlalchemy import (
5
4
  Boolean,
6
5
  DateTime,
@@ -12,7 +11,8 @@ from sqlalchemy import (
12
11
  from sqlalchemy.orm import Mapped, mapped_column, relationship
13
12
 
14
13
  from hapi_schema.db_dataset import DBDataset
15
- from hapi_schema.view import view
14
+ from hapi_schema.utils.base import Base
15
+ from hapi_schema.utils.view_params import ViewParams
16
16
 
17
17
 
18
18
  class DBResource(Base):
@@ -37,7 +37,7 @@ class DBResource(Base):
37
37
  dataset = relationship("DBDataset")
38
38
 
39
39
 
40
- resource_view = view(
40
+ view_params_resource = ViewParams(
41
41
  name="resource_view",
42
42
  metadata=Base.metadata,
43
43
  selectable=select(
@@ -1,11 +1,11 @@
1
1
  """Sector table and view."""
2
2
  from datetime import datetime
3
3
 
4
- from hdx.database.no_timezone import Base
5
4
  from sqlalchemy import DateTime, String, select, text
6
5
  from sqlalchemy.orm import Mapped, mapped_column
7
6
 
8
- from hapi_schema.view import view
7
+ from hapi_schema.utils.base import Base
8
+ from hapi_schema.utils.view_params import ViewParams
9
9
 
10
10
 
11
11
  class DBSector(Base):
@@ -21,7 +21,7 @@ class DBSector(Base):
21
21
  )
22
22
 
23
23
 
24
- sector_view = view(
24
+ view_params_sector = ViewParams(
25
25
  name="sector_view",
26
26
  metadata=Base.metadata,
27
27
  selectable=select(*DBSector.__table__.columns),
File without changes
@@ -0,0 +1,8 @@
1
+ try:
2
+ from hdx.database.no_timezone import Base
3
+
4
+ except ImportError:
5
+ from sqlalchemy.orm import DeclarativeBase
6
+
7
+ class Base(DeclarativeBase):
8
+ pass
@@ -0,0 +1,13 @@
1
+ from dataclasses import dataclass
2
+
3
+ from sqlalchemy.orm import DeclarativeMeta
4
+ from sqlalchemy.sql.expression import Selectable
5
+
6
+
7
+ @dataclass
8
+ class ViewParams:
9
+ """Class for keeping view constructor parameters."""
10
+
11
+ name: str
12
+ metadata: DeclarativeMeta
13
+ selectable: Selectable
@@ -1,21 +0,0 @@
1
- """OrgType table and view."""
2
-
3
- from hdx.database.no_timezone import Base
4
- from sqlalchemy import String, select
5
- from sqlalchemy.orm import Mapped, mapped_column
6
-
7
- from hapi_schema.view import view
8
-
9
-
10
- class DBOrgType(Base):
11
- __tablename__ = "org_type"
12
-
13
- code: Mapped[str] = mapped_column(String(32), primary_key=True)
14
- description: Mapped[str] = mapped_column(String(512), nullable=False)
15
-
16
-
17
- org_type_view = view(
18
- name="org_type_view",
19
- metadata=Base.metadata,
20
- selectable=select(*DBOrgType.__table__.columns),
21
- )
@@ -1,62 +0,0 @@
1
- """
2
- Create a DB View.
3
-
4
- Copied from:
5
- https://github.com/sqlalchemy/sqlalchemy/wiki/Views#sqlalchemy-14-20-version
6
- """
7
- import sqlalchemy as sa
8
- from sqlalchemy.ext import compiler
9
- from sqlalchemy.schema import DDLElement
10
- from sqlalchemy.sql import table
11
-
12
-
13
- class CreateView(DDLElement):
14
- def __init__(self, name, selectable):
15
- self.name = name
16
- self.selectable = selectable
17
-
18
-
19
- class DropView(DDLElement):
20
- def __init__(self, name):
21
- self.name = name
22
-
23
-
24
- @compiler.compiles(CreateView)
25
- def _create_view(element, compiler, **kw):
26
- return "CREATE VIEW %s AS %s" % (
27
- element.name,
28
- compiler.sql_compiler.process(element.selectable, literal_binds=True),
29
- )
30
-
31
-
32
- @compiler.compiles(DropView)
33
- def _drop_view(element, compiler, **kw):
34
- return "DROP VIEW %s" % (element.name)
35
-
36
-
37
- def view_exists(ddl, target, connection, **kw):
38
- return ddl.name in sa.inspect(connection).get_view_names()
39
-
40
-
41
- def view_doesnt_exist(ddl, target, connection, **kw):
42
- return not view_exists(ddl, target, connection, **kw)
43
-
44
-
45
- def view(name, metadata, selectable):
46
- t = table(name)
47
-
48
- t._columns._populate_separate_keys(
49
- col._make_proxy(t) for col in selectable.selected_columns
50
- )
51
-
52
- sa.event.listen(
53
- metadata,
54
- "after_create",
55
- CreateView(name, selectable).execute_if(callable_=view_doesnt_exist),
56
- )
57
- sa.event.listen(
58
- metadata,
59
- "before_drop",
60
- DropView(name).execute_if(callable_=view_exists),
61
- )
62
- return t
File without changes
File without changes
File without changes