Skip to content

Commit 951a95c

Browse files
migrations script real
1 parent 4de15fb commit 951a95c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

scripts/migration/plans-migration.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
/* eslint-disable no-console */
22

3-
import { usernameCollection, semestersCollection } from '../firebase-config';
3+
import { semestersCollection } from '../firebase-config';
44

55
/**
66
* Perform migration of semester to plans with a list of semesters
77
*/
88
async function runOnUser(userEmail: string) {
99
const semestersDoc = await semestersCollection.doc(userEmail).get();
1010
const semesters = semestersDoc.data()?.semesters ?? [];
11+
const currplans = semestersDoc.data()?.plans ?? [];
12+
const newplans =
13+
currplans.length >= 1
14+
? currplans.map(p => (!('name' in p) ? { name: 'Plan 1', semesters } : p))
15+
: [{ name: 'Plan 1', semesters }];
1116
await semestersCollection.doc(userEmail).update({
12-
plans: [{ name: 'Plan 1', semesters }],
17+
plans: newplans,
1318
});
1419
}
1520

@@ -19,7 +24,7 @@ async function main() {
1924
await runOnUser(userEmail);
2025
return;
2126
}
22-
const collection = await usernameCollection.get();
27+
const collection = await semestersCollection.get();
2328
for (const { id } of collection.docs) {
2429
console.group(`Running on ${id}...`);
2530
// Intentionally await in a loop to have no interleaved console logs.

0 commit comments

Comments
 (0)