Skip to content

Commit

Permalink
bg(database): Update database
Browse files Browse the repository at this point in the history
changes have been made to meet product's new requirements.
  • Loading branch information
oosahon committed Aug 27, 2019
1 parent 1a1020e commit e8bbe27
Show file tree
Hide file tree
Showing 26 changed files with 144 additions and 359 deletions.
14 changes: 13 additions & 1 deletion src/db/migrations/20190819194857-create-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ module.exports = {
type: Sequelize.STRING,
allowNull: false
},
manager_id: {
type: Sequelize.INTEGER,
references: {
model: 'users',
key: 'id'
}
},
gender: {
type: Sequelize.ENUM('male', 'female', 'other')
},
Expand All @@ -42,10 +49,15 @@ module.exports = {
type: Sequelize.STRING
},
role: {
type: Sequelize.ENUM('super_admin', 'travel_admin', 'travel_team_member', 'manager', 'requester'),
type: Sequelize.ENUM('super_admin', 'travel_admin', 'manager', 'requester'),
allowNull: false,
defaultValue: 'requester'
},
email_notification: {
type: Sequelize.BOOLEAN,
defaultValue: true,
allowNull: false
},
is_verified: {
type: Sequelize.BOOLEAN,
defaultValue: false
Expand Down
26 changes: 0 additions & 26 deletions src/db/migrations/20190820071904-create-department.js

This file was deleted.

34 changes: 0 additions & 34 deletions src/db/migrations/20190821140128-create-suppliers.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/db/migrations/20190821140753-create-facilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ module.exports = {
type: Sequelize.INTEGER,
allowNull: false
},
supplier_id: {
type: Sequelize.INTEGER,
references: {
model: 'suppliers',
key: 'id',
as: 'supplier_id'
},
onDelete: 'CASCADE'
},
created_at: {
allowNull: false,
type: Sequelize.DATE
Expand Down
6 changes: 2 additions & 4 deletions src/db/migrations/20190821142413-create-likes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ module.exports = {
type: Sequelize.INTEGER,
references: {
model: 'facilities',
key: 'id',
as: 'facility_id'
key: 'id'
},
onDelete: 'CASCADE'
},
user_id: {
type: Sequelize.INTEGER,
references: {
model: 'users',
key: 'id',
as: 'user_id'
key: 'id'
},
onDelete: 'CASCADE'
}
Expand Down
6 changes: 4 additions & 2 deletions src/db/migrations/20190821143206-create-rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ module.exports = {
type: Sequelize.INTEGER,
allowNull: false
},
images: {
type: Sequelize.ARRAY(Sequelize.STRING)
},
facility_id: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'facilities',
key: 'id',
as: 'facility_id'
key: 'id'
},
onDelete: 'CASCADE'
},
Expand Down
3 changes: 1 addition & 2 deletions src/db/migrations/20190821144025-create-amenities.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ module.exports = {
allowNull: false,
references: {
model: 'facilities',
key: 'id',
as: 'facility_id'
key: 'id'
},
onDelete: 'CASCADE'
},
Expand Down
6 changes: 2 additions & 4 deletions src/db/migrations/20190821144633-create-feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ module.exports = {
allowNull: false,
references: {
model: 'users',
key: 'id',
as: 'user_id'
key: 'id'
},
onDelete: 'CASCADE'
},
Expand All @@ -25,8 +24,7 @@ module.exports = {
type: Sequelize.INTEGER,
references: {
model: 'facilities',
key: 'id',
as: 'facility_id'
key: 'id'
},
onDelete: 'CASCADE'
},
Expand Down
10 changes: 6 additions & 4 deletions src/db/migrations/20190821153031-create-booking.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ module.exports = {
allowNull: false,
references: {
model: 'users',
key: 'id',
as: 'user_id'
key: 'id'
},
onDelete: 'CASCADE'
},
Expand All @@ -22,8 +21,7 @@ module.exports = {
allowNull: false,
references: {
model: 'rooms',
key: 'id',
as: 'room_id'
key: 'id'
},
onDelete: 'CASCADE'
},
Expand All @@ -35,6 +33,10 @@ module.exports = {
type: Sequelize.DATE,
allowNull: false
},
checked_in: {
type: Sequelize.BOOLEAN,
defaultValue: false
},
created_at: {
allowNull: false,
type: Sequelize.DATE
Expand Down
6 changes: 2 additions & 4 deletions src/db/migrations/20190821153817-create-rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ module.exports = {
type: Sequelize.INTEGER,
references: {
model: 'users',
key: 'id',
as: 'user_id'
key: 'id'
},
onDelete: 'CASCADE'
},
Expand All @@ -29,8 +28,7 @@ module.exports = {
allowNull: false,
references: {
model: 'facilities',
key: 'id',
as: 'facility_id'
key: 'id'
},
onDelete: 'CASCADE'
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
up: (queryInterface, Sequelize) => (
queryInterface.createTable('trips', {
queryInterface.createTable('requests', {
id: {
allowNull: false,
autoIncrement: true,
Expand All @@ -12,8 +12,7 @@ module.exports = {
allowNull: false,
references: {
model: 'users',
key: 'id',
as: 'user_id'
key: 'id'
},
onDelete: 'CASCADE'
},
Expand Down Expand Up @@ -45,8 +44,7 @@ module.exports = {
allowNull: false,
references: {
model: 'bookings',
key: 'id',
as: 'accommodation_id'
key: 'id'
},
onDelete: 'CASCADE'
},
Expand All @@ -64,6 +62,6 @@ module.exports = {
}
})
),
down: (queryInterface) => queryInterface.dropTable('trips')
down: (queryInterface) => queryInterface.dropTable('requests')
// removed the parameter "Sequelize" because it is not being used
};
18 changes: 4 additions & 14 deletions src/db/migrations/20190821160011-create-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,23 @@ module.exports = {
allowNull: false,
references: {
model: 'users',
key: 'id',
as: 'user_id'
key: 'id'
},
onDelete: 'CASCADE'
},
trip_id: {
request_id: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'trips',
key: 'id',
as: 'trip_id'
model: 'requests',
key: 'id'
},
onDelete: 'CASCADE'
},
comment: {
type: Sequelize.INTEGER,
allowNull: false
},
replied_to: {
type: Sequelize.INTEGER,
references: {
model: 'comments',
key: 'id',
as: 'replied_to'
}
},
created_at: {
allowNull: false,
type: Sequelize.DATE
Expand Down
10 changes: 4 additions & 6 deletions src/db/migrations/20190821160830-create-notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ module.exports = {
primaryKey: true,
type: Sequelize.INTEGER
},
trip_id: {
request_id: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'trips',
key: 'id',
as: 'trip_id'
model: 'requests',
key: 'id'
},
onDelete: 'CASCADE'
},
Expand All @@ -30,8 +29,7 @@ module.exports = {
allowNull: false,
references: {
model: 'users',
key: 'id',
as: 'receiver_id'
key: 'id'
},
onDelete: 'CASCADE'
},
Expand Down
20 changes: 6 additions & 14 deletions src/db/models/amenity.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,16 @@ module.exports = (sequelize, DataTypes) => {
},
description: {
type: DataTypes.STRING
},
facility_id: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'facilities',
key: 'id',
as: 'facility_id'
},
onDelete: 'CASCADE'
}
}, {
tableName: 'amenities',
underscored: true
});
Amenity.associate = () => {
// associations can be defined here
// removed the parameter "models" because it is not being used
};
Amenity.associate = (models) => (
Amenity.belongsTo(models.Facility, {
foreignKey: 'facility_id',
oneDelete: 'CASCADE'
})
);
return Amenity;
};
Loading

0 comments on commit e8bbe27

Please sign in to comment.