Cloudmigration: create migration (#85386)
* Cloudmigration: create migration
* fix drone build
* lint fix
* fix unit test
---------
Co-authored-by: Michael Mandrus <michael.mandrus@grafana.com>
(cherry picked from commit 383ebb2bc4)
Co-authored-by: Leonard Gram <leo@xlson.com>
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package cloudmigrationimpl
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/db"
|
|
"github.com/grafana/grafana/pkg/services/cloudmigration"
|
|
)
|
|
|
|
type sqlStore struct {
|
|
db db.DB
|
|
}
|
|
|
|
func (ss *sqlStore) MigrateDatasources(ctx context.Context, request *cloudmigration.MigrateDatasourcesRequest) (*cloudmigration.MigrateDatasourcesResponse, error) {
|
|
return nil, cloudmigration.ErrInternalNotImplementedError
|
|
}
|
|
|
|
func (ss *sqlStore) CreateMigration(ctx context.Context, migration cloudmigration.CloudMigration) error {
|
|
err := ss.db.WithDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
|
migration.Created = time.Now()
|
|
migration.Updated = time.Now()
|
|
_, err := sess.Insert(migration)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (ss *sqlStore) GetAllCloudMigrations(ctx context.Context) ([]*cloudmigration.CloudMigration, error) {
|
|
var migrations = make([]*cloudmigration.CloudMigration, 0)
|
|
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error { return sess.Find(&migrations) })
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return migrations, nil
|
|
}
|