Skip to content

Commit

Permalink
database renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
kmsngh committed Feb 5, 2021
1 parent e1da57c commit e9786f9
Show file tree
Hide file tree
Showing 20 changed files with 287 additions and 41 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"router": "^1.3.5",
"sequelize": "^6.3.5",
"swagger-jsdoc": "^4.0.0",
"yarn": "^1.22.4"
"yarn": "^1.22.10"
},
"devDependencies": {
"eslint": "^7.7.0"
Expand Down
8 changes: 4 additions & 4 deletions src/database/migrations/20200827230222-create-associations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
return queryInterface
.addColumn(
"Post", // name of Source model
"boardId", // name of the key we're adding
"BoardId", // name of the key we're adding
{
type: Sequelize.INTEGER,
references: {
Expand Down Expand Up @@ -37,7 +37,7 @@ module.exports = {
// Student hasMany Payment
return queryInterface.addColumn(
"Payment", // name of Target model
"studentId", // name of the key we're adding
"StudentId", // name of the key we're adding
{
type: Sequelize.UUID,
references: {
Expand All @@ -56,7 +56,7 @@ module.exports = {
return queryInterface
.removeColumn(
"Post", // name of Source model
"boardId" // key we want to remove
"BoardId" // key we want to remove
)
.then(() => {
// remove Student hasMany CancelRequest
Expand All @@ -69,7 +69,7 @@ module.exports = {
// remove Student hasMany Payment
return queryInterface.removeColumn(
"Payment", // name of the Target model
"studentId" // key we want to remove
"StudentId" // key we want to remove
);
});
},
Expand Down
4 changes: 2 additions & 2 deletions src/database/migrations/20201005191451-edit-petition.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn(
"Petition", // name of Source model
"authorId", // name of the key we're adding
"StudentId", // name of the key we're adding
{
type: Sequelize.UUID,
references: {
Expand All @@ -18,6 +18,6 @@ module.exports = {
},

down: async (queryInterface, Sequelize) => {
await queryInterface.removeColumn("Petition", "authorId");
await queryInterface.removeColumn("Petition", "StudentId");
},
};
55 changes: 55 additions & 0 deletions src/database/migrations/20201008181206-create-post-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"use strict";

module.exports = {
up: async (queryInterface, Sequelize) => {
await Promise.all([
queryInterface.createTable("PostTag", {
id: {
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4,
primaryKey: true,
},
korName: Sequelize.TEXT,
engName: Sequelize.TEXT,
BoardId: {
type: Sequelize.INTEGER,
references: {
model: "Board", // name of Source model
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
}),
queryInterface.createTable("Post_PostTag", {
PostId: {
type: Sequelize.UUID,
references: {
model: "Post", // name of Target model
key: "id", // key in Target model that we're referencing
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
PostTagId: {
type: Sequelize.UUID,
references: {
model: "PostTag", // name of Target model
key: "id", // key in Target model that we're referencing
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
createdAt: Sequelize.DATE,
updatedAt: Sequelize.DATE,
}),
]);
},

down: async (queryInterface, Sequelize) => {
await Promise.all([
queryInterface.dropTable("Post_PostTag"),
queryInterface.dropTable("PostTag"),
]);
},
};
25 changes: 25 additions & 0 deletions src/database/models/Admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use strict";
module.exports = (sequelize, DataTypes) => {
const Admin = sequelize.define(
"Admin",
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
email: DataTypes.STRING,
password: DataTypes.STRING,
salt: DataTypes.STRING,
},
{
freezeTableName: true,
charset: "utf8",
collate: "utf8_general_ci",
}
);
Admin.associate = function (models) {
// associations can be defined here
};
return Admin;
};
26 changes: 26 additions & 0 deletions src/database/models/Banner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";
module.exports = (sequelize, DataTypes) => {
const Banner = sequelize.define(
"Banner",
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
image: DataTypes.TEXT,
link: DataTypes.TEXT,
isActive: DataTypes.BOOLEAN,
},
{
freezeTableName: true,
timestamps: false,
charset: "utf8",
collate: "utf8_general_ci",
}
);
Banner.associate = function (models) {
// associations can be defined here
};
return Banner;
};
3 changes: 2 additions & 1 deletion src/database/models/Board.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ module.exports = (sequelize, DataTypes) => {
);

Board.associate = function (models) {
models.Board.hasMany(models.Post, { foreignKey: "boardId" });
models.Board.hasMany(models.Post);
models.Board.hasMany(models.PostTag);
};

return Board;
Expand Down
4 changes: 2 additions & 2 deletions src/database/models/Petition.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = (sequelize, DataTypes) => {
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
authorId: DataTypes.UUID,
StudentId: DataTypes.UUID,
korTitle: DataTypes.TEXT,
engTitle: DataTypes.TEXT,
korContent: DataTypes.TEXT,
Expand Down Expand Up @@ -37,7 +37,7 @@ module.exports = (sequelize, DataTypes) => {

Petition.associate = function (models) {
Petition.belongsToMany(models.Student, { through: "Student_Petition" });
Petition.belongsTo(models.Student, { foreignKey: "authorId" });
Petition.belongsTo(models.Student);
};

return Petition;
Expand Down
27 changes: 27 additions & 0 deletions src/database/models/PostTag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
module.exports = (sequelize, DataTypes) => {
const PostTag = sequelize.define(
"PostTag",
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
korName: DataTypes.TEXT,
engName: DataTypes.TEXT,
},
{
freezeTableName: true,
charset: "utf8",
collate: "utf8_general_ci",
timestamps: false,
}
);
PostTag.associate = function (models) {
// associations can be defined here
PostTag.belongsToMany(models.Post, { through: "Post_PostTag" });
PostTag.belongsTo(models.Board);
};
return PostTag;
};
8 changes: 2 additions & 6 deletions src/database/models/Student.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ module.exports = (sequelize, DataTypes) => {
foreignKey: "studentNumber",
sourceKey: "studentNumber",
});
Student.hasMany(models.Payment, {
foreignKey: "studentId",
});
Student.hasMany(models.Petition, {
foreignKey: "authorId",
});
Student.hasMany(models.Payment);
Student.hasMany(models.Petition);
Student.belongsToMany(models.Petition, { through: "Student_Petition" });
};
return Student;
Expand Down
2 changes: 1 addition & 1 deletion src/database/models/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = (sequelize, DataTypes) => {
);
Payment.associate = function (models) {
// associations can be defined here
Payment.belongsTo(models.Student, { foreignKey: "studentId" });
Payment.belongsTo(models.Student);
};
return Payment;
};
3 changes: 2 additions & 1 deletion src/database/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ module.exports = (sequelize, DataTypes) => {
);

Post.associate = function (models) {
models.Post.belongsTo(models.Board, { foreignKey: "boardId" });
Post.belongsTo(models.Board);
Post.belongsToMany(models.PostTag, { through: "Post_PostTag" });
};

return Post;
Expand Down
29 changes: 29 additions & 0 deletions src/database/seeders/20201008201030-create-banners.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use strict";

const models = require("../models");

module.exports = {
up: async (queryInterface, Sequelize) => {
await models.Banner.bulkCreate(
[
{
image:
"https://kaistua-web.s3.ap-northeast-2.amazonaws.com/Banner_kaiwiki.png",
link: "https://student.kaist.ac.kr/wiki",
isActive: 1,
},
{
image:
"https://kaistua-web.s3.ap-northeast-2.amazonaws.com/Banner2.png",
link: "https://student.kaist.ac.kr/web/user/studentFee",
isActive: 1,
},
],
{}
);
},

down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete("Banner", null, {});
},
};
82 changes: 82 additions & 0 deletions src/database/seeders/20201009070902-create-post-tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"use strict";

const models = require("../models");

module.exports = {
up: async (queryInterface, Sequelize) => {
await models.PostTag.bulkCreate(
[
{
korName: "회장단",
engName: "Presidency",
BoardId: 1,
},
{
korName: "협력국",
engName: "Bureau of Internal Operations and Communications",
BoardId: 1,
},
{
korName: "복지국",
engName: "Bureau of Welfare",
BoardId: 1,
},
{
korName: "정책국",
engName: "Bureau of Policy",
BoardId: 1,
},
{
korName: "디자인정보팀",
engName: "Bureau of Design & Information Technology",
BoardId: 1,
},
{
korName: "사무국",
engName: "Bureau of General Affairs",
BoardId: 1,
},
{
korName: "국제사무국",
engName: "Bureau of International Affairs",
BoardId: 1,
},
{
korName: "집행지원실",
engName: "Executive Secretariat",
BoardId: 1,
},
{
korName: "문화기획국",
engName: "Bureau of Cultural Events",
BoardId: 1,
},
{
korName: "회계팀",
engName: "Bureau of Finance",
BoardId: 1,
},
{
korName: "식당",
engName: "Restaurant",
BoardId: 2,
},
{
korName: "병원",
engName: "Health",
BoardId: 2,
},
{
korName: "기타",
engName: "Other",
BoardId: 2,
},
],
{}
);
},

down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete("Banner", null, {});
},
};
Loading

0 comments on commit e9786f9

Please sign in to comment.