wip: zen black
This commit is contained in:
40
packages/console/core/script/black-onboard-waitlist.ts
Normal file
40
packages/console/core/script/black-onboard-waitlist.ts
Normal file
@@ -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
packages/console/core/script/black-select-workspaces.ts
Normal file
41
packages/console/core/script/black-select-workspaces.ts
Normal file
@@ -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)
|
||||||
|
}
|
||||||
@@ -129,14 +129,17 @@ async function printWorkspace(workspaceID: string) {
|
|||||||
booked: BillingTable.timeSubscriptionBooked,
|
booked: BillingTable.timeSubscriptionBooked,
|
||||||
enrichment: BillingTable.subscription,
|
enrichment: BillingTable.subscription,
|
||||||
},
|
},
|
||||||
|
timeSubscriptionSelected: BillingTable.timeSubscriptionSelected,
|
||||||
})
|
})
|
||||||
.from(BillingTable)
|
.from(BillingTable)
|
||||||
.where(eq(BillingTable.workspaceID, workspace.id))
|
.where(eq(BillingTable.workspaceID, workspace.id))
|
||||||
.then(
|
.then(
|
||||||
(rows) =>
|
(rows) =>
|
||||||
rows.map((row) => ({
|
rows.map((row) => ({
|
||||||
...row,
|
|
||||||
balance: `$${(row.balance / 100000000).toFixed(2)}`,
|
balance: `$${(row.balance / 100000000).toFixed(2)}`,
|
||||||
|
reload: row.reload ? "yes" : "no",
|
||||||
|
customerID: row.customerID,
|
||||||
|
subscriptionID: row.subscriptionID,
|
||||||
subscription: row.subscriptionID
|
subscription: row.subscriptionID
|
||||||
? [
|
? [
|
||||||
`Black ${row.subscription.enrichment!.plan}`,
|
`Black ${row.subscription.enrichment!.plan}`,
|
||||||
@@ -145,7 +148,7 @@ async function printWorkspace(workspaceID: string) {
|
|||||||
`(ref: ${row.subscriptionID})`,
|
`(ref: ${row.subscriptionID})`,
|
||||||
].join(" ")
|
].join(" ")
|
||||||
: row.subscription.booked
|
: row.subscription.booked
|
||||||
? `Waitlist ${row.subscription.plan} plan`
|
? `Waitlist ${row.subscription.plan} plan${row.timeSubscriptionSelected ? " (selected)" : ""}`
|
||||||
: undefined,
|
: undefined,
|
||||||
}))[0],
|
}))[0],
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user