-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(userModel): set-up the user model
- add the database name, password,port and localhost to the .env file - run the sequelize model on the terminal to populate the user model and migrations - run the migrations on the terminal to populate the database - install uuidv4 dependency - add a .env-example sample [Delivers #168001215]
- Loading branch information
Funmi Olaiya
committed
Aug 21, 2019
1 parent
d198096
commit 07f5dbc
Showing
10 changed files
with
166 additions
and
91 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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
DATABASE_URL= | ||
DEV_DATABASE_URL=postgres://<db_user>:<db_password>@127.0.0.1:5432/dev_db | ||
TEST_DATABASE_URL=postgres://<db_user>:<db_password>@127.0.0.1:5432/test_db | ||
TEST_DB_NAME=<dummy-database-name> | ||
DEV_DB_NAME=user_db=<real-database-name> | ||
DB_USER=<databse-username> | ||
DB_PASS=<database-password> | ||
DB_PORT=<postgres-port> | ||
DB_HOST=<localhost-ip-address> |
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 |
---|---|---|
|
@@ -176,4 +176,7 @@ typings/ | |
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
.dynamodb/ | ||
|
||
# package-lock.json | ||
package-lock.json |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
require('dotenv').config() | ||
require('dotenv').config(); | ||
|
||
module.exports = { | ||
module.exports = { | ||
development: { | ||
url: process.env.DEV_DATABASE_URL, | ||
dialect: "postgres", | ||
dialect: 'postgres', | ||
}, | ||
test: { | ||
url: process.env.TEST_DATABASE_URL, | ||
dialect: "postgres", | ||
dialect: 'postgres', | ||
}, | ||
production: { | ||
url: process.env.DATABASE_URL, | ||
dialect: "postgres" | ||
dialect: 'postgres' | ||
}, | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,44 +1,58 @@ | ||
export default { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('Users', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
first_name: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
}, | ||
last_name: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
email: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
unique: true | ||
}, | ||
password: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
is_admin: { | ||
type: Sequelize.BOOLEAN, | ||
defaultValue: false | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
up(queryInterface, Sequelize) { | ||
return queryInterface.sequelize.query('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";') | ||
.then(() => queryInterface.createTable('users', { | ||
id: { | ||
allowNull: false, | ||
primaryKey: true, | ||
type: Sequelize.DataTypes.UUID, | ||
defaultValue: Sequelize.literal('uuid_generate_v4()'), | ||
}, | ||
firstName: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
}, | ||
lastName: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
}, | ||
email: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
}, | ||
password: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
}, | ||
isAdmin: { | ||
type: Sequelize.BOOLEAN, | ||
allowNull: false, | ||
}, | ||
phoneNumber: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
}, | ||
department: { | ||
type: Sequelize.ENUM('admin', 'staff', 'manager'), | ||
allowNull: true, | ||
}, | ||
office: { | ||
type: Sequelize.STRING, | ||
allowNull: true | ||
}, | ||
imageUrl: { | ||
type: Sequelize.STRING, | ||
allowNull: true, | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
})); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('Users'); | ||
} | ||
}; | ||
down: (queryInterface, Sequelize) => queryInterface.dropTable('users') | ||
}; |
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,36 @@ | ||
export default { | ||
up: (queryInterface, Sequelize) => queryInterface.bulkInsert( | ||
'users', | ||
[ | ||
{ | ||
firstName: 'funmi', | ||
lastName: 'Olaiya', | ||
email: 'funmi@yahoo.com', | ||
password: 'funmi', | ||
isAdmin: 'true', | ||
phoneNumber: '66666666666', | ||
department: 'staff', | ||
office: 'software developer', | ||
imageUrl: 'http://www.tco-team.com/blog/become-a-good-developer/', | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
}, | ||
{ | ||
firstName: 'kelechi', | ||
lastName: 'oliver', | ||
email: 'kelechi@yahoo.com', | ||
password: 'kelechi', | ||
isAdmin: 'true', | ||
phoneNumber: '8888888888', | ||
department: 'admin', | ||
office: '', | ||
imageUrl: '', | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
}, | ||
], | ||
{} | ||
), | ||
|
||
down: (queryInterface, Sequelize) => queryInterface.bulkDelete('users', null, {}) | ||
}; |
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 |
---|---|---|
@@ -1,30 +1,42 @@ | ||
export default (sequelize, DataTypes) => { | ||
const User = sequelize.define('User', { | ||
first_name: { | ||
firstName: { | ||
type: DataTypes.STRING, | ||
allowNull: false | ||
allowNull: false, | ||
}, | ||
last_name: { | ||
lastName: { | ||
type: DataTypes.STRING, | ||
allowNull: false | ||
allowNull: false, | ||
}, | ||
email: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
unique: true | ||
}, | ||
password: { | ||
type: DataTypes.STRING, | ||
allowNull: false | ||
}, | ||
is_admin: { | ||
type: DataTypes.BOOLEAN, | ||
defaultValue: false, | ||
|
||
} | ||
}, {}); | ||
User.associate = (models) => { | ||
// associations can be defined here | ||
}; | ||
allowNull: false, | ||
}, | ||
isAdmin: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
}, | ||
phoneNumber: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
}, | ||
department: { | ||
type: DataTypes.ENUM, | ||
values: ['admin', 'staff', 'manager'], | ||
allowNull: true, | ||
}, | ||
office: { | ||
type: DataTypes.STRING, | ||
allowNull: true, | ||
}, | ||
imageUrl: { | ||
type: DataTypes.STRING, | ||
allowNull: true, | ||
}, | ||
}); | ||
return User; | ||
}; |
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