Repository navigation
Expand file tree
/
Copy pathgenu_topup.sh
More file actions
executable file
·40 lines (34 loc) · 1.6 KB
/
Copy pathgenu_topup.sh
File metadata and controls
executable file
·40 lines (34 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# Incrementally grow the users table to a target count using `drush genu`.
#
# devel_generate's genu only dedupes usernames *within one batch* (an
# in-memory array) -- it never checks already-existing DB rows. So calling
# genu repeatedly without --kill eventually collides with a previously
# generated username and dies on a DB unique-key violation. Whatever had
# already been inserted before the collision stays committed (no wrapping
# transaction), so the fix is simply: recheck the actual count, ask for only
# the remaining shortfall, and retry. Each retry batch is smaller, so the
# chance of hitting a duplicate keeps shrinking and this converges quickly.
#
# Usage: genu_topup.sh <target_total_users> [pass] [max_retries]
set -uo pipefail
TARGET=${1:?target total user count required}
PASS=${2:-test}
MAX_RETRIES=${3:-50}
for ((i = 1; i <= MAX_RETRIES; i++)); do
current=$(ddev drush sqlq "SELECT COUNT(*) FROM users_field_data;" | head -1)
remaining=$((TARGET - current))
if [ "$remaining" -le 0 ]; then
echo "Target reached: ${current} users (target ${TARGET})"
exit 0
fi
echo "[attempt ${i}/${MAX_RETRIES}] current=${current} target=${TARGET} remaining=${remaining}"
if ddev drush genu "$remaining" --pass="$PASS"; then
echo "Batch of ${remaining} succeeded cleanly."
else
echo "Batch failed partway (likely a username collision) -- rechecking count and retrying the remainder."
fi
done
final=$(ddev drush sqlq "SELECT COUNT(*) FROM users_field_data;" | head -1)
echo "ERROR: did not reach target ${TARGET} after ${MAX_RETRIES} attempts (stuck at ${final})" >&2
exit 1