-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathcreate.go
33 lines (25 loc) · 893 Bytes
/
create.go
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
// SPDX-License-Identifier: Apache-2.0
package deployment
import (
"context"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/database"
"github.com/go-vela/types/library"
"github.com/sirupsen/logrus"
)
// CreateDeployment creates a new deployment in the database.
func (e *engine) CreateDeployment(ctx context.Context, d *library.Deployment) (*library.Deployment, error) {
e.logger.WithFields(logrus.Fields{
"deployment": d.GetID(),
}).Tracef("creating deployment %d in the database", d.GetID())
// cast the library type to database type
deployment := database.DeploymentFromLibrary(d)
// validate the necessary fields are populated
err := deployment.Validate()
if err != nil {
return nil, err
}
result := e.client.Table(constants.TableDeployment).Create(deployment)
// send query to the database
return deployment.ToLibrary(d.Builds), result.Error
}