KV to D1 migration (this is totally gonna break something)

This commit is contained in:
2024-05-12 01:25:46 -04:00
parent a2b3391bda
commit e00b7e8c55
24 changed files with 1835 additions and 669 deletions

View File

@ -15,12 +15,15 @@ export async function onRequestPost(context: RequestContext) {
)
return jsonError("No processing report with that ID found", 404);
const data: { [k: string]: any } | null = await context.env.DATA.get(
`report_${id}`,
{ type: "json" },
);
const data: Record<string, any> | null = await context.env.D1.prepare(
"SELECT attachments FROM reports WHERE id = ?;",
)
.bind(id)
.first();
if (!data) return jsonError("Report doesn't exist", 404);
if (!data) return jsonError("No report with that ID found", 404);
data.attachments = JSON.parse(data.attachments);
const accessToken = await GetAccessToken(context.env);
const attachmentDeletePromises = [];
@ -47,7 +50,6 @@ export async function onRequestPost(context: RequestContext) {
);
await Promise.allSettled(attachmentDeletePromises);
await context.env.DATA.delete(`report_${id}`);
await context.env.D1.prepare("DELETE FROM reports WHERE id = ?;")
.bind(id)
.run();