Skip to content

Commit

Permalink
Merge pull request #41 from andela/ch/164798024-create-notification-t…
Browse files Browse the repository at this point in the history
…able

#164798024 create notification table
  • Loading branch information
Rotimi Babalola committed Apr 3, 2019
2 parents 9c9a97b + 3c3950f commit 9e94647
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
39 changes: 39 additions & 0 deletions server/migrations/20190403160516-create-notification.js
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'),
};
38 changes: 38 additions & 0 deletions server/models/notification.js
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;
};
25 changes: 25 additions & 0 deletions server/seeders/20190403162229-Notifications.js
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',
},
]),
};

0 comments on commit 9e94647

Please sign in to comment.