From 10de467469b80fe4746e91c0e37ae7d075698d98 Mon Sep 17 00:00:00 2001 From: Marcelo Henrique Neppel Date: Mon, 1 Jul 2024 16:59:19 -0300 Subject: [PATCH] Fix library Signed-off-by: Marcelo Henrique Neppel --- lib/charms/postgresql_k8s/v0/postgresql.py | 25 ++++++++++------------ 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/charms/postgresql_k8s/v0/postgresql.py b/lib/charms/postgresql_k8s/v0/postgresql.py index 57633a9172..f8f3ad2b23 100644 --- a/lib/charms/postgresql_k8s/v0/postgresql.py +++ b/lib/charms/postgresql_k8s/v0/postgresql.py @@ -36,7 +36,7 @@ # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 29 +LIBPATCH = 30 INVALID_EXTRA_USER_ROLE_BLOCKING_MESSAGE = "invalid role(s) for extra user roles" @@ -383,6 +383,16 @@ def _generate_database_privileges_statements( ) return statements + def get_last_archived_wal(self) -> str: + """Get the name of the last archived wal for the current PostgreSQL cluster.""" + try: + with self._connect_to_database() as connection, connection.cursor() as cursor: + cursor.execute("SELECT last_archived_wal FROM pg_stat_archiver;") + return cursor.fetchone()[0] + except psycopg2.Error as e: + logger.error(f"Failed to get PostgreSQL last archived WAL: {e}") + raise PostgreSQLGetPostgreSQLVersionError() + def get_postgresql_text_search_configs(self) -> Set[str]: """Returns the PostgreSQL available text search configs. @@ -629,16 +639,3 @@ def validate_date_style(self, date_style: str) -> bool: return True except psycopg2.Error: return False - - def get_last_archived_wal(self) -> str | None: - """ - Returns: - Name of the last archived wal for the current PostgreSQL cluster. None, if there is no information available. - """ - try: - with self._connect_to_database() as connection, connection.cursor() as cursor: - cursor.execute("SELECT last_archived_wal FROM pg_stat_archiver;") - return cursor.fetchone()[0] - except psycopg2.Error as e: - logger.error(f"Failed to get PostgreSQL last archived WAL: {e}") - raise PostgreSQLGetPostgreSQLVersionError()