@@ -14,6 +14,7 @@ type DatabaseBranch struct {
14
14
Name string `json:"name"`
15
15
ParentBranch string `json:"parent_branch"`
16
16
Region Region `json:"region"`
17
+ Production bool `json:"production"`
17
18
CreatedAt time.Time `json:"created_at"`
18
19
UpdatedAt time.Time `json:"updated_at"`
19
20
Status string `json:"status,omitempty"`
@@ -86,6 +87,14 @@ type RefreshSchemaRequest struct {
86
87
Branch string `json:"-"`
87
88
}
88
89
90
+ // PromoteBranchRequest encapsulates the request for promoting a branch to
91
+ // production.
92
+ type PromoteBranchRequest struct {
93
+ Organization string `json:"-"`
94
+ Database string `json:"-"`
95
+ Branch string `json:"branch"`
96
+ }
97
+
89
98
// DatabaseBranchesService is an interface for communicating with the PlanetScale
90
99
// Database Branch API endpoint.
91
100
type DatabaseBranchesService interface {
@@ -97,6 +106,7 @@ type DatabaseBranchesService interface {
97
106
Diff (context.Context , * DiffBranchRequest ) ([]* Diff , error )
98
107
Schema (context.Context , * BranchSchemaRequest ) ([]* Diff , error )
99
108
RefreshSchema (context.Context , * RefreshSchemaRequest ) error
109
+ Promote (context.Context , * PromoteBranchRequest ) (* DatabaseBranch , error )
100
110
}
101
111
102
112
type databaseBranchesService struct {
@@ -243,6 +253,24 @@ func (d *databaseBranchesService) RefreshSchema(ctx context.Context, refreshReq
243
253
return nil
244
254
}
245
255
256
+ // PromoteBranch promotes a database's branch from a development branch to a
257
+ // production branch.
258
+ func (d * databaseBranchesService ) Promote (ctx context.Context , promoteReq * PromoteBranchRequest ) (* DatabaseBranch , error ) {
259
+ path := fmt .Sprintf ("%s/%s/promote-branch" , databasesAPIPath (promoteReq .Organization ), promoteReq .Database )
260
+ req , err := d .client .newRequest (http .MethodPost , path , promoteReq )
261
+ if err != nil {
262
+ return nil , errors .Wrap (err , "error creating request for branch promotion" )
263
+ }
264
+
265
+ branch := & DatabaseBranch {}
266
+ err = d .client .do (ctx , req , & branch )
267
+ if err != nil {
268
+ return nil , err
269
+ }
270
+
271
+ return branch , nil
272
+ }
273
+
246
274
func databaseBranchesAPIPath (org , db string ) string {
247
275
return fmt .Sprintf ("%s/%s/branches" , databasesAPIPath (org ), db )
248
276
}
0 commit comments