Skip to content

Commit 34eb938

Browse files
author
Maggie Chen
committed
added migration files to drop legacy database
1 parent 535cb4f commit 34eb938

File tree

2 files changed

+244
-0
lines changed

2 files changed

+244
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { DataType } from "sequelize-typescript";
2+
import { Migration } from "../umzug";
3+
4+
const TABLE_NAME = "applicationdashboardtable";
5+
const userEmails = ["johndoe@gmail.com", "janedoe@gmail.ca"];
6+
const SEEDED_DATA = [
7+
{
8+
applicationId: 1,
9+
reviewerId: 1,
10+
reviewerEmail: userEmails[0],
11+
passionFSG: 0,
12+
teamPlayer: 0,
13+
desireToLearn: 0,
14+
skill: 0,
15+
reviewerComments: "Great job presenting your case study!",
16+
recommendedSecondChoice: "N/A",
17+
skillCategory: "junior",
18+
},
19+
{
20+
applicationId: 1,
21+
reviewerId: 2,
22+
reviewerEmail: userEmails[1],
23+
passionFSG: 0,
24+
teamPlayer: 0,
25+
desireToLearn: 0,
26+
skill: 0,
27+
reviewerComments: "Very good!",
28+
recommendedSecondChoice: "considered",
29+
skillCategory: "intermediate",
30+
},
31+
];
32+
export const up: Migration = async ({ context: sequelize }) => {
33+
await sequelize.getQueryInterface().dropTable(TABLE_NAME);
34+
};
35+
36+
export const down: Migration = async ({ context: sequelize }) => {
37+
await sequelize.getQueryInterface().createTable(TABLE_NAME, {
38+
id: {
39+
type: DataType.INTEGER,
40+
allowNull: false,
41+
primaryKey: true,
42+
unique: true,
43+
autoIncrement: true,
44+
},
45+
applicationId: {
46+
type: DataType.INTEGER,
47+
allowNull: false,
48+
references: {
49+
model: "applicantresponse",
50+
key: "id",
51+
},
52+
},
53+
reviewerId: {
54+
type: DataType.INTEGER,
55+
allowNull: false,
56+
references: {
57+
model: "users",
58+
key: "id",
59+
},
60+
},
61+
reviewerEmail: {
62+
type: DataType.STRING,
63+
allowNull: false,
64+
},
65+
passionFSG: {
66+
type: DataType.INTEGER,
67+
allowNull: false,
68+
},
69+
teamPlayer: {
70+
type: DataType.INTEGER,
71+
allowNull: false,
72+
},
73+
desireToLearn: {
74+
type: DataType.INTEGER,
75+
allowNull: false,
76+
},
77+
skill: {
78+
type: DataType.INTEGER,
79+
allowNull: false,
80+
},
81+
skillCategory: {
82+
type: DataType.ENUM("junior", "intermediate", "senior"),
83+
allowNull: false,
84+
},
85+
reviewerComments: {
86+
type: DataType.STRING,
87+
allowNull: false,
88+
},
89+
recommendedSecondChoice: {
90+
type: DataType.ENUM("N/A", "considered", "not considered"),
91+
allowNull: false,
92+
},
93+
createdAt: DataType.DATE,
94+
updatedAt: DataType.DATE,
95+
});
96+
// Creating ForeignKey for User and Application table
97+
await sequelize.getQueryInterface().bulkInsert(TABLE_NAME, SEEDED_DATA);
98+
// Inserting users to User table
99+
};
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import { DataType } from "sequelize-typescript";
2+
import { DataTypes } from "sequelize";
3+
import { Migration } from "../umzug";
4+
import allApplications from "./applicationlist.json";
5+
import { SecondChoiceStatusType, StatusType } from "../types";
6+
7+
const TABLE_NAME = "applicantresponse";
8+
9+
// To get more application data, copy paste more info from http://localhost:5000/applications
10+
// into applicationlist.json (using applications endpoint in server.ts)
11+
const importApplicationData = () => {
12+
const seededData = allApplications.map((currApplication) => {
13+
return {
14+
academicOrCoop: currApplication.academicOrCoop,
15+
academicYear: currApplication.academicYear,
16+
email: currApplication.email,
17+
firstChoiceRole: currApplication.firstChoiceRole,
18+
firstName: currApplication.firstName,
19+
heardFrom: currApplication.heardFrom,
20+
lastName: currApplication.lastName,
21+
locationPreference: currApplication.locationPreference,
22+
program: currApplication.program,
23+
pronouns: currApplication.pronouns,
24+
pronounsSpecified: currApplication.pronounsSpecified,
25+
resumeUrl: currApplication.resumeUrl,
26+
roleSpecificQuestions: [
27+
JSON.stringify(currApplication.roleSpecificQuestions),
28+
],
29+
secondChoiceRole: currApplication.secondChoiceRole,
30+
shortAnswerQuestions: [
31+
JSON.stringify(currApplication.shortAnswerQuestions),
32+
],
33+
status: currApplication.status,
34+
term: currApplication.term,
35+
timesApplied: currApplication.timesApplied,
36+
timestamp: currApplication.timestamp,
37+
};
38+
});
39+
40+
return seededData;
41+
};
42+
43+
export const up: Migration = async ({ context: sequelize }) => {
44+
await sequelize.getQueryInterface().dropTable(TABLE_NAME);
45+
};
46+
47+
export const down: Migration = async ({ context: sequelize }) => {
48+
await sequelize.getQueryInterface().createTable(TABLE_NAME, {
49+
id: {
50+
type: DataType.INTEGER,
51+
allowNull: false,
52+
primaryKey: true,
53+
autoIncrement: true,
54+
unique: true,
55+
},
56+
academicOrCoop: {
57+
type: DataType.STRING(4000),
58+
allowNull: true,
59+
},
60+
academicYear: {
61+
type: DataType.STRING(4000),
62+
allowNull: true,
63+
},
64+
email: {
65+
type: DataType.STRING(4000),
66+
allowNull: true,
67+
},
68+
firstChoiceRole: {
69+
type: DataType.STRING(4000),
70+
allowNull: true,
71+
},
72+
firstName: {
73+
type: DataType.STRING(4000),
74+
allowNull: true,
75+
},
76+
heardFrom: {
77+
type: DataType.STRING(4000),
78+
allowNull: true,
79+
},
80+
lastName: {
81+
type: DataType.STRING(4000),
82+
allowNull: true,
83+
},
84+
locationPreference: {
85+
type: DataType.STRING(4000),
86+
allowNull: true,
87+
},
88+
program: {
89+
type: DataType.STRING(4000),
90+
allowNull: true,
91+
},
92+
pronouns: {
93+
type: DataType.STRING(4000),
94+
allowNull: true,
95+
},
96+
pronounsSpecified: {
97+
type: DataType.STRING(4000),
98+
allowNull: true,
99+
},
100+
resumeUrl: {
101+
type: DataType.STRING(4000),
102+
allowNull: true,
103+
},
104+
roleSpecificQuestions: {
105+
type: DataType.ARRAY(DataType.STRING(4000)),
106+
allowNull: true,
107+
},
108+
secondChoiceRole: {
109+
type: DataType.STRING(4000),
110+
allowNull: true,
111+
},
112+
shortAnswerQuestions: {
113+
type: DataType.ARRAY(DataType.STRING(4000)),
114+
allowNull: true,
115+
},
116+
status: {
117+
type: DataType.ENUM(...Object.values(StatusType)),
118+
allowNull: false,
119+
defaultValue: StatusType.PENDING,
120+
},
121+
secondChoiceStatus: {
122+
type: DataTypes.ENUM(...Object.values(SecondChoiceStatusType)),
123+
allowNull: false,
124+
defaultValue: SecondChoiceStatusType.NOT_APPLICABLE,
125+
},
126+
term: {
127+
type: DataType.STRING(4000),
128+
allowNull: true,
129+
},
130+
timesApplied: {
131+
type: DataType.STRING(4000),
132+
allowNull: true,
133+
},
134+
timestamp: {
135+
type: DataType.BIGINT,
136+
allowNull: true,
137+
},
138+
createdAt: DataType.DATE,
139+
updatedAt: DataType.DATE,
140+
});
141+
142+
const SEEDED_DATA = importApplicationData();
143+
144+
await sequelize.getQueryInterface().bulkInsert(TABLE_NAME, SEEDED_DATA);
145+
};

0 commit comments

Comments
 (0)