hdx-python-database 1.3.6__tar.gz → 1.3.7__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.
- hdx_python_database-1.3.6/.config/pre-commit-config.yaml → hdx_python_database-1.3.7/.pre-commit-config.yaml +5 -6
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/PKG-INFO +4 -2
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/documentation/mkdocs.yaml +3 -1
- hdx_python_database-1.3.7/hatch.toml +34 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/pyproject.toml +2 -48
- {hdx_python_database-1.3.6/.config → hdx_python_database-1.3.7}/pytest.ini +1 -1
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/requirements.txt +35 -42
- {hdx_python_database-1.3.6/.config → hdx_python_database-1.3.7}/ruff.toml +0 -1
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/src/hdx/database/_version.py +2 -2
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/src/hdx/database/database.py +24 -6
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/src/hdx/database/postgresql.py +13 -2
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/src/hdx/database/utils.py +1 -3
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/tests/hdx/database/test_database.py +1 -3
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/tests/hdx/database/test_dburi.py +4 -12
- hdx_python_database-1.3.6/tests/hdx/database/test_recreate.py → hdx_python_database-1.3.7/tests/hdx/database/test_drop_recreate.py +7 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/tests/hdx/database/test_ssh.py +1 -3
- /hdx_python_database-1.3.6/.config/coveragerc → /hdx_python_database-1.3.7/.coveragerc +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/.github/workflows/publish.yaml +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/.github/workflows/run-python-tests.yaml +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/.gitignore +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/CONTRIBUTING.md +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/LICENSE +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/README.md +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/documentation/.readthedocs.yaml +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/documentation/index.md +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/src/hdx/database/__init__.py +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/src/hdx/database/dburi.py +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/src/hdx/database/no_timezone.py +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/src/hdx/database/views.py +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/src/hdx/database/with_timezone.py +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/tests/fixtures/test.db +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/tests/hdx/database/__init__.py +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/tests/hdx/database/conftest.py +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/tests/hdx/database/dbtestdate.py +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/tests/hdx/database/test_postgresql.py +0 -0
- {hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/tests/hdx/database/test_reflect.py +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
default_language_version:
|
|
2
|
-
python: python3.
|
|
2
|
+
python: python3.13
|
|
3
3
|
repos:
|
|
4
4
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
5
5
|
rev: v5.0.0
|
|
@@ -8,16 +8,15 @@ repos:
|
|
|
8
8
|
- id: end-of-file-fixer
|
|
9
9
|
- id: check-ast
|
|
10
10
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
11
|
-
rev: v0.
|
|
11
|
+
rev: v0.12.0
|
|
12
12
|
hooks:
|
|
13
13
|
# Run the linter.
|
|
14
|
-
- id: ruff
|
|
15
|
-
args: [
|
|
14
|
+
- id: ruff-check
|
|
15
|
+
args: [ --fix ]
|
|
16
16
|
# Run the formatter.
|
|
17
17
|
- id: ruff-format
|
|
18
|
-
args: [--config, .config/ruff.toml]
|
|
19
18
|
- repo: https://github.com/astral-sh/uv-pre-commit
|
|
20
|
-
rev: 0.
|
|
19
|
+
rev: 0.7.14
|
|
21
20
|
hooks:
|
|
22
21
|
# Run the pip compile
|
|
23
22
|
- id: pip-compile
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hdx-python-database
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.7
|
|
4
4
|
Summary: HDX Python database utilities
|
|
5
5
|
Project-URL: Homepage, https://github.com/OCHA-DAP/hdx-python-database
|
|
6
6
|
Author-email: Michael Rans <rans@email.com>
|
|
@@ -24,7 +24,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
24
24
|
Classifier: Programming Language :: Python :: 3.11
|
|
25
25
|
Classifier: Programming Language :: Python :: 3.12
|
|
26
26
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
-
Requires-Python: >=3.
|
|
27
|
+
Requires-Python: >=3.10
|
|
28
28
|
Requires-Dist: sqlalchemy>=2
|
|
29
29
|
Provides-Extra: dev
|
|
30
30
|
Requires-Dist: pre-commit; extra == 'dev'
|
|
@@ -35,8 +35,10 @@ Requires-Dist: psycopg[binary]; extra == 'postgresql'
|
|
|
35
35
|
Provides-Extra: sshtunnel
|
|
36
36
|
Requires-Dist: sshtunnel; extra == 'sshtunnel'
|
|
37
37
|
Provides-Extra: test
|
|
38
|
+
Requires-Dist: psycopg[binary]; extra == 'test'
|
|
38
39
|
Requires-Dist: pytest; extra == 'test'
|
|
39
40
|
Requires-Dist: pytest-cov; extra == 'test'
|
|
41
|
+
Requires-Dist: sshtunnel; extra == 'test'
|
|
40
42
|
Description-Content-Type: text/markdown
|
|
41
43
|
|
|
42
44
|
[](https://github.com/OCHA-DAP/hdx-python-database/actions/workflows/run-python-tests.yaml)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Build
|
|
2
|
+
|
|
3
|
+
[build.targets.wheel]
|
|
4
|
+
packages = ["src/hdx"]
|
|
5
|
+
|
|
6
|
+
[build.hooks.vcs]
|
|
7
|
+
version-file = "src/hdx/database/_version.py"
|
|
8
|
+
|
|
9
|
+
# Versioning
|
|
10
|
+
|
|
11
|
+
[version]
|
|
12
|
+
source = "vcs"
|
|
13
|
+
|
|
14
|
+
[version.raw-options]
|
|
15
|
+
local_scheme = "no-local-version"
|
|
16
|
+
version_scheme = "python-simplified-semver"
|
|
17
|
+
|
|
18
|
+
# Tests
|
|
19
|
+
|
|
20
|
+
[envs.hatch-test]
|
|
21
|
+
features = ["test"]
|
|
22
|
+
|
|
23
|
+
[[envs.hatch-test.matrix]]
|
|
24
|
+
python = ["3.13"]
|
|
25
|
+
|
|
26
|
+
[envs.hatch-test.scripts]
|
|
27
|
+
run = """
|
|
28
|
+
pytest --rootdir=. --junitxml=test-results.xml --cov --no-cov-on-fail \
|
|
29
|
+
--cov-report=lcov --cov-report=term-missing
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
[envs.hatch-static-analysis]
|
|
33
|
+
config-path = "none"
|
|
34
|
+
dependencies = ["ruff==0.12.0"]
|
|
@@ -31,7 +31,7 @@ classifiers = [
|
|
|
31
31
|
"Operating System :: MacOS",
|
|
32
32
|
"Operating System :: Microsoft :: Windows",
|
|
33
33
|
]
|
|
34
|
-
requires-python = ">=3.
|
|
34
|
+
requires-python = ">=3.10"
|
|
35
35
|
|
|
36
36
|
dependencies = [
|
|
37
37
|
"sqlalchemy>=2",
|
|
@@ -48,52 +48,6 @@ Homepage = "https://github.com/OCHA-DAP/hdx-python-database"
|
|
|
48
48
|
[project.optional-dependencies]
|
|
49
49
|
sshtunnel = ["sshtunnel"]
|
|
50
50
|
postgresql = ["psycopg[binary]"]
|
|
51
|
-
test = ["pytest", "pytest-cov"]
|
|
51
|
+
test = ["sshtunnel", "psycopg[binary]", "pytest", "pytest-cov"]
|
|
52
52
|
dev = ["pre-commit"]
|
|
53
53
|
docs = ["mkapi"]
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
#########
|
|
57
|
-
# Hatch #
|
|
58
|
-
#########
|
|
59
|
-
|
|
60
|
-
# Build
|
|
61
|
-
|
|
62
|
-
[tool.hatch.build.targets.wheel]
|
|
63
|
-
packages = ["src/hdx"]
|
|
64
|
-
|
|
65
|
-
[tool.hatch.build.hooks.vcs]
|
|
66
|
-
version-file = "src/hdx/database/_version.py"
|
|
67
|
-
|
|
68
|
-
# Versioning
|
|
69
|
-
|
|
70
|
-
[tool.hatch.version]
|
|
71
|
-
source = "vcs"
|
|
72
|
-
|
|
73
|
-
[tool.hatch.version.raw-options]
|
|
74
|
-
local_scheme = "no-local-version"
|
|
75
|
-
version_scheme = "python-simplified-semver"
|
|
76
|
-
|
|
77
|
-
# Tests
|
|
78
|
-
|
|
79
|
-
[tool.hatch.envs.hatch-test]
|
|
80
|
-
features = ["sshtunnel", "postgresql", "test"]
|
|
81
|
-
|
|
82
|
-
[[tool.hatch.envs.hatch-test.matrix]]
|
|
83
|
-
python = ["3.12"]
|
|
84
|
-
|
|
85
|
-
[tool.hatch.envs.hatch-test.scripts]
|
|
86
|
-
run = """
|
|
87
|
-
pytest -c .config/pytest.ini --rootdir=. --junitxml=test-results.xml \
|
|
88
|
-
--cov --cov-config=.config/coveragerc --no-cov-on-fail \
|
|
89
|
-
--cov-report=lcov --cov-report=term-missing
|
|
90
|
-
"""
|
|
91
|
-
|
|
92
|
-
[tool.hatch.envs.hatch-static-analysis]
|
|
93
|
-
dependencies = ["ruff==0.9.10"]
|
|
94
|
-
|
|
95
|
-
[tool.hatch.envs.hatch-static-analysis.scripts]
|
|
96
|
-
format-check = ["ruff format --config .config/ruff.toml --check --diff {args:.}",]
|
|
97
|
-
format-fix = ["ruff format --config .config/ruff.toml {args:.}",]
|
|
98
|
-
lint-check = ["ruff check --config .config/ruff.toml {args:.}",]
|
|
99
|
-
lint-fix = ["ruff check --config .config/ruff.toml --fix {args:.}",]
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# This file was autogenerated by uv via the following command:
|
|
2
2
|
# uv pip compile pyproject.toml --resolver=backtracking --all-extras -o requirements.txt
|
|
3
|
-
astdoc==1.
|
|
3
|
+
astdoc==1.3.0
|
|
4
4
|
# via mkapi
|
|
5
5
|
babel==2.17.0
|
|
6
6
|
# via mkdocs-material
|
|
7
|
-
backrefs==5.
|
|
7
|
+
backrefs==5.9
|
|
8
8
|
# via mkdocs-material
|
|
9
9
|
bcrypt==4.3.0
|
|
10
10
|
# via paramiko
|
|
11
|
-
certifi==2025.
|
|
11
|
+
certifi==2025.7.14
|
|
12
12
|
# via requests
|
|
13
13
|
cffi==1.17.1
|
|
14
14
|
# via
|
|
@@ -16,54 +16,49 @@ cffi==1.17.1
|
|
|
16
16
|
# pynacl
|
|
17
17
|
cfgv==3.4.0
|
|
18
18
|
# via pre-commit
|
|
19
|
-
charset-normalizer==3.4.
|
|
19
|
+
charset-normalizer==3.4.2
|
|
20
20
|
# via requests
|
|
21
|
-
click==8.1
|
|
21
|
+
click==8.2.1
|
|
22
22
|
# via mkdocs
|
|
23
23
|
colorama==0.4.6
|
|
24
24
|
# via mkdocs-material
|
|
25
|
-
coverage==7.
|
|
25
|
+
coverage==7.9.2
|
|
26
26
|
# via pytest-cov
|
|
27
|
-
cryptography==
|
|
27
|
+
cryptography==45.0.5
|
|
28
28
|
# via paramiko
|
|
29
|
-
distlib==0.
|
|
29
|
+
distlib==0.4.0
|
|
30
30
|
# via virtualenv
|
|
31
31
|
filelock==3.18.0
|
|
32
32
|
# via virtualenv
|
|
33
33
|
ghp-import==2.1.0
|
|
34
34
|
# via mkdocs
|
|
35
|
-
greenlet==3.
|
|
35
|
+
greenlet==3.2.3
|
|
36
36
|
# via sqlalchemy
|
|
37
|
-
identify==2.6.
|
|
37
|
+
identify==2.6.12
|
|
38
38
|
# via pre-commit
|
|
39
39
|
idna==3.10
|
|
40
40
|
# via requests
|
|
41
|
-
iniconfig==2.
|
|
41
|
+
iniconfig==2.1.0
|
|
42
42
|
# via pytest
|
|
43
43
|
jinja2==3.1.6
|
|
44
44
|
# via
|
|
45
45
|
# mkapi
|
|
46
46
|
# mkdocs
|
|
47
47
|
# mkdocs-material
|
|
48
|
-
markdown==3.
|
|
48
|
+
markdown==3.8.2
|
|
49
49
|
# via
|
|
50
|
-
# astdoc
|
|
51
50
|
# mkdocs
|
|
52
51
|
# mkdocs-material
|
|
53
52
|
# pymdown-extensions
|
|
54
|
-
markdown-it-py==3.0.0
|
|
55
|
-
# via rich
|
|
56
53
|
markupsafe==3.0.2
|
|
57
54
|
# via
|
|
58
55
|
# jinja2
|
|
59
56
|
# mkdocs
|
|
60
|
-
mdurl==0.1.2
|
|
61
|
-
# via markdown-it-py
|
|
62
57
|
mergedeep==1.3.4
|
|
63
58
|
# via
|
|
64
59
|
# mkdocs
|
|
65
60
|
# mkdocs-get-deps
|
|
66
|
-
mkapi==4.
|
|
61
|
+
mkapi==4.4.4
|
|
67
62
|
# via hdx-python-database (pyproject.toml)
|
|
68
63
|
mkdocs==1.6.1
|
|
69
64
|
# via
|
|
@@ -71,13 +66,13 @@ mkdocs==1.6.1
|
|
|
71
66
|
# mkdocs-material
|
|
72
67
|
mkdocs-get-deps==0.2.0
|
|
73
68
|
# via mkdocs
|
|
74
|
-
mkdocs-material==9.6.
|
|
69
|
+
mkdocs-material==9.6.15
|
|
75
70
|
# via mkapi
|
|
76
71
|
mkdocs-material-extensions==1.3.1
|
|
77
72
|
# via mkdocs-material
|
|
78
73
|
nodeenv==1.9.1
|
|
79
74
|
# via pre-commit
|
|
80
|
-
packaging==
|
|
75
|
+
packaging==25.0
|
|
81
76
|
# via
|
|
82
77
|
# mkdocs
|
|
83
78
|
# pytest
|
|
@@ -87,33 +82,35 @@ paramiko==3.5.1
|
|
|
87
82
|
# via sshtunnel
|
|
88
83
|
pathspec==0.12.1
|
|
89
84
|
# via mkdocs
|
|
90
|
-
platformdirs==4.3.
|
|
85
|
+
platformdirs==4.3.8
|
|
91
86
|
# via
|
|
92
87
|
# mkdocs-get-deps
|
|
93
88
|
# virtualenv
|
|
94
|
-
pluggy==1.
|
|
95
|
-
# via
|
|
96
|
-
|
|
89
|
+
pluggy==1.6.0
|
|
90
|
+
# via
|
|
91
|
+
# pytest
|
|
92
|
+
# pytest-cov
|
|
93
|
+
pre-commit==4.2.0
|
|
97
94
|
# via hdx-python-database (pyproject.toml)
|
|
98
|
-
psycopg==3.2.
|
|
95
|
+
psycopg==3.2.9
|
|
99
96
|
# via hdx-python-database (pyproject.toml)
|
|
100
|
-
psycopg-binary==3.2.
|
|
97
|
+
psycopg-binary==3.2.9
|
|
101
98
|
# via psycopg
|
|
102
99
|
pycparser==2.22
|
|
103
100
|
# via cffi
|
|
104
|
-
pygments==2.19.
|
|
101
|
+
pygments==2.19.2
|
|
105
102
|
# via
|
|
106
103
|
# mkdocs-material
|
|
107
|
-
#
|
|
108
|
-
pymdown-extensions==10.
|
|
104
|
+
# pytest
|
|
105
|
+
pymdown-extensions==10.16
|
|
109
106
|
# via mkdocs-material
|
|
110
107
|
pynacl==1.5.0
|
|
111
108
|
# via paramiko
|
|
112
|
-
pytest==8.
|
|
109
|
+
pytest==8.4.1
|
|
113
110
|
# via
|
|
114
111
|
# hdx-python-database (pyproject.toml)
|
|
115
112
|
# pytest-cov
|
|
116
|
-
pytest-cov==6.
|
|
113
|
+
pytest-cov==6.2.1
|
|
117
114
|
# via hdx-python-database (pyproject.toml)
|
|
118
115
|
python-dateutil==2.9.0.post0
|
|
119
116
|
# via ghp-import
|
|
@@ -124,25 +121,21 @@ pyyaml==6.0.2
|
|
|
124
121
|
# pre-commit
|
|
125
122
|
# pymdown-extensions
|
|
126
123
|
# pyyaml-env-tag
|
|
127
|
-
pyyaml-env-tag==
|
|
124
|
+
pyyaml-env-tag==1.1
|
|
128
125
|
# via mkdocs
|
|
129
|
-
requests==2.32.
|
|
126
|
+
requests==2.32.4
|
|
130
127
|
# via mkdocs-material
|
|
131
|
-
rich==13.9.4
|
|
132
|
-
# via mkapi
|
|
133
128
|
six==1.17.0
|
|
134
129
|
# via python-dateutil
|
|
135
|
-
sqlalchemy==2.0.
|
|
130
|
+
sqlalchemy==2.0.41
|
|
136
131
|
# via hdx-python-database (pyproject.toml)
|
|
137
132
|
sshtunnel==0.4.0
|
|
138
133
|
# via hdx-python-database (pyproject.toml)
|
|
139
|
-
typing-extensions==4.
|
|
140
|
-
# via
|
|
141
|
-
|
|
142
|
-
# sqlalchemy
|
|
143
|
-
urllib3==2.3.0
|
|
134
|
+
typing-extensions==4.14.1
|
|
135
|
+
# via sqlalchemy
|
|
136
|
+
urllib3==2.5.0
|
|
144
137
|
# via requests
|
|
145
|
-
virtualenv==20.
|
|
138
|
+
virtualenv==20.32.0
|
|
146
139
|
# via pre-commit
|
|
147
140
|
watchdog==6.0.0
|
|
148
141
|
# via mkdocs
|
|
@@ -281,17 +281,15 @@ class Database:
|
|
|
281
281
|
engine = create_engine(db_uri, poolclass=NullPool, echo=False)
|
|
282
282
|
if reflect:
|
|
283
283
|
Base = automap_base(declarative_base=table_base)
|
|
284
|
-
Base.prepare(
|
|
285
|
-
autoload_with=engine, reflection_options={"views": True}
|
|
286
|
-
)
|
|
284
|
+
Base.prepare(autoload_with=engine, reflection_options={"views": True})
|
|
287
285
|
table_base = Base
|
|
288
286
|
else:
|
|
289
287
|
table_base.metadata.create_all(engine)
|
|
290
288
|
return Session(engine), table_base
|
|
291
289
|
|
|
292
290
|
@staticmethod
|
|
293
|
-
def
|
|
294
|
-
"""Wipe
|
|
291
|
+
def drop_schema(engine: Engine, schema_name: str = "public") -> bool:
|
|
292
|
+
"""Wipe schema in database using SQLAlchemy.
|
|
295
293
|
|
|
296
294
|
Args:
|
|
297
295
|
engine (Engine): SQLAlchemy engine to use.
|
|
@@ -307,10 +305,30 @@ class Database:
|
|
|
307
305
|
DropSchema(schema_name, cascade=True, if_exists=True)
|
|
308
306
|
)
|
|
309
307
|
connection.commit()
|
|
308
|
+
return True
|
|
309
|
+
except SQLAlchemyError:
|
|
310
|
+
return False
|
|
311
|
+
|
|
312
|
+
@staticmethod
|
|
313
|
+
def recreate_schema(engine: Engine, schema_name: str = "public") -> bool:
|
|
314
|
+
"""Wipe and create empty schema in database using SQLAlchemy.
|
|
315
|
+
|
|
316
|
+
Args:
|
|
317
|
+
engine (Engine): SQLAlchemy engine to use.
|
|
318
|
+
schema_name (str): Schema name. Defaults to "public".
|
|
319
|
+
|
|
320
|
+
Returns:
|
|
321
|
+
bool: True if all successful, False if not
|
|
322
|
+
"""
|
|
323
|
+
# Wipe and create an empty schema
|
|
324
|
+
try:
|
|
325
|
+
with engine.connect() as connection:
|
|
310
326
|
connection.execute(
|
|
311
|
-
|
|
327
|
+
DropSchema(schema_name, cascade=True, if_exists=True)
|
|
312
328
|
)
|
|
313
329
|
connection.commit()
|
|
330
|
+
connection.execute(CreateSchema(schema_name, if_not_exists=True))
|
|
331
|
+
connection.commit()
|
|
314
332
|
return True
|
|
315
333
|
except SQLAlchemyError:
|
|
316
334
|
return False
|
|
@@ -59,6 +59,12 @@ def restore_from_pgfile(db_uri: str, pg_restore_file: str) -> str:
|
|
|
59
59
|
str: Output from the pg_restore command
|
|
60
60
|
"""
|
|
61
61
|
db_params = get_params_from_connection_uri(db_uri)
|
|
62
|
+
if pg_restore_file[-3:] == ".xz":
|
|
63
|
+
decompress = subprocess.Popen(
|
|
64
|
+
("unxz", "-c", "-d", pg_restore_file), stdout=subprocess.PIPE
|
|
65
|
+
).stdout
|
|
66
|
+
else:
|
|
67
|
+
decompress = None
|
|
62
68
|
subprocess_params = ["pg_restore", "-c"]
|
|
63
69
|
for key, value in db_params.items():
|
|
64
70
|
match key:
|
|
@@ -74,13 +80,18 @@ def restore_from_pgfile(db_uri: str, pg_restore_file: str) -> str:
|
|
|
74
80
|
continue
|
|
75
81
|
subprocess_params.append(f"{value}")
|
|
76
82
|
|
|
77
|
-
|
|
83
|
+
if not decompress:
|
|
84
|
+
subprocess_params.append(pg_restore_file)
|
|
78
85
|
env = environ.copy()
|
|
79
86
|
password = db_params.get("password")
|
|
80
87
|
if password:
|
|
81
88
|
env["PGPASSWORD"] = password
|
|
82
89
|
process = subprocess.run(
|
|
83
|
-
subprocess_params,
|
|
90
|
+
subprocess_params,
|
|
91
|
+
env=env,
|
|
92
|
+
capture_output=True,
|
|
93
|
+
encoding="utf-8",
|
|
94
|
+
stdin=decompress,
|
|
84
95
|
)
|
|
85
96
|
try:
|
|
86
97
|
process.check_returncode()
|
|
@@ -13,7 +13,5 @@ def camel_to_snake_case(string: str) -> str:
|
|
|
13
13
|
Returns:
|
|
14
14
|
str: String in snake case
|
|
15
15
|
"""
|
|
16
|
-
string = re.sub(
|
|
17
|
-
r"((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))", r"_\1", string
|
|
18
|
-
)
|
|
16
|
+
string = re.sub(r"((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))", r"_\1", string)
|
|
19
17
|
return string.lower().lstrip("_")
|
|
@@ -45,9 +45,7 @@ class TestDatabase:
|
|
|
45
45
|
now = datetime(2023, 10, 20, 22, 35, 55, tzinfo=timezone.utc)
|
|
46
46
|
rows = [{"test_date": now}]
|
|
47
47
|
dbdatabase.batch_populate(rows, DBTestDate)
|
|
48
|
-
dbtestdate = (
|
|
49
|
-
dbsession.execute(select(DBTestDate)).all()[1][0].test_date
|
|
50
|
-
)
|
|
48
|
+
dbtestdate = dbsession.execute(select(DBTestDate)).all()[1][0].test_date
|
|
51
49
|
assert dbtestdate == now
|
|
52
50
|
|
|
53
51
|
remove(dbpath)
|
|
@@ -17,9 +17,7 @@ class TestDBURI:
|
|
|
17
17
|
"dialect": "postgresql",
|
|
18
18
|
"driver": "psycopg",
|
|
19
19
|
}
|
|
20
|
-
connection_uri_pg =
|
|
21
|
-
"postgresql+psycopg://myuser:mypass@myserver:1234/mydatabase"
|
|
22
|
-
)
|
|
20
|
+
connection_uri_pg = "postgresql+psycopg://myuser:mypass@myserver:1234/mydatabase"
|
|
23
21
|
params_pg_no_driver = {
|
|
24
22
|
"database": "mydatabase",
|
|
25
23
|
"host": "myserver",
|
|
@@ -37,9 +35,7 @@ class TestDBURI:
|
|
|
37
35
|
"dialect": "postgresql",
|
|
38
36
|
"driver": None,
|
|
39
37
|
}
|
|
40
|
-
connection_uri_pg_no_driver =
|
|
41
|
-
"postgresql://myuser:mypass@myserver:1234/mydatabase"
|
|
42
|
-
)
|
|
38
|
+
connection_uri_pg_no_driver = "postgresql://myuser:mypass@myserver:1234/mydatabase"
|
|
43
39
|
params_sq_no_driver = {
|
|
44
40
|
"database": "mydatabase",
|
|
45
41
|
"host": "myserver",
|
|
@@ -67,9 +63,7 @@ class TestDBURI:
|
|
|
67
63
|
include_driver=False,
|
|
68
64
|
)
|
|
69
65
|
assert result == TestDBURI.params_pg_no_driver
|
|
70
|
-
result = get_params_from_connection_uri(
|
|
71
|
-
TestDBURI.connection_uri_pg_no_driver
|
|
72
|
-
)
|
|
66
|
+
result = get_params_from_connection_uri(TestDBURI.connection_uri_pg_no_driver)
|
|
73
67
|
assert result == TestDBURI.params_pg_driver_none
|
|
74
68
|
result = get_params_from_connection_uri(TestDBURI.connection_uri_sq)
|
|
75
69
|
assert result == TestDBURI.params_sq_driver_none
|
|
@@ -77,9 +71,7 @@ class TestDBURI:
|
|
|
77
71
|
def test_get_connection_uri(self):
|
|
78
72
|
result = get_connection_uri(**TestDBURI.params_pg)
|
|
79
73
|
assert result == TestDBURI.connection_uri_pg
|
|
80
|
-
result = get_connection_uri(
|
|
81
|
-
**TestDBURI.params_pg, include_driver=False
|
|
82
|
-
)
|
|
74
|
+
result = get_connection_uri(**TestDBURI.params_pg, include_driver=False)
|
|
83
75
|
assert result == TestDBURI.connection_uri_pg_no_driver
|
|
84
76
|
result = get_connection_uri(**TestDBURI.params_pg_no_driver)
|
|
85
77
|
assert result == TestDBURI.connection_uri_pg
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
from hdx.database import Database
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
def test_drop_schema(mock_engine):
|
|
5
|
+
db_uri = "postgresql+psycopg://myuser:mypass@0.0.0.0:12345/mydatabase"
|
|
6
|
+
assert Database.drop_schema(mock_engine, db_uri) is True
|
|
7
|
+
db_uri = "Error"
|
|
8
|
+
assert Database.drop_schema(mock_engine, db_uri) is False
|
|
9
|
+
|
|
10
|
+
|
|
4
11
|
def test_recreate_schema(mock_engine):
|
|
5
12
|
db_uri = "postgresql+psycopg://myuser:mypass@0.0.0.0:12345/mydatabase"
|
|
6
13
|
assert Database.recreate_schema(mock_engine, db_uri) is True
|
|
@@ -53,9 +53,7 @@ class TestSSH:
|
|
|
53
53
|
)
|
|
54
54
|
assert dbdatabase._base == NoTZBase
|
|
55
55
|
|
|
56
|
-
with Database(
|
|
57
|
-
ssh_host="mysshhost", ssh_port=25, **params
|
|
58
|
-
) as dbdatabase:
|
|
56
|
+
with Database(ssh_host="mysshhost", ssh_port=25, **params) as dbdatabase:
|
|
59
57
|
dbsession = dbdatabase.get_session()
|
|
60
58
|
assert (
|
|
61
59
|
str(dbsession.bind.engine.url)
|
|
File without changes
|
|
File without changes
|
{hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/.github/workflows/run-python-tests.yaml
RENAMED
|
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
|
{hdx_python_database-1.3.6 → hdx_python_database-1.3.7}/tests/hdx/database/test_postgresql.py
RENAMED
|
File without changes
|
|
File without changes
|