#!/bin/bash
###ALTER TABLE user ADD COLUMN sskey VARCHAR(44) NOT NULL AFTER uuid;


# MySQL credentials
USER="111111"
DATABASE="111111"
PASSWORD='111111'

# Generate a 32-character Base64 encoded random string using openssl
generate_random_base64() {
  openssl rand -base64 32
}

ids=$(mysql -u"$USER" -p"$PASSWORD" -D "$DATABASE" -Bse "SELECT id FROM user WHERE sskey = '';")

echo $ids

# Loop through each id and update the sskey with a random Base64 string
for id in $ids; do
  random_string=$(generate_random_base64)
  mysql -u"$USER" -p"$PASSWORD" -D "$DATABASE" -Bse "UPDATE user SET sskey='$random_string' WHERE id=$id;"
done

echo "Updated rows where sskey was NULL with random Base64 strings."
