From ac293cda1ce8d8fc95b02981820ef81f091fb4e4 Mon Sep 17 00:00:00 2001 From: andres-portainer <91705312+andres-portainer@users.noreply.github.com> Date: Fri, 18 Oct 2024 10:33:10 -0300 Subject: [PATCH] feat(database): share more database code between CE and EE BE-11303 (#43) --- api/database/boltdb/export.go | 29 ++++++++----------- .../test_data/output_24_to_latest.json | 13 ++++++++- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/api/database/boltdb/export.go b/api/database/boltdb/export.go index 547b7c3df..68edb402f 100644 --- a/api/database/boltdb/export.go +++ b/api/database/boltdb/export.go @@ -49,8 +49,8 @@ func (c *DbConnection) ExportJSON(databasePath string, metadata bool) ([]byte, e backup["__metadata"] = meta } - err = connection.View(func(tx *bolt.Tx) error { - err = tx.ForEach(func(name []byte, bucket *bolt.Bucket) error { + if err := connection.View(func(tx *bolt.Tx) error { + return tx.ForEach(func(name []byte, bucket *bolt.Bucket) error { bucketName := string(name) var list []any version := make(map[string]string) @@ -84,27 +84,22 @@ func (c *DbConnection) ExportJSON(databasePath string, metadata bool) ([]byte, e return nil } - if len(list) > 0 { - if bucketName == "ssl" || - bucketName == "settings" || - bucketName == "tunnel_server" { - backup[bucketName] = nil - if len(list) > 0 { - backup[bucketName] = list[0] - } - return nil + if bucketName == "ssl" || + bucketName == "settings" || + bucketName == "tunnel_server" { + backup[bucketName] = nil + if len(list) > 0 { + backup[bucketName] = list[0] } - backup[bucketName] = list + return nil } + backup[bucketName] = list + return nil }) - - return err - }) - - if err != nil { + }); err != nil { return []byte("{}"), err } diff --git a/api/datastore/test_data/output_24_to_latest.json b/api/datastore/test_data/output_24_to_latest.json index f6436b8d7..03ea15f5f 100644 --- a/api/datastore/test_data/output_24_to_latest.json +++ b/api/datastore/test_data/output_24_to_latest.json @@ -1,10 +1,15 @@ { + "api_key": null, + "customtemplates": null, "dockerhub": [ { "Authentication": false, "Username": "" } ], + "edge_stack": null, + "edgegroups": null, + "edgejobs": null, "endpoint_groups": [ { "AuthorizedTeams": null, @@ -103,6 +108,9 @@ "UserAccessPolicies": {} } ], + "extension": null, + "helm_user_repository": null, + "pending_actions": null, "registries": [ { "Authentication": true, @@ -860,6 +868,8 @@ "UpdatedBy": "" } ], + "tags": null, + "team_membership": null, "teams": [ { "Id": 1, @@ -933,5 +943,6 @@ ], "version": { "VERSION": "{\"SchemaVersion\":\"2.23.0\",\"MigratorCount\":0,\"Edition\":1,\"InstanceID\":\"463d5c47-0ea5-4aca-85b1-405ceefee254\"}" - } + }, + "webhooks": null } \ No newline at end of file