-
Notifications
You must be signed in to change notification settings - Fork 154
/
db.js
120 lines (111 loc) · 2.63 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Created by championswimmer on 15/05/17.
*/
const Sequelize = require('sequelize')
const config = require('../config')
const secrets = config.secrets
const sequelize = process.env.DATABASE_URL
? new Sequelize(process.env.DATABASE_URL)
: new Sequelize(secrets.BOSS_DB_NAME, secrets.BOSS_DB_USER, secrets.BOSS_DB_PASS, {
host: secrets.BOSS_DB_HOST || 'localhost',
dialect: 'postgres',
pool: {
max: 5,
min: 0,
idle: 10000
}
})
const User = sequelize.define('user', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
oneauthId: Sequelize.STRING,
username: Sequelize.STRING,
role: Sequelize.ENUM(['admin', 'user'])
})
const Claim = sequelize.define('claim', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
user: Sequelize.STRING,
issueUrl: Sequelize.STRING,
pullUrl: { type: Sequelize.STRING, unique: true },
repo: Sequelize.STRING,
reason: Sequelize.STRING,
bounty: Sequelize.INTEGER,
status: Sequelize.ENUM(Object.keys(config.CLAIM_STATUS).map(key => config.CLAIM_STATUS[key])),
pr_resource_id: {
type: Sequelize.INTEGER,
allowNull: true
},
issue_resource_id: {
type: Sequelize.INTEGER,
allowNull: true
}
})
const GithubResource = sequelize.define(
'github_resource',
{
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
type: {
type: Sequelize.ENUM('ISSUE', 'PULL_REQUEST'),
unique: 'uk_type_resource_id_project_owner',
allowNull: false
},
resource_id: {
type: Sequelize.INTEGER,
unique: 'uk_type_resource_id_project_owner',
allowNull: false
},
owner: {
type: Sequelize.STRING,
unique: 'uk_type_resource_id_project_owner',
allowNull: false
},
project: {
type: Sequelize.STRING,
unique: 'uk_type_resource_id_project_owner',
allowNull: false
},
status: {
type: Sequelize.ENUM('OPEN', 'CLOSED', 'MERGED'),
allowNull: false,
defaultValue: 'OPEN'
}
},
{ indexes: [{ fields: ['type', 'resource_id', 'project'], unique: true }] }
)
Claim.belongsTo(GithubResource, {
as: 'pr',
foreignKey: 'pr_resource_id',
allowNull: true
})
Claim.belongsTo(GithubResource, {
as: 'issue',
foreignKey: 'issue_resource_id',
allowNull: true
})
GithubResource.hasMany(Claim, {
as: 'prClaim',
foreignKey: 'pr_resource_id'
})
GithubResource.hasMany(Claim, {
as: 'issueClaim',
foreignKey: 'issue_resource_id'
})
module.exports = {
Sequelize,
Database: sequelize,
Claim,
User,
GithubResource
}