Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: delete dummy data #307

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions tools/migrate_kv.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
import { type Item, kv } from "@/utils/db.ts";
import {
deleteComment,
deleteItem,
getCommentsByItem,
getItem,
kv,
} from "@/utils/db.ts";

export async function migrateKv() {
const iter = kv.list<Item>({ prefix: ["items_by_time"] });
const itemIds = [
"58306d42-c17c-448c-aba0-31e43f68ca03",
"588169af-73e3-4383-a98b-257d4a20d9fd",
"7c05abda-67dd-4d11-a98e-6c03bf4a74b7",
"8d9f15a8-10b8-43e4-b3d5-0714ae585cc2",
"a3fa1164-28a3-461e-be5d-8625eb55e760",
"b11890b5-851e-4ba7-8f13-1befd0e43c46",
"e1416f18-f3a0-41d5-ae17-388b5d257aac",
"33c0a21d-752b-4222-9b92-8c20efa1e644",
"19299bbe-f508-4115-b105-892978271493",
"5b3a0604-8f9e-46cc-9653-ea376a7f13df",
"15d30182-fbb9-4385-a23b-70ce3dcb27ee",
"7c47b301-17b5-4864-b7c5-e970d428877f",
"d8358836-305c-4221-ab20-ca928095011a",
];
const promises = [];
for await (const res of iter) {
promises.push(kv.set(["items", res.value.id], res.value));
for (const itemId of itemIds) {
const item = await getItem(itemId);
if (item === null) break;
promises.push(deleteItem(item));

const comments = await getCommentsByItem(itemId);
for (const comment of comments) {
promises.push(deleteComment(comment));
}
}
await Promise.all(promises);
}
Expand Down