Bases: PostgresDatabaseStrategy
A class for interacting with cloud PostgreSQL databases.
This class provides methods for dumping and managing cloud PostgreSQL databases.
The constructor for the CloudPostgresDatabase class.
It initializes the database configuration from environment variables.
Source code in dev_tool/db/postgres/cloud.py
| def __init__(self) -> None:
"""
The constructor for the CloudPostgresDatabase class.
It initializes the database configuration from environment variables.
"""
config = DatabaseConfig.from_env(prefix='CLOUD_')
super().__init__(config)
|
create_database
A method that creates a database in the cloud.
This method is not implemented and will raise an exception.
Source code in dev_tool/db/postgres/cloud.py
| @override
def create_database(self) -> None:
"""
A method that creates a database in the cloud.
This method is not implemented and will raise an exception.
"""
message = 'Please do not create a database in the cloud database.'
CONTEXT.notification.error_banner(message)
raise NotImplementedError(message)
|
drop_database
A method that drops a database from the cloud.
This method is not implemented and will raise an exception.
Source code in dev_tool/db/postgres/cloud.py
| @override
def drop_database(self) -> None:
"""
A method that drops a database from the cloud.
This method is not implemented and will raise an exception.
"""
message = 'Please do not drop a database in the cloud database.'
CONTEXT.notification.error_banner(message)
raise NotImplementedError(message)
|
dump_database
A method that dumps a cloud database to a local directory.
Parameters:
-
input_file
(Path)
–
The path to the output directory.
Source code in dev_tool/db/postgres/cloud.py
| def dump_database(self, input_file: Path) -> None:
"""
A method that dumps a cloud database to a local directory.
:param input_file: The path to the output directory.
"""
try:
self._remove_mounted()
mount = '/tmp/mounted' # noqa: S108
version = CONTEXT.configuration.get_docker_config().get('postgres-version')
command = [
'docker', 'run',
'--rm',
'-e', f'PGPASSWORD={self.config.password}',
'-v', f'{input_file}:{mount}',
f'postgres:{version}',
'pg_dump',
'-h', self.config.host,
'-p', self.config.port,
'-U', self.config.user,
'-d', self.config.name,
'-F', 'd',
'--jobs=8',
'--no-owner',
'--no-acl',
'--clean',
'--create',
'--verbose',
'-f', '/tmp/mounted/dump' # noqa: S108
]
subprocess.run(command, check=True)
except subprocess.CalledProcessError as exception:
message = f'Failed to dump cloud database {self.config.name}: {exception}'
CONTEXT.notification.error_banner(message)
log.exception(message)
raise PostgreSQLConnectionError(message) from None
except Exception as exception:
message = f'Unexpected error dumping cloud database {self.config.name}: {exception}'
CONTEXT.notification.error_banner(message)
log.exception(message)
raise PostgreSQLConnectionError(message) from None
|