-
Notifications
You must be signed in to change notification settings - Fork 573
/
Copy pathdeployments.js
45 lines (41 loc) · 1.21 KB
/
deployments.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
"use strict";
var _ = require('lodash');
var AppError = require('../core/app-error');
module.exports = function(sequelize, DataTypes) {
var Deployments = sequelize.define("Deployments", {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
autoIncrement: true,
primaryKey: true
},
appid: DataTypes.INTEGER(10),
name: DataTypes.STRING,
description: DataTypes.STRING,
deployment_key: DataTypes.STRING,
last_deployment_version_id: DataTypes.INTEGER(10),
label_id: DataTypes.INTEGER(10),
created_at: DataTypes.DATE,
updated_at: DataTypes.DATE,
}, {
tableName: 'deployments',
underscored: true,
paranoid: true
});
Deployments.generateLabelId = function(deploymentId) {
var self = this;
return sequelize.transaction(function (t) {
return self.findById(deploymentId, {transaction: t,lock: t.LOCK.UPDATE}).then(function (data) {
if (_.isEmpty(data)){
throw new AppError.AppError("does not find deployment");
}
data.label_id = data.label_id + 1;
return data.save({transaction: t})
.then(function (data) {
return data.label_id;
});
});
});
};
return Deployments;
};