From 675bd199d4952c63ef10cd80de8c253dc08e8e53 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 23 Jun 2026 09:05:16 +0000 Subject: [PATCH] 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. --- birdnet-go/CHANGELOG.md | 2 +- .../rootfs/etc/cont-init.d/33-mariadb.sh | 23 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/birdnet-go/CHANGELOG.md b/birdnet-go/CHANGELOG.md index 8b145ba427..0b6751232b 100644 --- a/birdnet-go/CHANGELOG.md +++ b/birdnet-go/CHANGELOG.md @@ -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 diff --git a/birdnet-go/rootfs/etc/cont-init.d/33-mariadb.sh b/birdnet-go/rootfs/etc/cont-init.d/33-mariadb.sh index c2f082dfaf..d6cee19216 100755 --- a/birdnet-go/rootfs/etc/cont-init.d/33-mariadb.sh +++ b/birdnet-go/rootfs/etc/cont-init.d/33-mariadb.sh @@ -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"