Skip to content

Commit c0dc8ea

Browse files
committed
wip: zen black
1 parent 077ebdb commit c0dc8ea

3 files changed

Lines changed: 86 additions & 2 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { subscribe } from "diagnostics_channel"
2+
import { Billing } from "../src/billing.js"
3+
import { and, Database, eq } from "../src/drizzle/index.js"
4+
import { BillingTable, PaymentTable, SubscriptionTable } from "../src/schema/billing.sql.js"
5+
6+
const workspaceID = process.argv[2]
7+
8+
if (!workspaceID) {
9+
console.error("Usage: bun script/foo.ts <workspaceID>")
10+
process.exit(1)
11+
}
12+
13+
console.log(`Onboarding to Black waitlist`)
14+
15+
const billing = await Database.use((tx) =>
16+
tx
17+
.select({
18+
subscriptionPlan: BillingTable.subscriptionPlan,
19+
timeSubscriptionBooked: BillingTable.timeSubscriptionBooked,
20+
})
21+
.from(BillingTable)
22+
.where(eq(BillingTable.workspaceID, workspaceID))
23+
.then((rows) => rows[0]),
24+
)
25+
26+
if (!billing?.timeSubscriptionBooked) {
27+
console.error(`Error: Workspace is not on the waitlist`)
28+
process.exit(1)
29+
}
30+
31+
await Database.use((tx) =>
32+
tx
33+
.update(BillingTable)
34+
.set({
35+
timeSubscriptionSelected: new Date(),
36+
})
37+
.where(eq(BillingTable.workspaceID, workspaceID)),
38+
)
39+
40+
console.log(`Done`)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Database, eq, and, sql, inArray, isNull, count } from "../src/drizzle/index.js"
2+
import { BillingTable, SubscriptionPlan } from "../src/schema/billing.sql.js"
3+
import { UserTable } from "../src/schema/user.sql.js"
4+
import { AuthTable } from "../src/schema/auth.sql.js"
5+
6+
const plan = process.argv[2] as typeof SubscriptionPlan[number]
7+
if (!SubscriptionPlan.includes(plan)) {
8+
console.error("Usage: bun foo.ts <count>")
9+
process.exit(1)
10+
}
11+
12+
const workspaces = await Database.use((tx) =>
13+
tx
14+
.select({ workspaceID: BillingTable.workspaceID })
15+
.from(BillingTable)
16+
.where(and(eq(BillingTable.subscriptionPlan, plan), isNull(BillingTable.timeSubscriptionSelected)))
17+
.orderBy(sql`RAND()`)
18+
.limit(100),
19+
)
20+
21+
console.log(`Found ${workspaces.length} workspaces on Black ${plan} waitlist`)
22+
23+
console.log("== Workspace IDs ==")
24+
const ids = workspaces.map((w) => w.workspaceID)
25+
for (const id of ids) {
26+
console.log(id)
27+
}
28+
29+
console.log("\n== User Emails ==")
30+
const emails = await Database.use((tx) =>
31+
tx
32+
.select({ email: AuthTable.subject })
33+
.from(UserTable)
34+
.innerJoin(AuthTable, and(eq(UserTable.accountID, AuthTable.accountID), eq(AuthTable.provider, "email")))
35+
.where(inArray(UserTable.workspaceID, ids)),
36+
)
37+
38+
const unique = new Set(emails.map((row) => row.email))
39+
for (const email of unique) {
40+
console.log(email)
41+
}

packages/console/core/script/lookup-user.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,17 @@ async function printWorkspace(workspaceID: string) {
129129
booked: BillingTable.timeSubscriptionBooked,
130130
enrichment: BillingTable.subscription,
131131
},
132+
timeSubscriptionSelected: BillingTable.timeSubscriptionSelected,
132133
})
133134
.from(BillingTable)
134135
.where(eq(BillingTable.workspaceID, workspace.id))
135136
.then(
136137
(rows) =>
137138
rows.map((row) => ({
138-
...row,
139139
balance: `$${(row.balance / 100000000).toFixed(2)}`,
140+
reload: row.reload ? "yes" : "no",
141+
customerID: row.customerID,
142+
subscriptionID: row.subscriptionID,
140143
subscription: row.subscriptionID
141144
? [
142145
`Black ${row.subscription.enrichment!.plan}`,
@@ -145,7 +148,7 @@ async function printWorkspace(workspaceID: string) {
145148
`(ref: ${row.subscriptionID})`,
146149
].join(" ")
147150
: row.subscription.booked
148-
? `Waitlist ${row.subscription.plan} plan`
151+
? `Waitlist ${row.subscription.plan} plan${row.timeSubscriptionSelected ? " (selected)" : ""}`
149152
: undefined,
150153
}))[0],
151154
),

0 commit comments

Comments
 (0)