Skip to content

Commit

Permalink
feat: Implement backup and restore of dev-server database (#488)
Browse files Browse the repository at this point in the history
feat: Implement backup and restore of dev-server database (#488)
  • Loading branch information
dmashuda authored Feb 6, 2025
1 parent 824da88 commit f0dd661
Show file tree
Hide file tree
Showing 11 changed files with 756 additions and 17 deletions.
28 changes: 27 additions & 1 deletion internal/dev_server/api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ info:
servers:
- url: "http"
paths:
/dev/backup:
get:
summary: get the backup
operationId: getBackup
responses:
200:
$ref: "#/components/responses/DbBackup"
post:
summary: post backup
operationId: restoreBackup
requestBody:
content:
application/vnd.sqlite3:
schema:
type: string
format: binary
responses:
200:
description: 'Backup restored'
/dev/projects:
get:
summary: lists all projects that have been configured for the dev server
Expand Down Expand Up @@ -142,7 +161,7 @@ paths:
description: limit the number of environments returned
required: false
schema:
type: integer
type: integer
responses:
200:
description: OK. List of environments
Expand Down Expand Up @@ -286,6 +305,13 @@ components:
application/json:
schema:
$ref: "#/components/schemas/Project"
DbBackup:
description: A backup of the local sqlite database
content:
application/vnd.sqlite3:
schema:
type: string
format: binary
ErrorResponse:
description: Error response object
content:
Expand Down
21 changes: 21 additions & 0 deletions internal/dev_server/api/get_backup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package api

import (
"context"

"github.com/launchdarkly/ldcli/internal/dev_server/model"
)

func (s server) GetBackup(ctx context.Context, request GetBackupRequestObject) (GetBackupResponseObject, error) {
store := model.StoreFromContext(ctx)
backup, size, err := store.CreateBackup(ctx)
if err != nil {
return nil, err
}

return GetBackup200ApplicationvndSqlite3Response{DbBackupApplicationvndSqlite3Response{
Body: backup,
ContentLength: size,
}}, nil

}
14 changes: 14 additions & 0 deletions internal/dev_server/api/restore_backup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package api

import (
"context"
"github.com/launchdarkly/ldcli/internal/dev_server/model"
)

func (s server) RestoreBackup(ctx context.Context, request RestoreBackupRequestObject) (RestoreBackupResponseObject, error) {
err := model.RestoreDb(ctx, request.Body)
if err != nil {
return nil, err
}
return RestoreBackup200Response{}, nil
}
144 changes: 144 additions & 0 deletions internal/dev_server/api/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f0dd661

Please sign in to comment.