Skip to content

Commit

Permalink
chore:Setup Postgresql
Browse files Browse the repository at this point in the history
- Integrate author haven with Postgresql
- Populate database with necessary tables

[Delivers #163478786]
  • Loading branch information
Peace Oyedeji authored and Peace Oyedeji committed Feb 5, 2019
1 parent 01e42d4 commit 440879e
Show file tree
Hide file tree
Showing 23 changed files with 1,006 additions and 56 deletions.
434 changes: 431 additions & 3 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
"test": "PORT=3001 nyc mocha --require @babel/register tests/**/*.js --exit",
"lint": "eslint",
"start:dev": "NODE_ENV=development nodemon --exec babel-node index.js --preset-env",
"coverage": "nyc report --reporter=text-lcov | coveralls"
"coverage": "nyc report --reporter=text-lcov | coveralls",
"migrate": "./node_modules/.bin/babel-node ./node_modules/.bin/sequelize db:migrate",
"undo:migration": "./node_modules/.bin/babel-node ./node_modules/.bin/sequelize db:migrate:undo:all",
"migration": "npm run undo:migration && npm run migrate"
},
"author": "Andela Simulations Programme",
"license": "MIT",
"dependencies": {
"bcrypt": "^3.0.3",
"body-parser": "^1.18.3",
"chalk": "^2.4.2",
"cors": "^2.8.4",
Expand Down
99 changes: 59 additions & 40 deletions server/migrations/20190204141619-create-users.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,61 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('users', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
username: {
type: Sequelize.STRING
},
email: {
type: Sequelize.STRING
},
password: {
type: Sequelize.STRING
},
bio: {
type: Sequelize.TEXT
},
imageUrl: {
type: Sequelize.STRING
},
isVerified: {
type: Sequelize.BOOLEAN
},
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('User', {
id: {
allowNull: false,
primaryKey: true,
type: Sequelize.UUID,
defaultValue: Sequelize.literal('uuid_generate_v4()')
},
username: {
allowNull: {
args: false,
msg: 'Please enter a username'
},
type: Sequelize.STRING,
unique: {
args: true,
msg: 'Username already exist'
},
},
email: {
allowNull: false,
type: Sequelize.STRING,
unique: true,
validate: {
isEmail: true
}
},
password: {
allowNull: {
args: false,
msg: 'Please enter a password'
},
type: Sequelize.STRING,
validate: {
len: [8, 72]
},
},
bio: {
type: Sequelize.TEXT
},
imageUrl: {
type: Sequelize.STRING
},
isVerified: {
allowNull: false,
type: Sequelize.BOOLEAN
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
}));
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('users');
}
};
down: queryInterface => queryInterface.dropTable('User'),
};
27 changes: 27 additions & 0 deletions server/migrations/20190204142642-create-user-follower.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
up: (queryInterface, Sequelize) => queryInterface.createTable('UserFollower', {
userId: {
allowNull: false,
type: Sequelize.UUID,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
onDelete: 'CASCADE',
references: {
model: 'User',
key: 'id',
as: 'userId',
},
},
followerId: {
allowNull: false,
type: Sequelize.UUID,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
onDelete: 'CASCADE',
references: {
model: 'User',
key: 'id',
as: 'followerId',
}
}
}),
down: queryInterface => queryInterface.dropTable('UserFollower'),
};
15 changes: 15 additions & 0 deletions server/migrations/20190204144944-create-category.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
up: (queryInterface, Sequelize) => queryInterface.createTable('Category', {
id: {
allowNull: false,
primaryKey: true,
autoIncrement: true,
type: Sequelize.INTEGER
},
categoryName: {
allowNull: false,
type: Sequelize.TEXT
},
}),
down: queryInterface => queryInterface.dropTable('Category')
};
64 changes: 64 additions & 0 deletions server/migrations/20190204145037-create-articles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module.exports = {
up: (queryInterface, Sequelize) => queryInterface.createTable('Article', {
id: {
allowNull: false,
primaryKey: true,
type: Sequelize.UUID,
defaultValue: Sequelize.literal('uuid_generate_v4()')
},
slug: {
allowNull: {
args: false,
msg: 'Please enter a title'
},
type: Sequelize.TEXT
},
body: {
allowNull: {
args: false,
msg: 'Please enter your text'
},
type: Sequelize.TEXT
},
description: {
allowNull: {
args: false,
msg: 'Please give description'
},
type: Sequelize.TEXT
},
authorId: {
allowNull: false,
type: Sequelize.UUID,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
onDelete: 'CASCADE',
references: {
model: 'User',
key: 'id',
as: 'authorId',
},
},
references: {
type: Sequelize.ARRAY(Sequelize.STRING)
},
categoryId: {
allowNull: false,
type: Sequelize.INTEGER,
onDelete: 'CASCADE',
references: {
model: 'Category',
key: 'id',
as: 'categoryId',
},
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
}),
down: queryInterface => queryInterface.dropTable('Article')
};
41 changes: 41 additions & 0 deletions server/migrations/20190204150708-create-notifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = {
up: (queryInterface, Sequelize) => queryInterface.createTable('Notification', {
id: {
allowNull: false,
primaryKey: true,
type: Sequelize.UUID,
defaultValue: Sequelize.literal('uuid_generate_v4()')
},
userId: {
allowNull: false,
type: Sequelize.UUID,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
onDelete: 'CASCADE',
references: {
model: 'User',
key: 'id',
as: 'userId',
},
},
notificationBody: {
allowNull: {
args: false,
msg: 'What is the notification about?'
},
type: Sequelize.TEXT
},
seen: {
allowNull: false,
type: Sequelize.BOOLEAN
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
}),
down: queryInterface => queryInterface.dropTable('Notification')
};
40 changes: 40 additions & 0 deletions server/migrations/20190204152147-create-bookmarks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@


module.exports = {
up: (queryInterface, Sequelize) => queryInterface.createTable('Bookmark', {
id: {
allowNull: false,
primaryKey: true,
type: Sequelize.UUID,
defaultValue: Sequelize.literal('uuid_generate_v4()')
},
articleId: {
allowNull: false,
type: Sequelize.UUID,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
onDelete: 'CASCADE',
references: {
model: 'Article',
key: 'id',
as: 'articleId',
},
},
userId: {
allowNull: false,
type: Sequelize.UUID,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
onDelete: 'CASCADE',
references: {
model: 'User',
key: 'id',
as: 'userId',
},
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
}),
// eslint-disable-next-line no-unused-vars
down: queryInterface => queryInterface.dropTable('Bookmark')
};
39 changes: 39 additions & 0 deletions server/migrations/20190204152533-create-comments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@


module.exports = {
up: (queryInterface, Sequelize) => queryInterface.createTable('Comment', {
id: {
allowNull: false,
primaryKey: true,
type: Sequelize.UUID,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
},
articleId: {
allowNull: false,
type: Sequelize.UUID,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
onDelete: 'CASCADE',
references: {
model: 'Article',
key: 'id',
as: 'articleId',
},
},
commentBody: {
allowNull: {
args: false,
msg: 'Please write your comment?'
},
type: Sequelize.TEXT
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
}),
down: queryInterface => queryInterface.dropTable('Comment')
};
16 changes: 16 additions & 0 deletions server/migrations/20190204153144-create-tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


module.exports = {
up: (queryInterface, Sequelize) => queryInterface.createTable('Tag', {
id: {
allowNull: false,
primaryKey: true,
type: Sequelize.UUID,
defaultValue: Sequelize.literal('uuid_generate_v4()')
},
tagText: {
type: Sequelize.TEXT
},
}),
down: queryInterface => queryInterface.dropTable('Tag')
};
27 changes: 27 additions & 0 deletions server/migrations/20190204153340-create-tags-article.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
up: (queryInterface, Sequelize) => queryInterface.createTable('TagArticle', {
tagId: {
allowNull: false,
type: Sequelize.UUID,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
onDelete: 'CASCADE',
references: {
model: 'Tag',
key: 'id',
as: 'tagId',
},
},
articleId: {
allowNull: false,
type: Sequelize.UUID,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
onDelete: 'CASCADE',
references: {
model: 'Article',
key: 'id',
as: 'articleId',
},
},
}),
down: queryInterface => queryInterface.dropTable('TagArticle')
};
Loading

0 comments on commit 440879e

Please sign in to comment.