mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-08-31 09:13:33 +02:00
birdnet-go: fall back to existence-check when CREATE DATABASE is denied
The HA MariaDB service user may lack global CREATE DATABASE privilege. If CREATE DATABASE fails, check whether the database was pre-created manually and proceed if so. Only exit 1 if the database is truly absent, with a clear instruction to create it manually.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
## nightly-20260615-2 (2026-06-23)
|
||||
- MariaDB auto-config: create the `birdnet` database on first start if it does not exist (birdnet-go connects to a pre-existing schema and does not create it, causing "database doesn't exist" errors)
|
||||
- MariaDB auto-config: ensure the `birdnet` database exists before starting — birdnet-go does not create it automatically; if `CREATE DATABASE` fails due to insufficient privileges the script falls back to checking whether the database was pre-created manually, and exits with a clear instruction if it is missing
|
||||
- MariaDB auto-config: disabling `mariadb_auto_config` now reverts to SQLite only when `output.mysql.host` in config.yaml matches the HA MariaDB host (avoids clobbering manually-configured MySQL pointing at a different server)
|
||||
- Added `mariadb-client` to the addon packages so the `mysql` CLI used for database creation is available inside the container
|
||||
|
||||
|
||||
@@ -68,17 +68,30 @@ bashio::log.blue "User: ${MYSQL_USER}"
|
||||
bashio::log.blue "Database: ${MYSQL_DATABASE}"
|
||||
bashio::log.green "---"
|
||||
|
||||
# Create the database — birdnet-go connects to an existing schema and does NOT
|
||||
# create it automatically, so we must do it here. MYSQL_PWD avoids exposing
|
||||
# the password via the process command line.
|
||||
# Ensure the database exists. birdnet-go connects to an existing schema and
|
||||
# does NOT create it automatically. MYSQL_PWD avoids password in process list.
|
||||
# The HA MariaDB service user may lack global CREATE DATABASE privilege, so if
|
||||
# CREATE DATABASE fails we fall back to checking whether the database already
|
||||
# exists (pre-created manually or by a previous run with broader privileges).
|
||||
if ! MYSQL_PWD="${MYSQL_PASS}" mysql \
|
||||
--host="${MYSQL_HOST}" \
|
||||
--port="${MYSQL_PORT}" \
|
||||
--user="${MYSQL_USER}" \
|
||||
--connect-timeout=10 \
|
||||
-e "CREATE DATABASE IF NOT EXISTS \`${MYSQL_DATABASE}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" 2>/dev/null; then
|
||||
bashio::log.error "Failed to create MariaDB database '${MYSQL_DATABASE}' — verify the MariaDB addon is running and the user has CREATE DATABASE privileges"
|
||||
exit 1
|
||||
bashio::log.warning "Could not CREATE DATABASE '${MYSQL_DATABASE}' (insufficient privileges?) — checking if it already exists"
|
||||
if ! MYSQL_PWD="${MYSQL_PASS}" mysql \
|
||||
--host="${MYSQL_HOST}" \
|
||||
--port="${MYSQL_PORT}" \
|
||||
--user="${MYSQL_USER}" \
|
||||
--connect-timeout=10 \
|
||||
"${MYSQL_DATABASE}" \
|
||||
-e "SELECT 1;" >/dev/null 2>&1; then
|
||||
bashio::log.error "Database '${MYSQL_DATABASE}' does not exist and could not be created."
|
||||
bashio::log.error "Create it manually in MariaDB: CREATE DATABASE \`${MYSQL_DATABASE}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
||||
exit 1
|
||||
fi
|
||||
bashio::log.yellow "Database '${MYSQL_DATABASE}' already exists — skipping creation"
|
||||
fi
|
||||
bashio::log.blue "Database '${MYSQL_DATABASE}' is ready"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user