35
35
36
36
# Increment this PATCH version before using `charmcraft publish-lib` or reset
37
37
# to 0 if you are raising the major API version
38
- LIBPATCH = 53
38
+ LIBPATCH = 52
39
39
40
40
# Groups to distinguish HBA access
41
41
ACCESS_GROUP_IDENTITY = "identity_access"
@@ -700,15 +700,22 @@ def list_valid_privileges_and_roles(self) -> Tuple[Set[str], Set[str]]:
700
700
"superuser" ,
701
701
}, {role [0 ] for role in cursor .fetchall () if role [0 ]}
702
702
703
- def set_up_database (self ) -> None :
703
+ def set_up_database (self , temp_location : Optional [ str ] = None ) -> None :
704
704
"""Set up postgres database with the right permissions."""
705
705
connection = None
706
+ cursor = None
706
707
try :
707
- with self ._connect_to_database () as connection , connection .cursor () as cursor :
708
- cursor .execute ("SELECT TRUE FROM pg_roles WHERE rolname='admin';" )
709
- if cursor .fetchone () is not None :
710
- return
708
+ connection = self ._connect_to_database ()
709
+ cursor = connection .cursor ()
711
710
711
+ if temp_location is not None :
712
+ cursor .execute ("SELECT TRUE FROM pg_tablespace WHERE spcname='temp';" )
713
+ if cursor .fetchone () is None :
714
+ cursor .execute (f"CREATE TABLESPACE temp LOCATION '{ temp_location } ';" )
715
+ cursor .execute ("GRANT CREATE ON TABLESPACE temp TO public;" )
716
+
717
+ cursor .execute ("SELECT TRUE FROM pg_roles WHERE rolname='admin';" )
718
+ if cursor .fetchone () is None :
712
719
# Allow access to the postgres database only to the system users.
713
720
cursor .execute ("REVOKE ALL PRIVILEGES ON DATABASE postgres FROM PUBLIC;" )
714
721
cursor .execute ("REVOKE CREATE ON SCHEMA public FROM PUBLIC;" )
@@ -727,6 +734,8 @@ def set_up_database(self) -> None:
727
734
logger .error (f"Failed to set up databases: { e } " )
728
735
raise PostgreSQLDatabasesSetupError () from e
729
736
finally :
737
+ if cursor is not None :
738
+ cursor .close ()
730
739
if connection is not None :
731
740
connection .close ()
732
741
0 commit comments