FreedomBox/plinth/db/mariadb.py
Sunil Mohan Adapa ced83a31e9
zoph: Fix cases when CLI user is set to "autodetect"
Closes: #2538

Tests:

- Without the patch, set the Zoph CLI User to "autodetect" and notice the
failure to load Zoph page.

- With the patch, set user to "autodetect" and access the app page. It is
updated to the first admin user in Zoph DB.

- Try with updating Zoph configuration.

- Try with re-running Zoph setup.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2025-09-21 13:25:58 -04:00

18 lines
528 B
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""Utilities to help with MariaDB/MySQL databases.
Uses utilities from 'mysql-client' package such as 'mysql' and 'mysqldump'.
"""
import subprocess
def run_query(database_name: str, query: str) -> subprocess.CompletedProcess:
"""Run a database query using 'root' user.
Does not ensure that the database server is running.
"""
return subprocess.run(
['mysql', '--user=root', '--database', database_name],
input=query.encode('utf-8'), check=True)