Parcourir la source

wip: zen black

Frank il y a 4 semaines
Parent
commit
c0dc8ea39e

+ 40 - 0
packages/console/core/script/black-onboard-waitlist.ts

@@ -0,0 +1,40 @@
+import { subscribe } from "diagnostics_channel"
+import { Billing } from "../src/billing.js"
+import { and, Database, eq } from "../src/drizzle/index.js"
+import { BillingTable, PaymentTable, SubscriptionTable } from "../src/schema/billing.sql.js"
+
+const workspaceID = process.argv[2]
+
+if (!workspaceID) {
+  console.error("Usage: bun script/foo.ts <workspaceID>")
+  process.exit(1)
+}
+
+console.log(`Onboarding to Black waitlist`)
+
+const billing = await Database.use((tx) =>
+  tx
+    .select({
+      subscriptionPlan: BillingTable.subscriptionPlan,
+      timeSubscriptionBooked: BillingTable.timeSubscriptionBooked,
+    })
+    .from(BillingTable)
+    .where(eq(BillingTable.workspaceID, workspaceID))
+    .then((rows) => rows[0]),
+)
+
+if (!billing?.timeSubscriptionBooked) {
+  console.error(`Error: Workspace is not on the waitlist`)
+  process.exit(1)
+}
+
+await Database.use((tx) =>
+  tx
+    .update(BillingTable)
+    .set({
+      timeSubscriptionSelected: new Date(),
+    })
+    .where(eq(BillingTable.workspaceID, workspaceID)),
+)
+
+console.log(`Done`)

+ 41 - 0
packages/console/core/script/black-select-workspaces.ts

@@ -0,0 +1,41 @@
+import { Database, eq, and, sql, inArray, isNull, count } from "../src/drizzle/index.js"
+import { BillingTable, SubscriptionPlan } from "../src/schema/billing.sql.js"
+import { UserTable } from "../src/schema/user.sql.js"
+import { AuthTable } from "../src/schema/auth.sql.js"
+
+const plan = process.argv[2] as typeof SubscriptionPlan[number]
+if (!SubscriptionPlan.includes(plan)) {
+  console.error("Usage: bun foo.ts <count>")
+  process.exit(1)
+}
+
+const workspaces = await Database.use((tx) =>
+  tx
+    .select({ workspaceID: BillingTable.workspaceID })
+    .from(BillingTable)
+    .where(and(eq(BillingTable.subscriptionPlan, plan), isNull(BillingTable.timeSubscriptionSelected)))
+    .orderBy(sql`RAND()`)
+    .limit(100),
+)
+
+console.log(`Found ${workspaces.length} workspaces on Black ${plan} waitlist`)
+
+console.log("== Workspace IDs ==")
+const ids = workspaces.map((w) => w.workspaceID)
+for (const id of ids) {
+  console.log(id)
+}
+
+console.log("\n== User Emails ==")
+const emails = await Database.use((tx) =>
+  tx
+    .select({ email: AuthTable.subject })
+    .from(UserTable)
+    .innerJoin(AuthTable, and(eq(UserTable.accountID, AuthTable.accountID), eq(AuthTable.provider, "email")))
+    .where(inArray(UserTable.workspaceID, ids)),
+)
+
+const unique = new Set(emails.map((row) => row.email))
+for (const email of unique) {
+  console.log(email)
+}

+ 5 - 2
packages/console/core/script/lookup-user.ts

@@ -129,14 +129,17 @@ async function printWorkspace(workspaceID: string) {
           booked: BillingTable.timeSubscriptionBooked,
           enrichment: BillingTable.subscription,
         },
+        timeSubscriptionSelected: BillingTable.timeSubscriptionSelected,
       })
       .from(BillingTable)
       .where(eq(BillingTable.workspaceID, workspace.id))
       .then(
         (rows) =>
           rows.map((row) => ({
-            ...row,
             balance: `$${(row.balance / 100000000).toFixed(2)}`,
+            reload: row.reload ? "yes" : "no",
+            customerID: row.customerID,
+            subscriptionID: row.subscriptionID,
             subscription: row.subscriptionID
               ? [
                   `Black ${row.subscription.enrichment!.plan}`,
@@ -145,7 +148,7 @@ async function printWorkspace(workspaceID: string) {
                   `(ref: ${row.subscriptionID})`,
                 ].join(" ")
               : row.subscription.booked
-                ? `Waitlist ${row.subscription.plan} plan`
+                ? `Waitlist ${row.subscription.plan} plan${row.timeSubscriptionSelected ? " (selected)" : ""}`
                 : undefined,
           }))[0],
       ),