Skip to content

Commit

Permalink
chore: cleanup DB migration script (denoland#612)
Browse files Browse the repository at this point in the history
This code is no longer needed.
  • Loading branch information
iuioiua authored Oct 1, 2023
1 parent 1b8cdbd commit 11cb626
Showing 1 changed file with 0 additions and 54 deletions.
54 changes: 0 additions & 54 deletions tasks/db_migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<OldItem>({ 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<User>({
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<OldItem>({ prefix: ["items_by_user"] });
for await (const { key, value } of iter3) {
if (value.createdAt) await kv.delete(key);
}

kv.close();

0 comments on commit 11cb626

Please sign in to comment.