Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch from server_version to server_version_num #304

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/pypgstac/python/pypgstac/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,18 @@ def pg_version(self) -> str:
"""Get the current pg version number from a pgstac database."""
version = self.query_one(
"""
SHOW server_version;
SHOW server_version_num;
""",
)
logger.debug(f"PG VERSION: {version}.")
if isinstance(version, bytes):
version = version.decode()
if isinstance(version, str):
if int(version.split(".")[0]) < 13:
raise Exception("PgSTAC requires PostgreSQL 13+")
if int(version) < 130000:
major, minor, patch = tuple(
map(int, [version[i:i + 2] for i in range(0, len(version), 2)]),
)
raise Exception(f"PgSTAC requires PostgreSQL 13+, current version is: {major}.{minor}.{patch}") # noqa: E501
return version
else:
if self.connection is not None:
Expand Down
12 changes: 10 additions & 2 deletions src/pypgstac/python/pypgstac/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,16 @@ def run_migration(self, toversion: Optional[str] = None) -> str:
logger.info("using unreleased version")
toversion = "unreleased"

pg_version = self.db.pg_version
logger.info(f"Migrating PgSTAC on PostgreSQL Version {pg_version}")
major, minor, patch = tuple(
map(
int,
[
self.db.pg_version[i:i + 2]
for i in range(0, len(self.db.pg_version), 2)
],
),
)
logger.info(f"Migrating PgSTAC on PostgreSQL Version {major}.{minor}.{patch}")
oldversion = self.db.version
if oldversion == toversion:
logger.info(f"Target database already at version: {toversion}")
Expand Down
Loading