/
Bulk delete using CQL query
Bulk delete using CQL query
Example script delete-organizsations
for bulk deleting organizsations selected by a CQL query.
#!/bin/sh
if [ -z "$1" ]
then
echo "First parameter must be non-empty CQL query"
exit 1
fi
OKAPIURL="${OKAPIURL:-https://folio-snapshot-okapi.dev.folio.org}"
TENANT="${TENANT:-diku}"
OKAPIUSERNAME="${OKAPIUSERNAME:-diku_admin}"
OKAPIPASSWORD="${OKAPIPASSWORD:-admin}"
LOGIN=$( jq -n -c --arg username "$OKAPIUSERNAME" --arg password "$OKAPIPASSWORD" '{"username": $username, "password": $password}' )
curl -w"\n\n" -sS -j -c /tmp/cookies.txt -H "X-Okapi-Tenant: $TENANT" -H "Content-type: application/json" -d "$LOGIN" "$OKAPIURL/authn/login-with-expiry"
while true
do
R=$( curl -w"\n%{http_code}\n" -sS -b /tmp/cookies.txt -H "X-Okapi-Tenant: $TENANT" -H "X-Okapi-URL: $OKAPIURL" --get --data-urlencode "query=$1" "$OKAPIURL/organizations-storage/organizations?limit=1" )
STATUS=$( echo "$R" | tail -n 1 )
if [ "$STATUS" != "200" ]
then
echo "GET failed:"
echo "$R"
break
fi
JSON=$( echo "$R" | head -n -1 )
echo "$JSON" | jq -c '.[] | .[0]?'
ID=$( echo "$JSON" | jq -r '.[] | .[0]?.id?' )
LENGTH=${#ID}
[ "$LENGTH" -eq 36 ] || break
R=$( curl -w"\n%{http_code}\n" -sS -b /tmp/cookies.txt -H "X-Okapi-Tenant: $TENANT" -H "X-Okapi-URL: $OKAPIURL" -XDELETE "$OKAPIURL/organizations-storage/organizations/$ID" )
STATUS=$( echo "$R" | tail -n 1 )
if [ "$STATUS" != "204" ]
then
echo "DELETE failed:"
echo "$R"
break
fi
done
Example invokation:
delete-organizsations 'name=="*rubbish*"'
Use CQL query cql.allRecords=1
to delete all records:
delete-organizsations 'cql.allRecords=1'
, multiple selections available,
Related content
Script to hard delete OLD records
Script to hard delete OLD records
More like this
Script to delete records containing error record data
Script to delete records containing error record data
More like this
Deleting Data Import Logs via API
Deleting Data Import Logs via API
More like this
SQL Queries for tests
SQL Queries for tests
More like this
Script to update mapping rules with required condition for specified fields
Script to update mapping rules with required condition for specified fields
More like this
Database schema
Database schema
More like this