MCPcopy
hub / github.com/pocketbase/pocketbase / DBExport

Method DBExport

core/settings_model.go:245–284  ·  view source on GitHub ↗

DBExport prepares and exports the current settings for db persistence.

(app App)

Source from the content-addressed store, hash-verified

243
244// DBExport prepares and exports the current settings for db persistence.
245func (s *Settings) DBExport(app App) (map[string]any, error) {
246 s.mu.RLock()
247 defer s.mu.RUnlock()
248
249 now := types.NowDateTime()
250
251 result := map[string]any{
252 "id": s.PK(),
253 }
254
255 if s.IsNew() {
256 result["created"] = now
257 }
258 result["updated"] = now
259
260 // @todo remove with encoding/json/2
261 // serialize as empty array
262 if s.settings.SuperuserIPs == nil {
263 s.settings.SuperuserIPs = []string{}
264 }
265
266 encoded, err := json.Marshal(s.settings)
267 if err != nil {
268 return nil, err
269 }
270
271 encryptionKey := os.Getenv(app.EncryptionEnv())
272 if encryptionKey != "" {
273 encryptVal, encryptErr := security.Encrypt(encoded, encryptionKey)
274 if encryptErr != nil {
275 return nil, encryptErr
276 }
277
278 result["value"] = encryptVal
279 } else {
280 result["value"] = encoded
281 }
282
283 return result, nil
284}
285
286// PostValidate implements the [PostValidator] interface and defines
287// the Settings model validations.

Callers 1

TestSettings_DBExportFunction · 0.95

Calls 5

PKMethod · 0.95
IsNewMethod · 0.95
NowDateTimeFunction · 0.92
EncryptFunction · 0.92
EncryptionEnvMethod · 0.65

Tested by 1

TestSettings_DBExportFunction · 0.76