Skip to content

Commit 8e4d876

Browse files
authored
Merge pull request #157 from HackDavis/refactor/seeding-script
updated seeding for new schema
2 parents 91e317e + e7eb285 commit 8e4d876

File tree

5 files changed

+73
-25
lines changed

5 files changed

+73
-25
lines changed

migrations/create-submissions.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function up(db) {
5151
additionalProperties: true,
5252
},
5353
is_scored: {
54-
bsonType: 'boolean',
54+
bsonType: 'bool',
5555
description: 'is_scored must be boolean',
5656
},
5757
},

migrations/create-teams.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export async function up(db) {
66
$jsonSchema: {
77
bsonType: 'object',
88
title: 'Teams Object Validation',
9-
required: ['number', 'name', 'tracks', 'hacker_ids'],
9+
required: ['number', 'name', 'tracks'],
1010
properties: {
1111
_id: {
1212
bsonType: 'objectId',

migrations/create-users.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function up(db) {
4141
'position must be either developer, designer, pm, or other',
4242
},
4343
is_beginner: {
44-
bsonType: 'boolean',
44+
bsonType: 'bool',
4545
description: 'is_beginner must be a boolean',
4646
},
4747
starter_kit_stage: {

scripts/dbSeed.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async function dbSeed(collectionNames, numDocuments, wipe) {
2626
}
2727

2828
const collection = db.collection(
29-
collectionName === 'admin' ? 'judges' : collectionName
29+
collectionName === 'admin' ? 'users' : collectionName
3030
);
3131

3232
if (wipe === 'y') {

scripts/generateData.mjs

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,94 @@ import tracks from '../app/(api)/_data/tracks.json' assert { type: 'json' };
44

55
function generateData(collectionName, numDocuments) {
66
const specialties = ['tech', 'business', 'design'];
7-
const fakeTracks = Array.from(
8-
{ length: Math.ceil(Math.random() * 5) },
9-
() => tracks[Math.floor(Math.random() * tracks.length)].name
10-
);
7+
const numSpecialties = 2;
8+
const hackerPositions = ['developer', 'designer', 'pm', 'other'];
9+
const eventTypes = ['workshop', 'meal', 'general', 'activity'];
1110

1211
let data = [];
13-
if (collectionName === 'judges') {
14-
data = Array.from({ length: numDocuments }, () => ({
15-
name: faker.person.firstName(),
12+
13+
if (collectionName === 'users') {
14+
const judges = Array.from({ length: numDocuments }, () => ({
15+
name: faker.person.fullName(),
1616
email: faker.internet.email(),
1717
password: faker.internet.password(),
18-
specialty: specialties[Math.floor(Math.random() * specialties.length)],
19-
judge_group_id: new ObjectId(),
18+
specialties: faker.helpers.arrayElements(specialties, numSpecialties),
2019
role: 'judge',
2120
}));
21+
22+
const hackers = Array.from({ length: numDocuments }, () => ({
23+
name: faker.person.firstName(),
24+
email: faker.internet.email(),
25+
password: faker.internet.password(),
26+
position: faker.helpers.arrayElement(hackerPositions),
27+
is_beginner: faker.datatype.boolean(),
28+
starter_kit_stage: faker.number.int({ min: 1, max: 4 }),
29+
role: 'hacker',
30+
}));
31+
32+
data = [...judges, ...hackers];
2233
} else if (collectionName === 'admin') {
2334
data.push({
2435
name: 'Admin',
2536
email: 'admin@hackdavis.io',
2637
password: '$2a$10$oit1hC4hBaj9OX.WQxm3uOtb0qnPNk4iR9QhZmFm7/r1rAphAMAva',
27-
specialty: 'tech',
2838
role: 'admin',
2939
});
3040
} else if (collectionName === 'teams') {
3141
data = Array.from({ length: numDocuments }, () => ({
3242
number: faker.number.int({ min: 1, max: 1000 }),
3343
name: faker.lorem.word(),
34-
tracks: fakeTracks,
44+
tracks: faker.helpers.arrayElements(
45+
tracks.map((t) => t.name),
46+
faker.number.int({ min: 1, max: 5 })
47+
),
3548
}));
3649
} else if (collectionName === 'submissions') {
37-
data = Array.from({ length: numDocuments }, () => ({
38-
judge_id: new ObjectId(),
39-
team_id: new ObjectId(),
40-
scores: Array.from({ length: 5 }, () => Math.ceil(Math.random() * 5)),
41-
correlations: Array.from(fakeTracks, (fakeTrack) => ({
42-
track: fakeTrack,
43-
score: Math.ceil(Math.random() * 5),
44-
})),
45-
comments: faker.lorem.sentence(),
46-
}));
50+
data = Array.from({ length: numDocuments }, () => {
51+
const scores = {
52+
social_good: faker.number.int({ min: 1, max: 5 }),
53+
creativity: faker.number.int({ min: 1, max: 5 }),
54+
presentation: faker.number.int({ min: 1, max: 5 }),
55+
comments: faker.lorem.sentence(),
56+
};
57+
const randomTracks = faker.helpers.arrayElements(
58+
tracks.map((t) => t.name),
59+
faker.number.int({ min: 1, max: 5 })
60+
);
61+
randomTracks.map((t) => {
62+
scores[t] = Array.from({ length: 5 }, () =>
63+
faker.number.int({ min: 1, max: 5 })
64+
);
65+
});
66+
67+
return {
68+
judge_id: new ObjectId(),
69+
team_id: new ObjectId(),
70+
scores: scores,
71+
is_scored: faker.datatype.boolean(),
72+
};
73+
});
74+
} else if (collectionName === 'events') {
75+
data = Array.from({ length: numDocuments }, () => {
76+
const eventType = faker.helpers.arrayElement(eventTypes);
77+
const isWorkshop = eventType === 'workshop';
78+
const startTime = faker.date.between({
79+
from: '2025-04-19T00:00:00.000Z',
80+
to: '2025-04-20T23:59:59.999Z',
81+
});
82+
83+
return {
84+
name: faker.company.catchPhrase(),
85+
type: eventType,
86+
host: isWorkshop ? faker.company.name() : '',
87+
location: faker.location.street(),
88+
start_time: startTime,
89+
end_time: faker.date.soon({ days: 2, refDate: startTime }),
90+
tags: isWorkshop
91+
? faker.helpers.arrayElements(hackerPositions, { min: 1 })
92+
: [],
93+
};
94+
});
4795
}
4896

4997
return data;

0 commit comments

Comments
 (0)