Compare commits
1 Commits
unstable
...
f/clean_au
Author | SHA1 | Date | |
---|---|---|---|
a08dbfe270 |
@ -16,10 +16,12 @@ set -o nounset
|
||||
|
||||
# -> delete "cascade" on table "flow" cleans access, code, oidc, pkce and refresh tables.
|
||||
|
||||
# For table authentication_session, a simple delete on this table should be enough.
|
||||
|
||||
DSN="${DSN:-postgresql://${HYDRA_DATABASE_USER}:${HYDRA_DATABASE_PASSWORD}@${HYDRA_DATABASE_SERVICE_NAME}:${HYDRA_DATABASE_SERVICE_PORT:-5432}/hydra?sslmode=disable}"
|
||||
RETENTION_HOURS="${RETENTION_HOURS:-48}"
|
||||
BATCH_SIZE="${BATCH_SIZE:-50}"
|
||||
BATCH_SIZE_ORIG="${BATCH_SIZE}"
|
||||
LIMIT="${LIMIT:-1000}"
|
||||
BEFORE_DATE="$(date +'%Y-%m-%d %H:%M:%S' --date=@$(($(date +%s) - RETENTION_HOURS * 3600)))"
|
||||
|
||||
@ -86,7 +88,43 @@ EOF
|
||||
log "${OUTPUT}"
|
||||
|
||||
if ! [[ "${OUTPUT}" =~ '^DELETE ' ]] ; then
|
||||
log "Output doesn't seems OK..."
|
||||
log "Output doesn't seem OK..."
|
||||
break
|
||||
fi
|
||||
OUTPUT_NB=$(echo "${OUTPUT}" | cut -d' ' -f 2)
|
||||
|
||||
if [ "${OUTPUT_NB}" -lt "${BATCH_SIZE}" ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
REMAINING_ELMTS=$((REMAINING_ELMTS - BATCH_SIZE))
|
||||
if [ "${REMAINING_ELMTS}" -lt "${BATCH_SIZE}" ]; then
|
||||
BATCH_SIZE="${REMAINING_ELMTS}"
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
BATCH_SIZE="${BATCH_SIZE_ORIG}"
|
||||
REMAINING_ELMTS="${LIMIT}"
|
||||
while [ "${REMAINING_ELMTS}" -gt 0 ]; do
|
||||
OUTPUT=$(psql "${DSN}" <<EOF
|
||||
DELETE
|
||||
FROM hydra_oauth2_authentication_session
|
||||
WHERE id = ANY (
|
||||
array(
|
||||
SELECT id
|
||||
FROM hydra_oauth2_authentication_session
|
||||
WHERE authenticated_at < '${BEFORE_DATE}'
|
||||
LIMIT ${BATCH_SIZE}
|
||||
)
|
||||
);
|
||||
EOF
|
||||
)
|
||||
|
||||
log "${OUTPUT}"
|
||||
|
||||
if ! [[ "${OUTPUT}" =~ '^DELETE ' ]] ; then
|
||||
log "Output doesn't seem OK..."
|
||||
break
|
||||
fi
|
||||
OUTPUT_NB=$(echo "${OUTPUT}" | cut -d' ' -f 2)
|
||||
|
Reference in New Issue
Block a user