From 11cb62626d9675fb6eaf9d85e7487cdc6c267956 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Sun, 1 Oct 2023 16:20:04 +1100 Subject: [PATCH] chore: cleanup DB migration script (#612) This code is no longer needed. --- tasks/db_migrate.ts | 54 --------------------------------------------- 1 file changed, 54 deletions(-) diff --git a/tasks/db_migrate.ts b/tasks/db_migrate.ts index 24c7bde09193..71dd80ec8f61 100644 --- a/tasks/db_migrate.ts +++ b/tasks/db_migrate.ts @@ -12,57 +12,3 @@ * deno task db:migrate * ``` */ -import { - createItem, - createVote, - deleteVote, - type Item, - kv, - User, -} from "@/utils/db.ts"; -import { ulid } from "std/ulid/mod.ts"; - -interface OldItem extends Item { - createdAt: Date; -} - -if (!confirm("WARNING: The database will be migrated. Continue?")) Deno.exit(); - -const iter1 = kv.list({ prefix: ["items"] }); -for await (const oldItemEntry of iter1) { - if (oldItemEntry.value.createdAt) { - const newItem = { - id: ulid(new Date(oldItemEntry.value.createdAt).getTime()), - userLogin: oldItemEntry.value.userLogin, - url: oldItemEntry.value.url, - title: oldItemEntry.value.title, - score: oldItemEntry.value.score, - }; - await createItem(newItem); - const iter2 = kv.list({ - prefix: ["users_voted_for_item", oldItemEntry.value.id], - }); - for await (const userEntry of iter2) { - await deleteVote({ - itemId: oldItemEntry.value.id, - userLogin: userEntry.value.login, - }); - await deleteVote({ - itemId: newItem.id, - userLogin: userEntry.value.login, - }); - await createVote({ - itemId: newItem.id, - userLogin: userEntry.value.login, - }); - } - await kv.delete(oldItemEntry.key); - } -} - -const iter3 = kv.list({ prefix: ["items_by_user"] }); -for await (const { key, value } of iter3) { - if (value.createdAt) await kv.delete(key); -} - -kv.close();