Skip to content

Commit 02a1f71

Browse files
authored
chore: seed for creating an organization with many members and projects (#7294)
1 parent 6f4861a commit 02a1f71

File tree

6 files changed

+61
-5
lines changed

6 files changed

+61
-5
lines changed

docs/DEVELOPMENT.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ We have a script to feed your local instance of Hive with initial seed data. Thi
110110

111111
1. Use `Start Hive` to run your local Hive instance
112112
2. Make sure `usage` and `usage-ingestor` are running as well (with `pnpm dev`)
113-
3. Open Hive app, create a project and a target, then create a token
114-
4. Run the seed script: `FEDERATION=<0|1> TOKEN=<access_token> TARGET=<target_id> pnpm seed:schemas`
115-
5. This should report a dummy schema
116-
6. Run the usage seed to generate some dummy usage data to your local instance of Hive, allowing you
113+
3. (Optional) Seed a organization with many projects and users `pnpm seed:org`
114+
4. Open Hive app, create a project and a target, then create a token (or use the previously created
115+
one)
116+
5. Run the seed script: `FEDERATION=<0|1> TOKEN=<access_token> TARGET=<target_id> pnpm seed:schemas`
117+
6. This should report a dummy schema
118+
7. Run the usage seed to generate some dummy usage data to your local instance of Hive, allowing you
117119
to test features e2e: `FEDERATION=<0|1> TOKEN=<access_token> TARGET=<target_id> pnpm seed:usage`
118120

119121
> Note: You can set `STAGE=<dev|staging|local>` in order to target a specific Hive environment and

integration-tests/local-dev.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ function applyEnv(env: Record<string, string>) {
77
}
88
}
99

10-
const serverEnvVars = parse(readFileSync('../packages/services/server/.env', 'utf-8'));
10+
const __dirname = import.meta.dirname;
11+
12+
const serverEnvVars = parse(readFileSync(__dirname + '/../packages/services/server/.env', 'utf-8'));
1113

1214
applyEnv({
1315
SUPERTOKENS_CONNECTION_URI: serverEnvVars.SUPERTOKENS_CONNECTION_URI,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"prettier": "prettier --cache --write --list-different --ignore-unknown \"**/*\"",
4444
"release": "pnpm build:libraries && changeset publish",
4545
"release:version": "changeset version && pnpm --filter hive-apollo-router-plugin --filter hive-console-sdk-rs sync-cargo-file && pnpm build:libraries && pnpm --filter @graphql-hive/cli oclif:readme",
46+
"seed:org": "tsx scripts/seed-organization.mts",
4647
"seed:schemas": "tsx scripts/seed-schemas.ts",
4748
"seed:usage": "tsx scripts/seed-usage.ts",
4849
"start": "pnpm run local:setup",

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"devDependencies": {
66
"@faker-js/faker": "9.9.0",
77
"@graphql-hive/core": "workspace:*",
8+
"@supercharge/promise-pool": "3.2.0",
89
"immer": "10.1.1"
910
}
1011
}

scripts/seed-organization.mts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Script for seeding an org with lot of projects and users.
3+
*
4+
* Requirements:
5+
* - Docker Compose is started (pnpm start)
6+
* - emails, app and server service is running
7+
*
8+
* Recommended method of running this :
9+
* `bun scripts/seed-organization.mts`
10+
*
11+
* Afterwards, log in with the printed credentials.
12+
*/
13+
import { PromisePool } from '@supercharge/promise-pool';
14+
15+
process.env.RUN_AGAINST_LOCAL_SERVICES = '1';
16+
await import('../integration-tests/local-dev.ts');
17+
const { initSeed } = await import('../integration-tests/testkit/seed');
18+
19+
const seed = initSeed();
20+
21+
const owner = await seed.createOwner();
22+
const password = 'ilikebigturtlesandicannotlie47';
23+
24+
const org = await owner.createOrg();
25+
26+
console.log('Create 100 projects');
27+
await PromisePool.withConcurrency(10)
28+
.for(new Array(100).fill(null))
29+
.process(() => org.createProject());
30+
31+
console.log('Create 200 orgainzation members');
32+
await PromisePool.withConcurrency(10)
33+
.for(new Array(100).fill(null))
34+
.process(() => org.inviteAndJoinMember());
35+
36+
console.log(`
37+
Seed User Credentials:
38+
39+
Email: ${owner.ownerEmail}
40+
Password: ${password}
41+
`);

0 commit comments

Comments
 (0)