Files
NetAlertX/scripts/db_cleanup/regenerate-database.sh
Adam Outler ed44c68d54 Update scripts/db_cleanup/regenerate-database.sh
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2026-02-07 10:29:57 -05:00

21 lines
722 B
Bash
Executable File

#!/bin/sh
# This script recreates the database from schema code.
# Database location
NETALERTX_DB_FILE=${NETALERTX_DB:-/data/db}/app.db
#remove the old database
rm -f "${NETALERTX_DB_FILE}" "${NETALERTX_DB_FILE}-shm" "${NETALERTX_DB_FILE}-wal"
# Calculate script directory and schema path
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
# Path to the schema file (relative to script location: scripts/db_cleanup/ -> ../../server/db/schema/app.sql)
SCHEMA_FILE="${SCRIPT_DIR}/../../server/db/schema/app.sql"
if [ ! -f "${SCHEMA_FILE}" ]; then
echo "Error: Schema file not found at ${SCHEMA_FILE}"
exit 1
fi
# Import the database schema into the new database file
sqlite3 "${NETALERTX_DB_FILE}" < "${SCHEMA_FILE}"