dycw-utilities 0.148.2__py3-none-any.whl → 0.148.4__py3-none-any.whl
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.
- {dycw_utilities-0.148.2.dist-info → dycw_utilities-0.148.4.dist-info}/METADATA +1 -1
- {dycw_utilities-0.148.2.dist-info → dycw_utilities-0.148.4.dist-info}/RECORD +7 -7
- utilities/__init__.py +1 -1
- utilities/postgres.py +40 -9
- {dycw_utilities-0.148.2.dist-info → dycw_utilities-0.148.4.dist-info}/WHEEL +0 -0
- {dycw_utilities-0.148.2.dist-info → dycw_utilities-0.148.4.dist-info}/entry_points.txt +0 -0
- {dycw_utilities-0.148.2.dist-info → dycw_utilities-0.148.4.dist-info}/licenses/LICENSE +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
utilities/__init__.py,sha256=
|
1
|
+
utilities/__init__.py,sha256=VDgRGy8SY-uljlJ76REYaNomUoE5yqIY42dKSUSpjuY,60
|
2
2
|
utilities/altair.py,sha256=92E2lCdyHY4Zb-vCw6rEJIsWdKipuu-Tu2ab1ufUfAk,9079
|
3
3
|
utilities/asyncio.py,sha256=z0w3fb-U5Ml5YXVaFFPClizXaQmjDO6YgZg-V9QL0VQ,16021
|
4
4
|
utilities/atomicwrites.py,sha256=xcOWenTBRS0oat3kg7Sqe51AohNThMQ2ixPL7QCG8hw,5795
|
@@ -48,7 +48,7 @@ utilities/pickle.py,sha256=MBT2xZCsv0pH868IXLGKnlcqNx2IRVKYNpRcqiQQqxw,653
|
|
48
48
|
utilities/platform.py,sha256=Ue9LSxYvg9yUXGKuz5aZoy_qkUEXde-v6B09exgSctU,2813
|
49
49
|
utilities/polars.py,sha256=BgiDryAVOapi41ddfJqN0wYh_sDj8BNEYtPB36LaHdo,71824
|
50
50
|
utilities/polars_ols.py,sha256=Uc9V5kvlWZ5cU93lKZ-cfAKdVFFw81tqwLW9PxtUvMs,5618
|
51
|
-
utilities/postgres.py,sha256=
|
51
|
+
utilities/postgres.py,sha256=Q1auvVqwUrIP6yhwvjCXg7zQbWgQ9czuJIa99eK6soM,8993
|
52
52
|
utilities/pottery.py,sha256=w2X80PXWwzdHdqSYJP6ESrPNNDP3xzpyuJn-fp-Vt3M,5969
|
53
53
|
utilities/pqdm.py,sha256=BTsYPtbKQWwX-iXF4qCkfPG7DPxIB54J989n83bXrIo,3092
|
54
54
|
utilities/psutil.py,sha256=KUlu4lrUw9Zg1V7ZGetpWpGb9DB8l_SSDWGbANFNCPU,2104
|
@@ -88,8 +88,8 @@ utilities/zoneinfo.py,sha256=oEH-nL3t4h9uawyZqWDtNtDAl6M-CLpLYGI_nI6DulM,1971
|
|
88
88
|
utilities/pytest_plugins/__init__.py,sha256=U4S_2y3zgLZVfMenHRaJFBW8yqh2mUBuI291LGQVOJ8,35
|
89
89
|
utilities/pytest_plugins/pytest_randomly.py,sha256=NXzCcGKbpgYouz5yehKb4jmxmi2SexKKpgF4M65bi10,414
|
90
90
|
utilities/pytest_plugins/pytest_regressions.py,sha256=Iwhfv_OJH7UCPZCfoh7ugZ2Xjqjil-BBBsOb8sDwiGI,1471
|
91
|
-
dycw_utilities-0.148.
|
92
|
-
dycw_utilities-0.148.
|
93
|
-
dycw_utilities-0.148.
|
94
|
-
dycw_utilities-0.148.
|
95
|
-
dycw_utilities-0.148.
|
91
|
+
dycw_utilities-0.148.4.dist-info/METADATA,sha256=VH2ptiCLL6fP3q4XBpXw-0nsTyTeHnHrxpuyT0A5tFE,1697
|
92
|
+
dycw_utilities-0.148.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
93
|
+
dycw_utilities-0.148.4.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
|
94
|
+
dycw_utilities-0.148.4.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
|
95
|
+
dycw_utilities-0.148.4.dist-info/RECORD,,
|
utilities/__init__.py
CHANGED
utilities/postgres.py
CHANGED
@@ -5,17 +5,21 @@ from pathlib import Path
|
|
5
5
|
from shutil import rmtree
|
6
6
|
from typing import TYPE_CHECKING, Literal, assert_never, override
|
7
7
|
|
8
|
+
from sqlalchemy import Table
|
9
|
+
from sqlalchemy.orm import DeclarativeBase
|
10
|
+
|
8
11
|
from utilities.asyncio import stream_command
|
9
12
|
from utilities.iterables import always_iterable
|
10
13
|
from utilities.logging import get_logger
|
11
14
|
from utilities.os import temp_environ
|
12
|
-
from utilities.sqlalchemy import
|
15
|
+
from utilities.sqlalchemy import get_table_name
|
13
16
|
from utilities.timer import Timer
|
14
17
|
from utilities.types import PathLike
|
15
18
|
|
16
19
|
if TYPE_CHECKING:
|
17
20
|
from sqlalchemy import URL
|
18
21
|
|
22
|
+
from utilities.sqlalchemy import TableOrORMInstOrClass
|
19
23
|
from utilities.types import LoggerOrName, MaybeListStr, MaybeSequence, PathLike
|
20
24
|
|
21
25
|
|
@@ -31,7 +35,10 @@ async def pg_dump(
|
|
31
35
|
format_: _PGDumpFormat = "plain",
|
32
36
|
jobs: int | None = None,
|
33
37
|
schemas: MaybeListStr | None = None,
|
34
|
-
|
38
|
+
schemas_exc: MaybeListStr | None = None,
|
39
|
+
tables: MaybeSequence[TableOrORMInstOrClass | str] | None = None,
|
40
|
+
tables_exc: MaybeSequence[TableOrORMInstOrClass | str] | None = None,
|
41
|
+
inserts: bool = False,
|
35
42
|
logger: LoggerOrName | None = None,
|
36
43
|
dry_run: bool = False,
|
37
44
|
) -> None:
|
@@ -69,14 +76,22 @@ async def pg_dump(
|
|
69
76
|
parts.append(f"--jobs={jobs}")
|
70
77
|
if schemas is not None:
|
71
78
|
parts.extend([f"--schema={s}" for s in always_iterable(schemas)])
|
79
|
+
if schemas_exc is not None:
|
80
|
+
parts.extend([f"--exclude-schema={s}" for s in always_iterable(schemas_exc)])
|
72
81
|
if tables is not None:
|
73
|
-
parts.extend([f"--table={
|
82
|
+
parts.extend([f"--table={_get_table_name(t)}" for t in always_iterable(tables)])
|
83
|
+
if tables_exc is not None:
|
84
|
+
parts.extend([
|
85
|
+
f"--exclude-table={_get_table_name(t)}" for t in always_iterable(tables_exc)
|
86
|
+
])
|
87
|
+
if inserts:
|
88
|
+
parts.append("--inserts")
|
74
89
|
if url.username is not None:
|
75
90
|
parts.append(f"--username={url.username}")
|
76
91
|
cmd = " ".join(parts)
|
77
92
|
if dry_run:
|
78
93
|
if logger is not None:
|
79
|
-
get_logger(logger=logger).info("Would run %r", str(
|
94
|
+
get_logger(logger=logger).info("Would run %r", str(cmd))
|
80
95
|
return
|
81
96
|
with temp_environ(PGPASSWORD=url.password), Timer() as timer: # pragma: no cover
|
82
97
|
try:
|
@@ -144,7 +159,8 @@ async def pg_restore(
|
|
144
159
|
data_only: bool = False,
|
145
160
|
jobs: int | None = None,
|
146
161
|
schemas: MaybeListStr | None = None,
|
147
|
-
|
162
|
+
schemas_exc: MaybeListStr | None = None,
|
163
|
+
tables: MaybeSequence[TableOrORMInstOrClass | str] | None = None,
|
148
164
|
logger: LoggerOrName | None = None,
|
149
165
|
dry_run: bool = False,
|
150
166
|
) -> None:
|
@@ -174,7 +190,6 @@ async def pg_restore(
|
|
174
190
|
"--exit-on-error",
|
175
191
|
"--no-owner",
|
176
192
|
"--no-privileges",
|
177
|
-
"--if-exists",
|
178
193
|
# connection options
|
179
194
|
f"--host={url.host}",
|
180
195
|
f"--port={url.port}",
|
@@ -183,20 +198,22 @@ async def pg_restore(
|
|
183
198
|
if data_only:
|
184
199
|
parts.append("--data-only")
|
185
200
|
else:
|
186
|
-
parts.
|
201
|
+
parts.extend(["--clean", "--if-exists"])
|
187
202
|
if jobs is not None:
|
188
203
|
parts.append(f"--jobs={jobs}")
|
189
204
|
if schemas is not None:
|
190
205
|
parts.extend([f"--schema={s}" for s in always_iterable(schemas)])
|
206
|
+
if schemas_exc is not None:
|
207
|
+
parts.extend([f"--exclude-schema={s}" for s in always_iterable(schemas_exc)])
|
191
208
|
if tables is not None:
|
192
|
-
parts.extend([f"--table={
|
209
|
+
parts.extend([f"--table={_get_table_name(t)}" for t in always_iterable(tables)])
|
193
210
|
if url.username is not None:
|
194
211
|
parts.append(f"--username={url.username}")
|
195
212
|
parts.append(str(path))
|
196
213
|
cmd = " ".join(parts)
|
197
214
|
if dry_run:
|
198
215
|
if logger is not None:
|
199
|
-
get_logger(logger=logger).info("Would run %r", str(
|
216
|
+
get_logger(logger=logger).info("Would run %r", str(cmd))
|
200
217
|
return
|
201
218
|
with temp_environ(PGPASSWORD=url.password), Timer() as timer: # pragma: no cover
|
202
219
|
try:
|
@@ -249,4 +266,18 @@ class _PGRestorePortError(PGRestoreError):
|
|
249
266
|
return f"Expected URL to contain a 'port'; got {self.url}"
|
250
267
|
|
251
268
|
|
269
|
+
##
|
270
|
+
|
271
|
+
|
272
|
+
def _get_table_name(obj: TableOrORMInstOrClass | str, /) -> str:
|
273
|
+
"""Get the table name from a Table or mapped class."""
|
274
|
+
match obj:
|
275
|
+
case Table() | DeclarativeBase() | type() as table_or_orm:
|
276
|
+
return get_table_name(table_or_orm)
|
277
|
+
case str() as name:
|
278
|
+
return name
|
279
|
+
case _ as never:
|
280
|
+
assert_never(never)
|
281
|
+
|
282
|
+
|
252
283
|
__all__ = ["PGDumpError", "PGRestoreError", "pg_dump", "pg_restore"]
|
File without changes
|
File without changes
|
File without changes
|