fix: better D1 error handling in migration

pull/177/head
lyc8503 2026-01-03 23:56:29 +08:00
parent e2ff649ebd
commit 821beb2a87
1 changed files with 16 additions and 12 deletions

View File

@ -78,17 +78,21 @@ r = requests.post(
}
).json()
if r['success'] :
print("State migrated to D1 successfully. Trying to delete unused KV namespace...")
r = requests.delete(
api_endpoint + f"/storage/kv/namespaces/{kv_id}",
headers=headers
).json()
if r['success']:
print("KV namespace deleted successfully.")
if not r['success']:
# UNIQUE constraint failed: uptimeflare.key: SQLITE_CONSTRAINT
if r['errors'][0]['code'] == 7500 and "UNIQUE" in r['errors'][0]['message']:
print("State probably already migrated to D1. Migration skipped.")
else:
print("Error deleting KV namespace: ", r)
print("Error writing state to D1: ", r)
print("Migration failed. Please report this issue at https://github.com/lyc8503/UptimeFlare/issues.")
exit(1)
print("State migrated to D1 successfully. Trying to delete unused KV namespace...")
r = requests.delete(
api_endpoint + f"/storage/kv/namespaces/{kv_id}",
headers=headers
).json()
if r['success']:
print("KV namespace deleted successfully.")
else:
print("Error writing state to D1: ", r)
print("Migration failed. Please report this issue at https://github.com/lyc8503/UptimeFlare/issues.")
exit(1)
print("Error deleting KV namespace: ", r)