npm db should be pre-populated now

This commit is contained in:
2026-03-04 13:39:51 +01:00
parent fa1331b3e8
commit c04a49f684
3 changed files with 13 additions and 16 deletions

View File

@@ -48,7 +48,11 @@ replace_in_sqlite_db() {
return 1 return 1
fi fi
echo "Starting replacement of '$OLD_STRING' with '$NEW_STRING' in '$DB_PATH'..." echo "Starting brute-force replacement of '$OLD_STRING' with '$NEW_STRING' in '$DB_PATH'..."
# Escape single quotes 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
@@ -64,25 +68,18 @@ replace_in_sqlite_db() {
# Loop through each column # Loop through each column
for COLUMN in $COLUMNS; do for COLUMN in $COLUMNS; do
# Check if the column is a text type (simplistic check) echo " Processing column: $COLUMN"
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) # Update every cell in the column, casting to TEXT to force string replacement
if [[ "$COLUMN_TYPE" =~ [Tt][Ee][Xx][Tt] ]]; then
echo " Updating column: $COLUMN (type: $COLUMN_TYPE)"
# Perform the replacement
sqlite3 "$DB_PATH" " sqlite3 "$DB_PATH" "
UPDATE $TABLE UPDATE $TABLE
SET $COLUMN = replace($COLUMN, '$OLD_STRING', '$NEW_STRING') SET $COLUMN = replace(CAST($COLUMN AS TEXT), '$OLD_STRING_ESC', '$NEW_STRING_ESC')
WHERE $COLUMN LIKE '%$OLD_STRING%'; WHERE CAST($COLUMN AS TEXT) LIKE '%$OLD_STRING_ESC%';
" "
fi
done done
done done
echo "Replacement completed for all text-type columns in '$DB_PATH'." echo "replacement of '$OLD_STRING' with '$NEW_STRING' completed in '$DB_PATH'."
} }
#example usage: replace_in_sqlite_db "database.sqlite" "Europe/Amsterdam" "UTC" #example usage: replace_in_sqlite_db "database.sqlite" "Europe/Amsterdam" "UTC"

Binary file not shown.

Binary file not shown.