db script sync fix

This commit is contained in:
2026-03-04 13:16:11 +01:00
parent 8f8ed0084e
commit 0bd2125f24
2 changed files with 18 additions and 15 deletions

View File

@@ -215,7 +215,9 @@ cd /opt/dockge
docker compose up -d docker compose up -d
# call replacements for nginx db # call replacements for nginx db
replace_in_sqlite_db "/opt/stacks/npm/data/database.sqlite" "?domain?" $domain
replace_in_sqlite_db "/opt/stacks/npm/data/database.sqlite" "?localip?" $localip
replace_in_sqlite_db "/opt/stacks/npm/data/database.sqlite" "?adminpass?" $adminpass
echo "" echo ""

View File

@@ -12,6 +12,10 @@ replace_in_sqlite_db() {
echo "Starting replacement of '$OLD_STRING' with '$NEW_STRING' in '$DB_PATH'..." echo "Starting replacement of '$OLD_STRING' with '$NEW_STRING' in '$DB_PATH'..."
# Escape single quotes in the strings for SQL
local OLD_STRING_ESC=$(echo "$OLD_STRING" | sed "s/'/''/g")
local NEW_STRING_ESC=$(echo "$NEW_STRING" | sed "s/'/''/g")
# Get a list of all tables in the database # Get a list of all tables in the database
local TABLES local TABLES
TABLES=$(sqlite3 "$DB_PATH" ".tables") TABLES=$(sqlite3 "$DB_PATH" ".tables")
@@ -21,30 +25,27 @@ replace_in_sqlite_db() {
echo "Processing table: $TABLE" echo "Processing table: $TABLE"
# Get a list of all columns in the table # Get a list of all columns in the table
local COLUMNS sqlite3 "$DB_PATH" "PRAGMA table_info($TABLE);" | awk -F'|' '{print $2","$3}' | while IFS=, read -r COLUMN COLUMN_TYPE; do
COLUMNS=$(sqlite3 "$DB_PATH" "PRAGMA table_info($TABLE);" | awk -F'|' '{print $2}' | grep -v '^$') # Skip empty lines
if [ -z "$COLUMN" ]; then
continue
fi
# Loop through each column # Check if the column is a string-based type (TEXT, VARCHAR, CHAR, CLOB, etc.)
for COLUMN in $COLUMNS; do if [[ "$COLUMN_TYPE" =~ [Tt][Ee][Xx][Tt]|[Vv][Aa][Rr][Cc][Hh][Aa][Rr]|[Cc][Hh][Aa][Rr]|[Cc][Ll][Oo][Bb]|[Ss][Tt][Rr][Ii][Nn][Gg] ]]; then
# Check if the column is a text type (simplistic check)
local COLUMN_TYPE
COLUMN_TYPE=$(sqlite3 "$DB_PATH" "PRAGMA table_info($TABLE);" | awk -F'|' -v col="$COLUMN" '$2 == col {print $3}')
# Only proceed if the column type contains 'TEXT' (case-insensitive)
if [[ "$COLUMN_TYPE" =~ [Tt][Ee][Xx][Tt] ]]; then
echo " Updating column: $COLUMN (type: $COLUMN_TYPE)" echo " Updating column: $COLUMN (type: $COLUMN_TYPE)"
# Perform the replacement # Perform the replacement (handles infixes)
sqlite3 "$DB_PATH" " sqlite3 "$DB_PATH" "
UPDATE $TABLE UPDATE $TABLE
SET $COLUMN = replace($COLUMN, '$OLD_STRING', '$NEW_STRING') SET $COLUMN = replace($COLUMN, '$OLD_STRING_ESC', '$NEW_STRING_ESC')
WHERE $COLUMN LIKE '%$OLD_STRING%'; WHERE $COLUMN LIKE '%$OLD_STRING_ESC%';
" "
fi fi
done done
done done
echo "Replacement completed for all text-type columns in '$DB_PATH'." echo "Replacement completed for all string-based columns in '$DB_PATH'."
} }
#set script directory #set script directory