forked from plasmicapp/plasmic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update DB seed code to include teams and feature tiers
Change-Id: I4eebc3035323139a4d30a78ecc43b13acd32b407 GitOrigin-RevId: abda3a0773b55739dc4b9c71d8ccdf41dfc48550
- Loading branch information
Showing
4 changed files
with
242 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
// environment we're running in. | ||
import { spawn } from "@/wab/common"; | ||
import { DEFAULT_DATABASE_URI } from "@/wab/server/config"; | ||
import { FeatureTier, User } from "@/wab/server/entities/Entities"; | ||
import { PlumePkgMgr } from "@/wab/server/pkgs/plume-pkg-mgr"; | ||
import { initializeGlobals } from "@/wab/server/svr-init"; | ||
import { Bundler } from "@/wab/shared/bundler"; | ||
|
@@ -14,7 +15,52 @@ import { DbMgr, normalActor, SUPER_USER } from "./DbMgr"; | |
|
||
initializeGlobals(); | ||
|
||
async function createFakeUser( | ||
if (require.main === module) { | ||
spawn(main()); | ||
} | ||
|
||
async function main() { | ||
const con = await ensureDbConnection(DEFAULT_DATABASE_URI, "default"); | ||
await con.transaction(async (em) => { | ||
await initDb(em); | ||
await seedTestDb(em); | ||
console.log("done"); | ||
}); | ||
} | ||
|
||
async function seedTestDb(em: EntityManager) { | ||
const db = new DbMgr(em, SUPER_USER); | ||
const bundler = new Bundler(); | ||
|
||
const { user: adminUser } = await seedTestUserAndProjects(em, bundler, { | ||
email: "[email protected]", | ||
firstName: "Plasmic", | ||
lastName: "Admin", | ||
}); | ||
const { user: user1 } = await seedTestUserAndProjects(em, bundler, { | ||
email: "[email protected]", | ||
firstName: "Plasmic", | ||
lastName: "User", | ||
}); | ||
const { user: user2 } = await seedTestUserAndProjects(em, bundler, { | ||
email: "[email protected]", | ||
firstName: "Plasmic", | ||
lastName: "User 2", | ||
}); | ||
|
||
const { enterpriseFt, teamFt, proFt, starterFt } = await seedTestFeatureTiers( | ||
em | ||
); | ||
await seedTeam(em, user1, "Test Enterprise Org", enterpriseFt); | ||
await seedTeam(em, user1, "Test Scale Org", teamFt); | ||
await seedTeam(em, user2, "Test Pro Org", proFt); | ||
await seedTeam(em, user2, "Test Starter Org", starterFt); | ||
|
||
// Seed the Plume pkg, which must be done after some users have been created | ||
await new PlumePkgMgr(db).seedPlumePkg(); | ||
} | ||
|
||
async function seedTestUserAndProjects( | ||
em: EntityManager, | ||
bundler: Bundler, | ||
userInfo: { | ||
|
@@ -50,8 +96,8 @@ async function createFakeUser( | |
revisionNum: 2, | ||
seqIdAssign: undefined, | ||
}); | ||
const latest = await db.getLatestProjectRev(project.id); | ||
console.log(latest); | ||
await db.getLatestProjectRev(project.id); | ||
|
||
// Need to set this back to the normal placeholder. | ||
const site = createSite(); | ||
const siteBundle = bundler.bundle(site, "", await getLastBundleVersion()); | ||
|
@@ -64,42 +110,148 @@ async function createFakeUser( | |
} | ||
|
||
const projects = await db.listProjectsForSelf(); | ||
return { user, projects }; | ||
} | ||
|
||
export async function createDummyDb(em: EntityManager) { | ||
const db = new DbMgr(em, SUPER_USER); | ||
const bundler = new Bundler(); | ||
console.log( | ||
`Inserted user id=${user.id} email=${ | ||
user.email | ||
} with projects ids=${projects.map((p) => p.id).join(",")}` | ||
); | ||
|
||
await createFakeUser(em, bundler, { | ||
email: "[email protected]", | ||
firstName: "Plasmic", | ||
lastName: "Admin", | ||
}); | ||
await createFakeUser(em, bundler, { | ||
email: "[email protected]", | ||
firstName: "Plasmic", | ||
lastName: "User", | ||
}); | ||
await createFakeUser(em, bundler, { | ||
email: "[email protected]", | ||
firstName: "Plasmic", | ||
lastName: "User 2", | ||
}); | ||
return { user, projects }; | ||
} | ||
|
||
// Seed the Plume pkg, which must be done after some users have been created | ||
await new PlumePkgMgr(db).seedPlumePkg(); | ||
/** | ||
* These feature tiers have Stripe IDs that map to our Stripe testmode account. | ||
* See docs/contributing/platform/02-integrations.md | ||
*/ | ||
async function seedTestFeatureTiers(em: EntityManager) { | ||
const db0 = new DbMgr(em, SUPER_USER); | ||
return { | ||
enterpriseFt: await db0.addFeatureTier({ | ||
name: "Enterprise", | ||
monthlyBasePrice: null, | ||
monthlyBaseStripePriceId: null, | ||
annualBasePrice: null, | ||
annualBaseStripePriceId: null, | ||
monthlySeatPrice: 80, | ||
monthlySeatStripePriceId: "price_1Ji3EFHIopbCiFeiUCtiVOyB", | ||
annualSeatPrice: 768, | ||
annualSeatStripePriceId: "price_1Ji3EFHIopbCiFeiSj0U8o1K", | ||
minUsers: 30, | ||
maxUsers: 1_000, | ||
maxWorkspaces: 10_000, | ||
monthlyViews: 1_000_000, | ||
versionHistoryDays: 180, | ||
analytics: true, | ||
contentRole: true, | ||
designerRole: true, | ||
editContentCreatorMode: true, | ||
localization: true, | ||
splitContent: true, | ||
privateUsersIncluded: null, | ||
maxPrivateUsers: null, | ||
publicUsersIncluded: null, | ||
maxPublicUsers: null, | ||
}), | ||
teamFt: await db0.addFeatureTier({ | ||
name: "Team", | ||
monthlyBasePrice: 499, | ||
monthlyBaseStripePriceId: "price_1N9VlSHIopbCiFeiTU6RyL48", | ||
annualBasePrice: 4_788, | ||
annualBaseStripePriceId: "price_1N9VlSHIopbCiFeibn88Ezt0", | ||
monthlySeatPrice: 40, | ||
monthlySeatStripePriceId: "price_1N9VlxHIopbCiFeiLf3ngIwB", | ||
annualSeatPrice: 384, | ||
annualSeatStripePriceId: "price_1N9VlxHIopbCiFeicxycQNAp", | ||
minUsers: 8, | ||
maxUsers: 30, | ||
maxWorkspaces: 300, | ||
monthlyViews: 500_000, | ||
versionHistoryDays: 180, | ||
analytics: true, | ||
contentRole: true, | ||
designerRole: true, | ||
editContentCreatorMode: true, | ||
localization: true, | ||
splitContent: true, | ||
privateUsersIncluded: null, | ||
maxPrivateUsers: null, | ||
publicUsersIncluded: null, | ||
maxPublicUsers: null, | ||
}), | ||
proFt: await db0.addFeatureTier({ | ||
name: "Pro", | ||
monthlyBasePrice: 129, | ||
monthlyBaseStripePriceId: "price_1N9VkLHIopbCiFeiSChtf6dV", | ||
annualBasePrice: 1_236, | ||
annualBaseStripePriceId: "price_1N9VkLHIopbCiFeiFsiEryvl", | ||
monthlySeatPrice: 20, | ||
monthlySeatStripePriceId: "price_1N9VkpHIopbCiFeiNptqZ2BR", | ||
annualSeatPrice: 192, | ||
annualSeatStripePriceId: "price_1N9VkpHIopbCiFeiMi50AFEk", | ||
minUsers: 4, | ||
maxUsers: 10, | ||
maxWorkspaces: 100, | ||
monthlyViews: 250_000, | ||
versionHistoryDays: 90, | ||
analytics: false, | ||
contentRole: false, | ||
designerRole: false, | ||
editContentCreatorMode: false, | ||
localization: false, | ||
splitContent: false, | ||
privateUsersIncluded: null, | ||
maxPrivateUsers: null, | ||
publicUsersIncluded: null, | ||
maxPublicUsers: null, | ||
}), | ||
starterFt: await db0.addFeatureTier({ | ||
name: "Starter", | ||
monthlyBasePrice: 49, | ||
monthlyBaseStripePriceId: "price_1N9VirHIopbCiFeicbMYaVhb", | ||
annualBasePrice: 468, | ||
annualBaseStripePriceId: "price_1N9VirHIopbCiFeiPRRXpINo", | ||
monthlySeatPrice: 0, | ||
monthlySeatStripePriceId: "price_1N9VjhHIopbCiFeic0V8lDJX", | ||
annualSeatPrice: 0, | ||
annualSeatStripePriceId: "price_1N9VjhHIopbCiFeiViCs7zEH", | ||
minUsers: 4, | ||
maxUsers: 10, | ||
maxWorkspaces: 100, | ||
monthlyViews: 250_000, | ||
versionHistoryDays: 90, | ||
analytics: false, | ||
contentRole: false, | ||
designerRole: false, | ||
editContentCreatorMode: false, | ||
localization: false, | ||
splitContent: false, | ||
privateUsersIncluded: null, | ||
maxPrivateUsers: null, | ||
publicUsersIncluded: null, | ||
maxPublicUsers: null, | ||
}), | ||
}; | ||
} | ||
|
||
export async function main() { | ||
const con = await ensureDbConnection(DEFAULT_DATABASE_URI, "default"); | ||
await con.transaction(async (em) => { | ||
await initDb(em); | ||
await createDummyDb(em); | ||
console.log("done"); | ||
async function seedTeam( | ||
em: EntityManager, | ||
user: User, | ||
name: string, | ||
featureTier: FeatureTier | ||
) { | ||
const db = new DbMgr(em, normalActor(user.id)); | ||
let team = await db.createTeam(name); | ||
|
||
const db0 = new DbMgr(em, SUPER_USER); | ||
team = await db0.sudoUpdateTeam({ | ||
id: team.id, | ||
featureTierId: featureTier.id, | ||
}); | ||
} | ||
|
||
if (require.main === module) { | ||
spawn(main()); | ||
console.log( | ||
`Inserted team id=${team.id} name=${team.name} owned by user id=${user.id} email=${user.email} with feature tier id=${featureTier.id} name=${featureTier.name}` | ||
); | ||
|
||
return team; | ||
} |
Oops, something went wrong.