Skip to content

Commit fa52007

Browse files
authored
Merge pull request #38 from uwblueprint/emma/seed-dev-database-with-platform-signups
Seed Dev Database With Platform Signups
2 parents f145d1a + 5858676 commit fa52007

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ TypeScript backend and frontend:
138138
docker exec -it scv2_ts_backend /bin/bash -c "yarn test"
139139
```
140140

141+
### Seeding the Database
142+
1. Make sure your seeding script is named "seed.ts" and under backend/typescript/prisma
143+
2. Go into our scv2_ts_backend docker container
144+
3. Go to "Files" - ".env"
145+
4. Open file editor
146+
5. Change the "test" in the database URL to "development" to populate the development collection
147+
6. Run the container
148+
7. Go to "Exec"
149+
8. Type in npx prisma db seed -- --environment development
150+
141151
## Updating Documentation
142152

143153
To update documentation, checkout the `gh-pages` branch:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Prisma, PrismaClient, Status } from "@prisma/client";
2+
3+
const prisma = new PrismaClient();
4+
5+
async function main() {
6+
const platformSignupPromises: Promise<Prisma.platformSignUpCreateInput>[] = [];
7+
8+
const users = await prisma.user.findMany();
9+
10+
// Check if there are users to associate with platform signups
11+
if (users.length === 0) {
12+
throw new Error("No users found for seeding platform signups");
13+
}
14+
15+
const platformSignups: Prisma.platformSignUpCreateInput[] = [];
16+
users.forEach((user) => {
17+
platformSignups.push({
18+
email: user.email,
19+
firstName: user.firstName,
20+
lastName: user.lastName,
21+
status: Status.PENDING,
22+
});
23+
});
24+
25+
platformSignups.forEach((signupRequest) => {
26+
platformSignupPromises.push(
27+
prisma.platformSignUp.create({
28+
data: signupRequest,
29+
}),
30+
);
31+
});
32+
33+
await Promise.all(platformSignupPromises);
34+
}
35+
36+
main()
37+
.catch((e) => console.error(e))
38+
.finally(async () => {
39+
await prisma.$disconnect();
40+
});

0 commit comments

Comments
 (0)