npm db should be pre-populated now
This commit is contained in:
29
deploy.sh
29
deploy.sh
@@ -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
|
sqlite3 "$DB_PATH" "
|
||||||
echo " Updating column: $COLUMN (type: $COLUMN_TYPE)"
|
UPDATE $TABLE
|
||||||
|
SET $COLUMN = replace(CAST($COLUMN AS TEXT), '$OLD_STRING_ESC', '$NEW_STRING_ESC')
|
||||||
# Perform the replacement
|
WHERE CAST($COLUMN AS TEXT) LIKE '%$OLD_STRING_ESC%';
|
||||||
sqlite3 "$DB_PATH" "
|
"
|
||||||
UPDATE $TABLE
|
|
||||||
SET $COLUMN = replace($COLUMN, '$OLD_STRING', '$NEW_STRING')
|
|
||||||
WHERE $COLUMN LIKE '%$OLD_STRING%';
|
|
||||||
"
|
|
||||||
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"
|
||||||
|
|||||||
BIN
stacks/npm/data/database (1).sqlite
Normal file
BIN
stacks/npm/data/database (1).sqlite
Normal file
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user