fix: better D1 error handling in migration
parent
e2ff649ebd
commit
821beb2a87
|
|
@ -78,17 +78,21 @@ r = requests.post(
|
||||||
}
|
}
|
||||||
).json()
|
).json()
|
||||||
|
|
||||||
if r['success'] :
|
if not r['success']:
|
||||||
print("State migrated to D1 successfully. Trying to delete unused KV namespace...")
|
# UNIQUE constraint failed: uptimeflare.key: SQLITE_CONSTRAINT
|
||||||
r = requests.delete(
|
if r['errors'][0]['code'] == 7500 and "UNIQUE" in r['errors'][0]['message']:
|
||||||
api_endpoint + f"/storage/kv/namespaces/{kv_id}",
|
print("State probably already migrated to D1. Migration skipped.")
|
||||||
headers=headers
|
|
||||||
).json()
|
|
||||||
if r['success']:
|
|
||||||
print("KV namespace deleted successfully.")
|
|
||||||
else:
|
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:
|
else:
|
||||||
print("Error writing state to D1: ", r)
|
print("Error deleting KV namespace: ", r)
|
||||||
print("Migration failed. Please report this issue at https://github.com/lyc8503/UptimeFlare/issues.")
|
|
||||||
exit(1)
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue