-
Notifications
You must be signed in to change notification settings - Fork 57
/
db.js
62 lines (56 loc) · 1.09 KB
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import Sequelize from 'sequelize';
import Faker from 'faker';
import _ from 'lodash';
const Conn = new Sequelize(
'relay',
'postgres',
'postgres',
{
dialect: 'postgres',
host: 'localhost'
}
);
const Person = Conn.define('person', {
firstName: {
type: Sequelize.STRING,
allowNull: false
},
lastName: {
type: Sequelize.STRING,
allowNull: false
},
email: {
type: Sequelize.STRING,
validate: {
isEmail: true
}
}
});
const Post = Conn.define('post', {
title: {
type: Sequelize.STRING,
allowNull: false
},
content: {
type: Sequelize.STRING,
allowNull: false
}
});
// Relations
Person.hasMany(Post);
Post.belongsTo(Person);
Conn.sync({ force: true }).then(()=> {
_.times(10, ()=> {
return Person.create({
firstName: Faker.name.firstName(),
lastName: Faker.name.lastName(),
email: Faker.internet.email()
}).then(person => {
return person.createPost({
title: `Sample post by ${person.firstName}`,
content: 'here is some content'
});
});
});
});
export default Conn;