From a4e4ae6a53e37f0fa289eafa71501632718dddbd Mon Sep 17 00:00:00 2001
From: dholms <dtholmgren@gmail.com>
Date: Tue, 7 Nov 2023 15:47:29 -0600
Subject: [PATCH] check failures script

---
 .../pds/src/migrate-script/check-failures.ts  | 63 +++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 packages/pds/src/migrate-script/check-failures.ts

diff --git a/packages/pds/src/migrate-script/check-failures.ts b/packages/pds/src/migrate-script/check-failures.ts
new file mode 100644
index 00000000000..266410a1886
--- /dev/null
+++ b/packages/pds/src/migrate-script/check-failures.ts
@@ -0,0 +1,63 @@
+import { countAll } from '../db/util'
+import { MigrateDb, getDb } from './db'
+
+const run = async () => {
+  const db = getDb()
+  const results = await Promise.all([
+    totalCount(db),
+    failureCount(db),
+    failedBlobs(db),
+    failedPrefs(db),
+    failedTakedowns(db),
+  ])
+  console.log(`
+Total migrations: ${results[0]}
+Failed migrations: ${results[1]}
+Failed blobs: ${results[2]}
+Failed prefs: ${results[3]}
+Failed takedowns: ${results[4]}
+`)
+}
+
+const totalCount = async (db: MigrateDb) => {
+  const res = await db
+    .selectFrom('status')
+    .select(countAll.as('count'))
+    .executeTakeFirst()
+  return res?.count
+}
+
+const failureCount = async (db: MigrateDb) => {
+  const res = await db
+    .selectFrom('status')
+    .select(countAll.as('count'))
+    .where('failed', '=', 1)
+    .executeTakeFirst()
+  return res?.count
+}
+
+const failedBlobs = async (db: MigrateDb) => {
+  const res = await db
+    .selectFrom('failed_blob')
+    .select(countAll.as('count'))
+    .executeTakeFirst()
+  return res?.count
+}
+
+const failedPrefs = async (db: MigrateDb) => {
+  const res = await db
+    .selectFrom('failed_pref')
+    .select(countAll.as('count'))
+    .executeTakeFirst()
+  return res?.count
+}
+
+const failedTakedowns = async (db: MigrateDb) => {
+  const res = await db
+    .selectFrom('failed_takedown')
+    .select(countAll.as('count'))
+    .executeTakeFirst()
+  return res?.count
+}
+
+run()