db: Add more utilities for managing PostgreSQL databases

- Add methods for creating/dropping user/database.

Tests:

- ttrss and miniflux functional tests work which check for backup/restore.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2025-01-26 10:50:19 -05:00
1 parent 2beb02b496
commit b99ead7aa6
4 files changed
+128 -61

No files matched your search

+5 -4
View File
@@ -10,8 +10,9 @@ from urllib.parse import urlparse
import pexpect
from plinth import action_utils, db
from plinth import action_utils
from plinth.actions import privileged, secret_str
from plinth.db import postgres
from plinth.utils import is_non_empty_file
STATIC_SETTINGS = {
@@ -142,12 +143,12 @@ def _get_database_config():
def dump_database():
"""Dump database to file."""
config = _get_database_config()
db.postgres_dump_database(DB_BACKUP_FILE, config['database'],
config['user'])
postgres.dump_database(DB_BACKUP_FILE, config['database'])
@privileged
def restore_database():
"""Restore database from file."""
config = _get_database_config()
db.postgres_restore_database(DB_BACKUP_FILE, config['database'])
postgres.restore_database(DB_BACKUP_FILE, config['database'],
config['user'], config['password'])
+5 -4
View File
@@ -3,8 +3,9 @@
import augeas
from plinth import action_utils, db
from plinth import action_utils
from plinth.actions import privileged
from plinth.db import postgres
CONFIG_FILE = '/etc/tt-rss/config.php'
DEFAULT_FILE = '/etc/default/tt-rss'
@@ -121,15 +122,15 @@ def enable_api_access():
def dump_database():
"""Dump database to file."""
config = _get_database_config()
db.postgres_dump_database(DB_BACKUP_FILE, config['database'],
config['user'])
postgres.dump_database(DB_BACKUP_FILE, config['database'])
@privileged
def restore_database():
"""Restore database from file."""
config = _get_database_config()
db.postgres_restore_database(DB_BACKUP_FILE, config['database'])
postgres.restore_database(DB_BACKUP_FILE, config['database'],
config['user'], config['password'])
def load_augeas():