UNPKG

1.24 kBJavaScriptView Raw
1"use strict";
2
3var _ = require('lodash');
4var AppError = require('../core/app-error');
5
6module.exports = function(sequelize, DataTypes) {
7 var Deployments = sequelize.define("Deployments", {
8 id: {
9 type: DataTypes.INTEGER(10),
10 allowNull: false,
11 autoIncrement: true,
12 primaryKey: true
13 },
14 appid: DataTypes.INTEGER(10),
15 name: DataTypes.STRING,
16 description: DataTypes.STRING,
17 deployment_key: DataTypes.STRING,
18 last_deployment_version_id: DataTypes.INTEGER(10),
19 label_id: DataTypes.INTEGER(10),
20 created_at: DataTypes.DATE,
21 updated_at: DataTypes.DATE,
22 }, {
23 tableName: 'deployments',
24 underscored: true,
25 paranoid: true
26 });
27
28 Deployments.generateLabelId = function(deploymentId) {
29 var self = this;
30 return sequelize.transaction(function (t) {
31 return self.findById(deploymentId, {transaction: t,lock: t.LOCK.UPDATE}).then(function (data) {
32 if (_.isEmpty(data)){
33 throw new AppError.AppError("does not find deployment");
34 }
35 data.label_id = data.label_id + 1;
36 return data.save({transaction: t})
37 .then(function (data) {
38 return data.label_id;
39 });
40 });
41 });
42 };
43
44 return Deployments;
45};