Skip to content

Commit 66512f0

Browse files
change from delete bad data to update with correct data
1 parent e59e252 commit 66512f0

File tree

1 file changed

+86
-11
lines changed

1 file changed

+86
-11
lines changed
Lines changed: 86 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,93 @@
1-
import { Op } from "sequelize";
21
import { Migration } from "../umzug";
32

3+
const USER_SEED_DATA = [
4+
{
5+
first_name: "Carolyn",
6+
last_name: "Zhang",
7+
email: "carolynzhang@uwblueprint.org",
8+
auth_id: "ATd5GMzp8IPJzQzuQYkaavcelb32",
9+
role: "Admin",
10+
position: "VP Engineering",
11+
},
12+
{
13+
first_name: "Jesse",
14+
last_name: "Huang",
15+
email: "jessehuang@uwblueprint.org",
16+
auth_id: "dkXIhkZXljOuEsXrZDASEguCQw43",
17+
role: "Admin",
18+
position: "VP Engineering",
19+
},
20+
];
21+
22+
const PREVIOUS_USER_SEED_DATA = [
23+
{
24+
first_name: "John",
25+
last_name: "Doe",
26+
email: "johndoe@gmail.com",
27+
auth_id: "bide",
28+
role: "User",
29+
},
30+
{
31+
first_name: "Jane",
32+
last_name: "Doe",
33+
email: "janedoe@gmail.ca",
34+
auth_id: "none",
35+
role: "Admin",
36+
},
37+
];
38+
439
export const up: Migration = async ({ context: sequelize }) => {
5-
await sequelize.getQueryInterface().bulkDelete("applicationdashboardtable", {
6-
reviewerId: { [Op.in]: [1, 2] },
7-
});
8-
await sequelize.getQueryInterface().bulkDelete("admins", {
9-
userId: { [Op.in]: [1, 2] },
10-
});
11-
await sequelize.getQueryInterface().bulkDelete("users", {
12-
id: { [Op.in]: [1, 2] },
13-
});
40+
// update malformed users with id 1 and 2 with proper seeded data
41+
await sequelize.getQueryInterface().bulkUpdate(
42+
"users",
43+
{
44+
first_name: USER_SEED_DATA[0].first_name,
45+
last_name: USER_SEED_DATA[0].last_name,
46+
email: USER_SEED_DATA[0].email,
47+
auth_id: USER_SEED_DATA[0].auth_id,
48+
role: USER_SEED_DATA[0].role,
49+
position: USER_SEED_DATA[0].position,
50+
},
51+
{ id: 1 },
52+
);
53+
54+
await sequelize.getQueryInterface().bulkUpdate(
55+
"users",
56+
{
57+
first_name: USER_SEED_DATA[1].first_name,
58+
last_name: USER_SEED_DATA[1].last_name,
59+
email: USER_SEED_DATA[1].email,
60+
auth_id: USER_SEED_DATA[1].auth_id,
61+
role: USER_SEED_DATA[1].role,
62+
position: USER_SEED_DATA[1].position,
63+
},
64+
{ id: 2 },
65+
);
1466
};
1567

1668
export const down: Migration = async ({ context: sequelize }) => {
17-
// No down migration needed as this is a cleanup operation
69+
// update malformed users with id 1 and 2 with proper seeded data
70+
await sequelize.getQueryInterface().bulkUpdate(
71+
"users",
72+
{
73+
first_name: PREVIOUS_USER_SEED_DATA[1].first_name,
74+
last_name: PREVIOUS_USER_SEED_DATA[1].last_name,
75+
email: PREVIOUS_USER_SEED_DATA[1].email,
76+
auth_id: PREVIOUS_USER_SEED_DATA[1].auth_id,
77+
role: PREVIOUS_USER_SEED_DATA[1].role,
78+
},
79+
{ id: 2 },
80+
);
81+
82+
await sequelize.getQueryInterface().bulkUpdate(
83+
"users",
84+
{
85+
first_name: PREVIOUS_USER_SEED_DATA[0].first_name,
86+
last_name: PREVIOUS_USER_SEED_DATA[0].last_name,
87+
email: PREVIOUS_USER_SEED_DATA[0].email,
88+
auth_id: PREVIOUS_USER_SEED_DATA[0].auth_id,
89+
role: PREVIOUS_USER_SEED_DATA[0].role,
90+
},
91+
{ id: 1 },
92+
);
1893
};

0 commit comments

Comments
 (0)