-
Notifications
You must be signed in to change notification settings - Fork 10
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 #24 from andela/ft-req-table-integration-167891585
#167891585: Creates Database Tables and Seeders
- Loading branch information
Showing
20 changed files
with
525 additions
and
9 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
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,57 @@ | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.sequelize.query('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";').then(() => queryInterface.createTable('Trips', { | ||
id: { | ||
allowNull: false, | ||
primaryKey: true, | ||
type: Sequelize.DataTypes.UUID, | ||
defaultValue: Sequelize.literal('uuid_generate_v4()'), | ||
}, | ||
type: { | ||
type: Sequelize.ENUM('oneway', 'return', 'multiple'), | ||
allowNull: false, | ||
}, | ||
userId: { | ||
type: Sequelize.UUID, | ||
allowNull: false, | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE', | ||
references: { | ||
model: 'Users', | ||
key: 'id', | ||
}, | ||
}, | ||
status: { | ||
allowNull: false, | ||
type: Sequelize.ENUM('pending', 'approved', 'rejected'), | ||
defaultValue: 'pending', | ||
}, | ||
startBranchId: { | ||
type: Sequelize.UUID, | ||
allowNull: false, | ||
}, | ||
reason: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
tripDate: { | ||
type: Sequelize.DATE, | ||
allowNull: false | ||
}, | ||
returnDate: { | ||
type: Sequelize.DATE, | ||
allowNull: true | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE, | ||
defaultValue: Sequelize.fn('now') | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE, | ||
defaultValue: Sequelize.fn('now') | ||
} | ||
})), | ||
down: queryInterface => queryInterface.dropTable('Trips') | ||
}; |
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,40 @@ | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.sequelize.query('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";').then(() => queryInterface.createTable('Locations', { | ||
id: { | ||
allowNull: false, | ||
primaryKey: true, | ||
type: Sequelize.DataTypes.UUID, | ||
defaultValue: Sequelize.literal('uuid_generate_v4()'), | ||
}, | ||
companyId: { | ||
type: Sequelize.UUID, | ||
allowNull: false, | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE', | ||
references: { | ||
model: 'Companies', | ||
key: 'id' | ||
} | ||
}, | ||
country: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
city: { | ||
type: Sequelize.STRING, | ||
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('Locations') | ||
}; |
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,35 @@ | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.sequelize.query('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";').then(() => queryInterface.createTable('Branches', { | ||
id: { | ||
allowNull: false, | ||
primaryKey: true, | ||
type: Sequelize.DataTypes.UUID, | ||
defaultValue: Sequelize.literal('uuid_generate_v4()'), | ||
}, | ||
name: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
locationId: { | ||
type: Sequelize.UUID, | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE', | ||
references: { | ||
model: 'Locations', | ||
key: 'id' | ||
} | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE, | ||
defaultValue: Sequelize.fn('now') | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE, | ||
defaultValue: Sequelize.fn('now') | ||
} | ||
})), | ||
down: queryInterface => queryInterface.dropTable('Branches') | ||
}; |
43 changes: 43 additions & 0 deletions
43
src/database/migrations/20190828150143-create-accomodation.js
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,43 @@ | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.sequelize.query('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";').then(() => queryInterface.createTable('Accomodations', { | ||
id: { | ||
allowNull: false, | ||
primaryKey: true, | ||
type: Sequelize.DataTypes.UUID, | ||
defaultValue: Sequelize.literal('uuid_generate_v4()') | ||
}, | ||
name: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
branchId: { | ||
type: Sequelize.UUID, | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE', | ||
references: { | ||
model: 'Branches', | ||
key: 'id' | ||
} | ||
}, | ||
capacity: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false | ||
}, | ||
status: { | ||
type: Sequelize.ENUM('available', 'filled'), | ||
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('Accomodations') | ||
}; |
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,49 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.sequelize.query('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";').then(() => queryInterface.createTable('Stops', { | ||
id: { | ||
allowNull: false, | ||
primaryKey: true, | ||
type: Sequelize.DataTypes.UUID, | ||
defaultValue: Sequelize.literal('uuid_generate_v4()'), | ||
}, | ||
destinationBranchId: { | ||
type: Sequelize.UUID, | ||
onDelete: 'RESTRICT', | ||
onUpdate: 'RESTRICT', | ||
references: { | ||
model: 'Branches', | ||
key: 'id', | ||
} | ||
}, | ||
accomodationId: { | ||
type: Sequelize.UUID, | ||
onDelete: 'RESTRICT', | ||
onUpdate: 'RESTRICT', | ||
references: { | ||
model: 'Accomodations', | ||
key: 'id' | ||
} | ||
}, | ||
tripId: { | ||
type: Sequelize.UUID, | ||
allowNull: false, | ||
onDelete: 'RESTRICT', | ||
onUpdate: 'RESTRICT', | ||
references: { | ||
model: 'Trips', | ||
key: 'id' | ||
} | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE, | ||
defaultValue: Sequelize.fn('now') | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE, | ||
defaultValue: Sequelize.fn('now') | ||
} | ||
})), | ||
down: queryInterface => queryInterface.dropTable('Stops') | ||
}; |
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,23 @@ | ||
module.exports = (sequelize, DataTypes) => { | ||
const Accomodation = sequelize.define('Accomodation', { | ||
name: DataTypes.STRING, | ||
branchId: DataTypes.UUID, | ||
capacity: DataTypes.INTEGER, | ||
status: DataTypes.STRING | ||
}, {}); | ||
Accomodation.associate = (models) => { | ||
Accomodation.belongsTo(models.Branch, { | ||
foreignKey: 'branchId', | ||
as: 'branch', | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE' | ||
}); | ||
Accomodation.hasMany(models.Stop, { | ||
foreignKey: 'accomodationId', | ||
as: 'stop', | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE' | ||
}); | ||
}; | ||
return Accomodation; | ||
}; |
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,33 @@ | ||
module.exports = (sequelize, DataTypes) => { | ||
const Branch = sequelize.define('Branch', { | ||
name: DataTypes.STRING, | ||
locationId: DataTypes.UUID | ||
}, {}); | ||
Branch.associate = (models) => { | ||
Branch.belongsTo(models.Location, { | ||
foreignKey: 'locationId', | ||
as: 'location', | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE' | ||
}); | ||
Branch.hasMany(models.Trip, { | ||
foreignKey: 'startBranchId', | ||
as: 'trip', | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE' | ||
}); | ||
Branch.hasMany(models.Accomodation, { | ||
foreignKey: 'branchId', | ||
as: 'accomodation', | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE' | ||
}); | ||
Branch.hasMany(models.Stop, { | ||
foreignKey: 'destinationBranchId', | ||
as: 'stop', | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE' | ||
}); | ||
}; | ||
return Branch; | ||
}; |
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
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,22 @@ | ||
module.exports = (sequelize, DataTypes) => { | ||
const Location = sequelize.define('Location', { | ||
companyId: DataTypes.UUID, | ||
country: DataTypes.STRING, | ||
city: DataTypes.STRING | ||
}, {}); | ||
Location.associate = (models) => { | ||
Location.belongsTo(models.Company, { | ||
foreignKey: 'companyId', | ||
as: 'company', | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE' | ||
}); | ||
Location.hasMany(models.Branch, { | ||
foreignKey: 'locationId', | ||
as: 'branch', | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE' | ||
}); | ||
}; | ||
return Location; | ||
}; |
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,28 @@ | ||
module.exports = (sequelize, DataTypes) => { | ||
const Stop = sequelize.define('Stop', { | ||
destinationBranchId: DataTypes.UUID, | ||
accomodationId: DataTypes.UUID, | ||
tripId: DataTypes.UUID, | ||
}, {}); | ||
Stop.associate = (models) => { | ||
Stop.belongsTo(models.Trip, { | ||
foreignKey: 'tripId', | ||
as: 'trip', | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE' | ||
}); | ||
Stop.belongsTo(models.Accomodation, { | ||
foreignKey: 'accomodationId', | ||
as: 'accomodation', | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE' | ||
}); | ||
Stop.belongsTo(models.Branch, { | ||
foreignKey: 'destinationBranchId', | ||
as: 'branch', | ||
onDelete: 'RESTRICT', | ||
onUpdate: 'RESTRICT' | ||
}); | ||
}; | ||
return Stop; | ||
}; |
Oops, something went wrong.