-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from andela/ch/164798024-create-notification-t…
…able #164798024 create notification table
- Loading branch information
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('Notifications', { | ||
id: { | ||
allowNull: false, | ||
primaryKey: true, | ||
type: Sequelize.UUID, | ||
defaultValue: Sequelize.UUIDV4, | ||
unique: true, | ||
}, | ||
user_id: { | ||
type: Sequelize.UUID, | ||
}, | ||
article_id: { | ||
type: Sequelize.STRING, | ||
}, | ||
message: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
}, | ||
is_seen: { | ||
type: Sequelize.BOOLEAN, | ||
defaultValue: false, | ||
allowNull: false, | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE, | ||
defaultValue: Sequelize.fn('now'), | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE, | ||
defaultValue: Sequelize.fn('now'), | ||
}, | ||
}); | ||
}, | ||
down: queryInterface => queryInterface.dropTable('Notifications'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module.exports = (sequelize, DataTypes) => { | ||
const Notification = sequelize.define('Notification', { | ||
id: { | ||
allowNull: false, | ||
primaryKey: true, | ||
type: DataTypes.UUID, | ||
defaultValue: DataTypes.UUIDV4, | ||
unique: true, | ||
}, | ||
user_id: { | ||
type: DataTypes.UUID, | ||
}, | ||
article_id: { | ||
type: DataTypes.STRING, | ||
}, | ||
message: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
}, | ||
is_seen: { | ||
type: DataTypes.BOOLEAN, | ||
defaultValue: false, | ||
allowNull: false, | ||
}, | ||
}); | ||
Notification.associate = models => | ||
Notification.belongsTo(models.User, { | ||
foreignKey: 'user_id', | ||
onDelete: 'CASCADE', | ||
}); | ||
|
||
Notification.associate = models => | ||
Notification.belongsTo(models.Article, { | ||
foreignKey: 'article_id', | ||
onDelete: 'CASCADE', | ||
}); | ||
return Notification; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module.exports = { | ||
up: queryInterface => | ||
queryInterface.bulkInsert('Notifications', [ | ||
{ | ||
id: '3473a764-53fe-11e9-8647-d663bd873d92', | ||
user_id: '57c515a1-890d-412f-8ca1-0a5390123dca', | ||
article_id: '7139d3af-b8b4-44f6-a49f-9305791700f4', | ||
message: | ||
'Your article: A Chicken in a sellsuit is an egg, had recieved a new comment from Bukunmi', | ||
}, | ||
{ | ||
id: '3473a62e-53fe-11e9-8647-d663bd873d92', | ||
user_id: '57c515a1-890d-412f-0ca1-0a5395123dca', | ||
article_id: '7139d3af-b8b4-44f6-a49f-7866779988yt', | ||
message: 'Chuks published a new article', | ||
}, | ||
{ | ||
id: '3473a4e4-53fe-11e9-8647-d663bd873d93', | ||
user_id: '7142e4ff-366d-46cc-9384-40eadb3b2626', | ||
article_id: 'fa3def47-153a-40bd-8181-a1c234567876', | ||
message: | ||
'Victory published a new article: When physics meet chemistry, there will never be a divorce', | ||
}, | ||
]), | ||
}; |