Files
grafana/pkg/services/folder/model.go
T
Kristin Laemmert b346ae0310 feat: add new Folder table migration & define nested folder interfaces (#56882)
* feat: add new Folder table migration

Add a new folder table to support the Nested Folders feature.

https://github.com/grafana/grafana/issues/56880

* register nested folders feature flag (unused)

* feat: nested folder service (experiment)

This commit adds a NestedFolderSvc interface and stubbed out implementation as an alternative to the existing folder service. This is an experimental feature to try out different methods for backwards compatibility and parallelization, so that Grafana can continue to store folders in the existing (non-nested) manner while also using the new nested folder service.

Eventually the new service will (hopefully) become _the_ service, at which point the legacy service can be deprecated (or remain, with the new service methods replacing the original. whatever makes sense at the time).


* nested folders: don't run the new migration

This commit removes the nested folder migration from the list of active migrations so we can merge this branch and continue development without impacting Grafana instances built off main.
2022-10-26 10:15:14 -04:00

101 lines
2.5 KiB
Go

package folder
import (
"time"
)
const (
GeneralFolderUID = "general"
MaxNestedFolderDepth = 8
)
type Folder struct {
ID int64
OrgID int64
UID string
ParentUID string
Title string
Description string
// TODO: is URL relevant for folders?
URL string
Created time.Time
Updated time.Time
// TODO: are these next three relevant for folders?
UpdatedBy int64
CreatedBy int64
HasACL bool
}
// NewFolder tales a title and returns a Folder with the Created and Updated
// fields set to the current time.
func NewFolder(title string, description string) *Folder {
return &Folder{
Title: title,
Description: description,
Created: time.Now(),
Updated: time.Now(),
}
}
// CreateFolderCommand captures the information required by the folder service
// to create a folder.
type CreateFolderCommand struct {
UID string `json:"uid"`
Title string `json:"title"`
Description string `json:"description"`
ParentUID string `json:"parent_uid"`
}
// UpdateFolderCommand captures the information required by the folder service
// to update a folder. Use Move to update a folder's parent folder.
type UpdateFolderCommand struct {
Folder *Folder `json:"folder"` // The extant folder
NewUID *string `json:"uid"`
NewTitle *string `json:"title"`
NewDescription *string `json:"description"`
}
// MoveFolderCommand captures the information required by the folder service
// to move a folder.
type MoveFolderCommand struct {
UID string `json:"uid"`
NewParentUID string `json:"new_parent_uid"`
}
// DeleteFolderCommand captures the information required by the folder service
// to delete a folder.
type DeleteFolderCommand struct {
UID string `json:"uid"`
}
// GetFolderCommand is used for all folder Get requests. Only one of UID, ID, or
// Title should be set; if multilpe fields are set by the caller the dashboard
// service will select the field with the most specificity, in order: ID, UID,
// Title.
type GetFolderCommand struct {
UID *string
ID *int
Title *string
}
// GetParentsCommand captures the information required by the folder service to
// return a list of all parent folders of a given folder.
type GetParentsCommand struct {
UID string
}
// GetTreeCommand captures the information required by the folder service to
// return a list of child folders of the given folder.
type GetTreeCommand struct {
UID string
Depth int64
// Pagination options
Limit int64
Page int64
}