Skip to content

Commit

Permalink
Update DB seed code to include teams and feature tiers
Browse files Browse the repository at this point in the history
Change-Id: I4eebc3035323139a4d30a78ecc43b13acd32b407
GitOrigin-RevId: abda3a0773b55739dc4b9c71d8ccdf41dfc48550
  • Loading branch information
jaslong authored and Copybara committed Mar 7, 2024
1 parent 4c17cd9 commit a3ed3b5
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 106 deletions.
72 changes: 19 additions & 53 deletions docs/contributing/platform/02-integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ a project on Google Developers Console.
- First click on the "OAuth consent screen". Fill in the required fields, and for scopes,
make sure "email", "profile", "openid" are included (should be by default).
- Next, click on the "Credentials tab"
- Select "Create credentials", and choose "OAuth Client ID".
- Application type: "Web application"
- Name: <whatever you want>
- Authorized Javascript origins: [http://localhost:3003]
- Authorized redirect URIs: [http://localhost:3003/api/v1/oauth2/google/callback]
- Select "Create credentials", and choose "OAuth Client ID".
- Application type: "Web application"
- Name: <whatever you want>
- Authorized Javascript origins: [http://localhost:3003]
- Authorized redirect URIs: [http://localhost:3003/api/v1/oauth2/google/callback]
- Save the client ID and secret in your `~/.plasmic/secrets.json`. It should look like:
```json
{
Expand All @@ -42,18 +42,18 @@ a project on Google Developers Console.
- Sign in to GitHub with your personal account and go to
[GitHub Developer Settings](https://github.com/settings/apps).
- Create a new GitHub App with the following information:
- Homepage URL: http://localhost:3003
- Callback URL: http://localhost:3003/github/callback
- Uncheck "Expire user authorization tokens"
- Check "Request user authorization (OAuth) during installation"
- Deactivate webhook
- Repository permissions:
- Actions: Read & write
- Administration: Read & write
- Contents: Read & write
- Pages: Read & write
- Pull requests: Read & write
- Workflows: Read & write
- Homepage URL: http://localhost:3003
- Callback URL: http://localhost:3003/github/callback
- Uncheck "Expire user authorization tokens"
- Check "Request user authorization (OAuth) during installation"
- Deactivate webhook
- Repository permissions:
- Actions: Read & write
- Administration: Read & write
- Contents: Read & write
- Pages: Read & write
- Pull requests: Read & write
- Workflows: Read & write
- Click on "Edit" in the app you created and generate/store a client secret
and a private key.
- Fill the following fields in your ~/.plasmic/secrets.json:
Expand Down Expand Up @@ -110,7 +110,7 @@ Potentially, you can also amend the resulting package.json (in the repo that get

## Setting up billing (Stripe)

To set up billing locally, add Stripe test secret key (https://dashboard.stripe.com/test/apikeys) to secrets.json:
To test billing locally, add Stripe test secret key (https://dashboard.stripe.com/test/apikeys) to secrets.json:

```json
{
Expand All @@ -120,40 +120,6 @@ To set up billing locally, add Stripe test secret key (https://dashboard.stripe.
}
```

Then add "Basic" and "Growth" feature tiers to your local Postgres database by running:

```sql
INSERT INTO feature_tier (
"id", "createdAt", "updatedAt", "name", "monthlySeatPrice",
"monthlySeatStripePriceId", "annualSeatPrice", "annualSeatStripePriceId",
"maxUsers", "versionHistoryDays", "designerRole", "contentRole"
) VALUES (
gen_random_uuid(), now(), now(), 'Basic', 15,
'price_1JKnrcHIopbCiFeifoHWd1h2', 144,
'price_1JLFtRHIopbCiFeiWxfflHKB', 10, 90, true, false
);

INSERT INTO feature_tier (
"id", "createdAt", "updatedAt", "name", "monthlySeatPrice",
"monthlySeatStripePriceId", "annualSeatPrice", "annualSeatStripePriceId",
"maxUsers", "versionHistoryDays", "designerRole", "contentRole"
) VALUES (
gen_random_uuid(), now(), now(), 'Growth', 40,
'price_1JLFu9HIopbCiFeiSZxQrGiI', 384,
'price_1JLFuIHIopbCiFeiRc7HOmiM', 30, 90, true, true
);

INSERT INTO feature_tier (
"id", "createdAt", "updatedAt", "name", "monthlySeatPrice",
"monthlySeatStripePriceId", "annualSeatPrice", "annualSeatStripePriceId",
"maxUsers", "versionHistoryDays", "designerRole", "contentRole"
) VALUES (
gen_random_uuid(), now(), now(), 'Enterprise', 80,
'price_1Ji3EFHIopbCiFeiUCtiVOyB', 768,
'price_1Ji3EFHIopbCiFeiSj0U8o1K', 1000, 90, true, true
);
```

## Setting up Google Sheets

Have a GCloud account, Sheets API enabled, OAuth consent screen.
Expand All @@ -172,4 +138,4 @@ Save into secrets.json:
"clientSecret": "<CLIENT_SECRET>"
}
}
```
```
220 changes: 186 additions & 34 deletions platform/wab/src/wab/server/db/DbInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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: {
Expand Down Expand Up @@ -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());
Expand All @@ -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;
}
Loading

0 comments on commit a3ed3b5

Please sign in to comment.