-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
724 additions
and
17 deletions.
There are no files selected for viewing
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
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,29 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('Categories', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
name: { | ||
type: Sequelize.STRING, | ||
unique: true, | ||
allowNull: false | ||
}, | ||
description: { | ||
type: Sequelize.STRING | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}), | ||
down: queryInterface => queryInterface.dropTable('Categories') | ||
}; |
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,29 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('Tags', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
name: { | ||
type: Sequelize.STRING, | ||
unique: true, | ||
allowNull: false | ||
}, | ||
description: { | ||
type: Sequelize.STRING | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}), | ||
down: queryInterface => queryInterface.dropTable('Tags') | ||
}; |
27 changes: 27 additions & 0 deletions
27
server/db/migrations/20190803192656-create-article-tags.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,27 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('ArticleTags', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
articleId: { | ||
type: Sequelize.INTEGER | ||
}, | ||
tagId: { | ||
type: Sequelize.INTEGER | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}), | ||
down: queryInterface => queryInterface.dropTable('ArticleTags') | ||
}; |
27 changes: 27 additions & 0 deletions
27
server/db/migrations/20190803193836-create-article-categories.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,27 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('ArticleCategories', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
articleId: { | ||
type: Sequelize.INTEGER | ||
}, | ||
categoryId: { | ||
type: Sequelize.INTEGER | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}), | ||
down: queryInterface => queryInterface.dropTable('ArticleCategories') | ||
}; |
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,14 @@ | ||
/* eslint-disable func-names */ | ||
|
||
'use strict'; | ||
|
||
module.exports = (sequelize, DataTypes) => { | ||
const ArticleCategories = sequelize.define('ArticleCategories', { | ||
articleId: DataTypes.INTEGER, | ||
categoryId: DataTypes.INTEGER | ||
}, {}); | ||
ArticleCategories.associate = function () { | ||
// associations can be defined here | ||
}; | ||
return ArticleCategories; | ||
}; |
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,14 @@ | ||
/* eslint-disable func-names */ | ||
|
||
'use strict'; | ||
|
||
module.exports = (sequelize, DataTypes) => { | ||
const ArticleTags = sequelize.define('ArticleTags', { | ||
articleId: DataTypes.INTEGER, | ||
tagId: DataTypes.INTEGER | ||
}, {}); | ||
ArticleTags.associate = function () { | ||
// associations can be defined here | ||
}; | ||
return ArticleTags; | ||
}; |
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,17 @@ | ||
/* eslint-disable func-names */ | ||
|
||
'use strict'; | ||
|
||
module.exports = (sequelize, DataTypes) => { | ||
const Categories = sequelize.define('Categories', { | ||
name: DataTypes.STRING, | ||
description: DataTypes.STRING | ||
}, {}); | ||
Categories.associate = function (models) { | ||
Categories.belongsToMany(models.Article, { | ||
through: 'ArticleCategories', | ||
foreignKey: 'categoryId' | ||
}); | ||
}; | ||
return Categories; | ||
}; |
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,17 @@ | ||
/* eslint-disable func-names */ | ||
|
||
'use strict'; | ||
|
||
module.exports = (sequelize, DataTypes) => { | ||
const Tags = sequelize.define('Tags', { | ||
name: DataTypes.STRING, | ||
description: DataTypes.STRING | ||
}, {}); | ||
Tags.associate = function (models) { | ||
Tags.belongsToMany(models.Article, { | ||
through: 'ArticleTags', | ||
foreignKey: 'tagId' | ||
}); | ||
}; | ||
return Tags; | ||
}; |
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,28 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const faker = require('faker'); | ||
|
||
module.exports = { | ||
up: (queryInterface) => { | ||
const randomArticles = _.times(30, () => ({ | ||
title: faker.name.title(), | ||
description: faker.lorem.sentence(), | ||
articleBody: faker.lorem.sentence(), | ||
uuid: faker.random.number({ max: '300' }), | ||
slug: faker.lorem.words(), | ||
image: faker.lorem.sentence(), | ||
authorId: faker.random.number({ | ||
min: 1, | ||
max: 12 | ||
}), | ||
favorited: true, | ||
favoriteCounts: 25, | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
})); | ||
return queryInterface.bulkInsert('Articles', randomArticles, {}); | ||
}, | ||
|
||
down: queryInterface => queryInterface.bulkDelete('Articles', 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
const faker = require('faker'); | ||
|
||
const categories = ['technology', 'health', 'science', 'fashion', 'education', 'culture', 'lifestyle']; | ||
|
||
module.exports = { | ||
up: (queryInterface) => { | ||
const randomCategories = categories.map(item => ({ | ||
name: item, | ||
description: faker.lorem.sentence(), | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
})); | ||
|
||
return queryInterface.bulkInsert('Categories', randomCategories, {}); | ||
}, | ||
|
||
down: queryInterface => queryInterface.bulkDelete('Categories', null, {}) | ||
}; |
25 changes: 25 additions & 0 deletions
25
server/db/seeders/20190803194616-demo-articleCategories.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,25 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const faker = require('faker'); | ||
|
||
module.exports = { | ||
up: (queryInterface) => { | ||
const articleCategories = _.times(30, () => ({ | ||
articleId: faker.random.number({ | ||
min: 1, | ||
max: 30 | ||
}), | ||
categoryId: faker.random.number({ | ||
min: 1, | ||
max: 7 | ||
}), | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
})); | ||
|
||
return queryInterface.bulkInsert('ArticleCategories', articleCategories, {}); | ||
}, | ||
|
||
down: queryInterface => queryInterface.bulkDelete('ArticleCategories', 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
const faker = require('faker'); | ||
|
||
const tags = ['javascript', 'AI', 'travel', 'peace', 'believe', 'race', 'react', 'tutorial', 'knowledge']; | ||
module.exports = { | ||
up: (queryInterface) => { | ||
const randomCategories = tags.map(item => ({ | ||
name: item, | ||
description: faker.lorem.sentence(), | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
})); | ||
|
||
return queryInterface.bulkInsert('Tags', randomCategories, {}); | ||
}, | ||
|
||
down: queryInterface => queryInterface.bulkDelete('Tags', 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const faker = require('faker'); | ||
|
||
module.exports = { | ||
up: (queryInterface) => { | ||
const articleCategories = _.times(30, () => ({ | ||
articleId: faker.random.number({ | ||
min: 1, | ||
max: 30 | ||
}), | ||
tagId: faker.random.number({ | ||
min: 1, | ||
max: 9 | ||
}), | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
})); | ||
|
||
return queryInterface.bulkInsert('ArticleTags', articleCategories, {}); | ||
}, | ||
|
||
down: queryInterface => queryInterface.bulkDelete('ArticleTags', null, {}) | ||
}; |
Oops, something went wrong.