(collection *core.Collection)
| 366 | } |
| 367 | |
| 368 | func (p *plugin) goCreateTemplate(collection *core.Collection) (string, error) { |
| 369 | // unset timestamp fields |
| 370 | collectionData, err := toMap(collection) |
| 371 | if err != nil { |
| 372 | return "", err |
| 373 | } |
| 374 | delete(collectionData, "created") |
| 375 | delete(collectionData, "updated") |
| 376 | deleteNestedMapKey(collectionData, "oauth2", "providers") |
| 377 | |
| 378 | jsonData, err := marhshalWithoutEscape(collectionData, "\t\t", "\t") |
| 379 | if err != nil { |
| 380 | return "", fmt.Errorf("failed to serialize collections list: %w", err) |
| 381 | } |
| 382 | |
| 383 | const template = `package %s |
| 384 | |
| 385 | import ( |
| 386 | "encoding/json" |
| 387 | |
| 388 | "github.com/pocketbase/pocketbase/core" |
| 389 | m "github.com/pocketbase/pocketbase/migrations" |
| 390 | ) |
| 391 | |
| 392 | func init() { |
| 393 | m.Register(func(app core.App) error { |
| 394 | jsonData := ` + "`%s`" + ` |
| 395 | |
| 396 | collection := &core.Collection{} |
| 397 | if err := json.Unmarshal([]byte(jsonData), &collection); err != nil { |
| 398 | return err |
| 399 | } |
| 400 | |
| 401 | return app.Save(collection) |
| 402 | }, func(app core.App) error { |
| 403 | collection, err := app.FindCollectionByNameOrId(%q) |
| 404 | if err != nil { |
| 405 | return err |
| 406 | } |
| 407 | |
| 408 | return app.Delete(collection) |
| 409 | }) |
| 410 | } |
| 411 | ` |
| 412 | |
| 413 | return fmt.Sprintf( |
| 414 | template, |
| 415 | filepath.Base(p.config.Dir), |
| 416 | escapeBacktick(string(jsonData)), |
| 417 | collection.Id, |
| 418 | ), nil |
| 419 | } |
| 420 | |
| 421 | func (p *plugin) goDeleteTemplate(collection *core.Collection) (string, error) { |
| 422 | // unset timestamp fields |
no test coverage detected