2022-07-07 13:02:01 -05:00
|
|
|
package export
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path"
|
|
|
|
"time"
|
|
|
|
|
2022-10-19 08:02:15 -05:00
|
|
|
"github.com/grafana/grafana/pkg/infra/db"
|
2022-07-07 13:02:01 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func exportKVStore(helper *commitHelper, job *gitExportJob) error {
|
|
|
|
kvdir := path.Join(helper.orgDir, "system", "kv_store")
|
|
|
|
|
2022-10-19 08:02:15 -05:00
|
|
|
return job.sql.WithDbSession(helper.ctx, func(sess *db.Session) error {
|
2022-07-07 13:02:01 -05:00
|
|
|
type kvResult struct {
|
|
|
|
Namespace string `xorm:"namespace"`
|
|
|
|
Key string `xorm:"key"`
|
|
|
|
Value string `xorm:"value"`
|
|
|
|
Updated time.Time `xorm:"updated"`
|
|
|
|
}
|
|
|
|
|
|
|
|
rows := make([]*kvResult, 0)
|
|
|
|
|
|
|
|
sess.Table("kv_store").Where("org_id = ? OR org_id = 0", helper.orgID)
|
|
|
|
|
|
|
|
err := sess.Find(&rows)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, row := range rows {
|
|
|
|
err = helper.add(commitOptions{
|
|
|
|
body: []commitBody{{
|
|
|
|
body: []byte(row.Value),
|
|
|
|
fpath: path.Join(kvdir, row.Namespace, row.Key),
|
|
|
|
}},
|
|
|
|
comment: fmt.Sprintf("Exporting: %s/%s", row.Namespace, row.Key),
|
|
|
|
when: row.Updated,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|