duplicate ip fix
This commit is contained in:
parent
2bd01fb3fc
commit
5c06c43457
@ -769,36 +769,24 @@ spec:
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get or create app_id
|
# Get or create app_id (using INSERT ... ON DUPLICATE KEY UPDATE for idempotency)
|
||||||
|
echo " Ensuring app entry exists for: $app_name"
|
||||||
|
run_mysql "INSERT INTO apps (name, token, creation_date, last_update, is_deleted) VALUES ('$app_name', UUID(), NOW(), NOW(), 0) ON DUPLICATE KEY UPDATE last_update=NOW()"
|
||||||
|
|
||||||
APP_ID=$(run_mysql "SELECT id FROM apps WHERE name='$app_name'")
|
APP_ID=$(run_mysql "SELECT id FROM apps WHERE name='$app_name'")
|
||||||
|
|
||||||
if [ -z "$APP_ID" ]; then
|
if [ -z "$APP_ID" ]; then
|
||||||
echo " Creating app entry for: $app_name"
|
echo " Failed to get app_id for: $app_name"
|
||||||
if run_mysql "INSERT INTO apps (name, token, creation_date, last_update, is_deleted) VALUES ('$app_name', UUID(), NOW(), NOW(), 0)"; then
|
return 1
|
||||||
APP_ID=$(run_mysql "SELECT id FROM apps WHERE name='$app_name'")
|
|
||||||
echo " Created app with ID: $APP_ID"
|
|
||||||
else
|
|
||||||
echo " Failed to create app entry for: $app_name"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
echo " Using app_id: $APP_ID"
|
||||||
|
|
||||||
if [ -n "$APP_ID" ]; then
|
# Register IP (using INSERT IGNORE to handle duplicates gracefully)
|
||||||
# Check if IP already exists
|
echo " Registering IP $ip for app $app_name (app_id: $APP_ID)"
|
||||||
EXISTING=$(run_mysql "SELECT id FROM app_ips_accesses WHERE app_id=$APP_ID AND ipaddress='$ip'")
|
if run_mysql "INSERT IGNORE INTO app_ips_accesses (app_id, ipaddress, creation_date, last_update, is_deleted) VALUES ($APP_ID, '$ip', NOW(), NOW(), 0)"; then
|
||||||
|
echo " Successfully registered IP $ip"
|
||||||
if [ -z "$EXISTING" ]; then
|
|
||||||
echo " Registering IP $ip for app $app_name (app_id: $APP_ID)"
|
|
||||||
if run_mysql "INSERT INTO app_ips_accesses (app_id, ipaddress, creation_date, last_update, is_deleted) VALUES ($APP_ID, '$ip', NOW(), NOW(), 0)"; then
|
|
||||||
echo " Successfully registered IP $ip"
|
|
||||||
else
|
|
||||||
echo " Failed to register IP $ip"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo " IP $ip already registered for $app_name"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo " Could not get APP_ID for $app_name"
|
echo " Failed to register IP $ip"
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user