Skip to content

Commit 3c22804

Browse files
committed
Merge branch 'database-transfer-updates'
* database-transfer-updates: New database transfer utilities Removed dev dependencies Updated lock files Update versions Updated version constraints Updatet transfer utilities Better stream utilities Added new utility functions Updated error management
2 parents cb45c6a + 87af2fc commit 3c22804

File tree

20 files changed

+672
-599
lines changed

20 files changed

+672
-599
lines changed
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
class ApplicationError(Exception):
2-
"""Base class for all errors that should be caught and handled by the application."""
3-
4-
pass
1+
from macrostrat.utils import ApplicationError # noqa

app-frame/poetry.lock

Lines changed: 40 additions & 111 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app-frame/pyproject.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@ packages = [
66
{ include = "macrostrat" },
77
{ include = "test_app" },
88
]
9-
version = "2.1.0"
9+
version = "2.2.0"
1010

1111
[tool.poetry.dependencies]
12-
"macrostrat.utils" = "^1.1.0"
13-
python = "^3.8"
12+
"macrostrat.utils" = "^1.3.0"
13+
python = "^3.10"
1414
python-dotenv = "^1.0.0"
1515
toposort = "^1.5"
1616
rich = "^13"
1717
typer = "^0.12.5"
1818
packaging = "^24.1"
1919

20-
[tool.poetry.dev-dependencies]
21-
2220
[build-system]
2321
build-backend = "poetry.core.masonry.api"
2422
requires = ["poetry-core>=1.0.0"]

auth-system/poetry.lock

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auth-system/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[tool.poetry]
22
name = "macrostrat.auth_system"
3-
version = "1.0.2"
3+
version = "1.0.3"
44
description = "Authentication system for Macrostrat and related apps"
55
authors = ["Daven Quinn <[email protected]>"]
66
readme = "README.md"
77
packages = [{ include = "macrostrat" }]
88

99
[tool.poetry.dependencies]
10-
python = "^3.9"
10+
python = "^3.10"
1111
"macrostrat.database" = "^3.3.1"
1212
"macrostrat.utils" = "^1.2.0"
1313
PyJWT = "^1.7.1 || ^2.0"

database/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [3.5.0] - 2024-11-25
4+
5+
- Add database transfer utilities for asynchronous `pg_load` and `pg_dump`
6+
operations.
7+
38
## [3.4.1] - 2024-10-28
49

510
- Update the underlying version of `sqlparse` and `geoalchemy2`.

database/macrostrat/database/transfer/dump_database.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import asyncio
2+
import sys
23
from pathlib import Path
34
from typing import Optional
45

56
import aiofiles
67
from sqlalchemy.engine import Engine
78

89
from macrostrat.utils import get_logger
9-
10-
from .utils import _create_command, print_stdout, print_stream_progress
10+
from .stream_utils import print_stdout, print_stream_progress
11+
from .utils import _create_command
1112

1213
log = get_logger(__name__)
1314

@@ -45,11 +46,22 @@ async def pg_dump(
4546
)
4647

4748

48-
async def pg_dump_to_file(dumpfile: Path, *args, **kwargs):
49-
proc = await pg_dump(*args, **kwargs)
49+
async def pg_dump_to_file(engine: Engine, dumpfile: Path | None, **kwargs):
50+
proc = await pg_dump(engine, **kwargs)
51+
if dumpfile is None or dumpfile == sys.stdout:
52+
# If we have no dumpfile, just print to stdout
53+
await _monitor_stdout(proc)
54+
return
5055
# Open dump file as an async stream
5156
async with aiofiles.open(dumpfile, mode="wb") as dest:
5257
await asyncio.gather(
5358
asyncio.create_task(print_stream_progress(proc.stdout, dest)),
5459
asyncio.create_task(print_stdout(proc.stderr)),
5560
)
61+
62+
63+
async def _monitor_stdout(proc):
64+
await asyncio.gather(
65+
asyncio.create_task(print_stdout(proc.stdout)),
66+
asyncio.create_task(print_stream_progress(proc.stderr, None)),
67+
)

database/macrostrat/database/transfer/move_tables.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
from sqlalchemy.engine import Engine
44

55
from macrostrat.utils import get_logger
6-
76
from .dump_database import pg_dump
87
from .restore_database import pg_restore
9-
from .utils import print_stdout, print_stream_progress
8+
from .stream_utils import print_stdout, print_stream_progress
109

1110
log = get_logger(__name__)
1211

database/macrostrat/database/transfer/restore_database.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@
77
from sqlalchemy.engine import Engine
88

99
from macrostrat.utils import get_logger
10-
11-
from .utils import (
12-
_create_command,
13-
_create_database_if_not_exists,
14-
print_stdout,
15-
print_stream_progress,
16-
)
10+
from .stream_utils import print_stdout, print_stream_progress
11+
from .utils import _create_command, _create_database_if_not_exists
1712

1813
console = Console()
1914

@@ -56,11 +51,13 @@ async def pg_restore(
5651
)
5752

5853

59-
async def pg_restore_from_file(dumpfile: Path, *args, **kwargs):
60-
proc = await pg_restore(*args, **kwargs)
54+
async def pg_restore_from_file(dumpfile: Path, engine: Engine, **kwargs):
55+
proc = await pg_restore(engine, **kwargs)
6156
# Open dump file as an async stream
6257
async with aiofiles.open(dumpfile, mode="rb") as source:
6358
await asyncio.gather(
64-
asyncio.create_task(print_stream_progress(source, proc.stdin)),
59+
asyncio.create_task(
60+
print_stream_progress(source, proc.stdin, prefix="Restored")
61+
),
6562
asyncio.create_task(print_stdout(proc.stderr)),
6663
)

0 commit comments

Comments
 (0)