Cloud migrations: store resource name in the cloud_migration_resource table (#93612)

* Cloud migrations: store resource name in the cloud_migration_resource table

* remove unused function: convertMigrateDataResponseToDTO

* make swagger-clean && make openapi3-gen

* use DB_Text for cloud_migration_resource.name instead of DB_Varchar
This commit is contained in:
Bruno 2024-09-26 11:16:52 -03:00 committed by GitHub
parent 2e559bb333
commit 1b7cd4c684
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 22 additions and 1 deletions

View File

@ -335,6 +335,7 @@ func (cma *CloudMigrationAPI) GetSnapshot(c *contextmodel.ReqContext) response.R
dtoResults := make([]MigrateDataResponseItemDTO, len(results))
for i := 0; i < len(results); i++ {
dtoResults[i] = MigrateDataResponseItemDTO{
Name: results[i].Name,
Type: MigrateDataType(results[i].Type),
RefID: results[i].RefID,
Status: ItemStatus(results[i].Status),

View File

@ -106,6 +106,7 @@ type MigrateDataResponseDTO struct {
}
type MigrateDataResponseItemDTO struct {
Name string `json:"name"`
// required:true
Type MigrateDataType `json:"type"`
// required:true

View File

@ -213,6 +213,7 @@ func Test_GetSnapshotStatusFromGMS(t *testing.T) {
State: cloudmigration.SnapshotStateFinished,
Results: []cloudmigration.CloudMigrationResource{
{
Name: "A name",
Type: cloudmigration.DatasourceDataType,
RefID: "A",
Status: cloudmigration.ItemStatusError,
@ -387,18 +388,21 @@ func Test_NonCoreDataSourcesHaveWarning(t *testing.T) {
State: cloudmigration.SnapshotStateFinished,
Results: []cloudmigration.CloudMigrationResource{
{
Name: "1 name",
Type: cloudmigration.DatasourceDataType,
RefID: "1", // this will be core
Status: cloudmigration.ItemStatusOK,
SnapshotUID: snapshotUid,
},
{
Name: "2 name",
Type: cloudmigration.DatasourceDataType,
RefID: "2", // this will be non-core
Status: cloudmigration.ItemStatusOK,
SnapshotUID: snapshotUid,
},
{
Name: "3 name",
Type: cloudmigration.DatasourceDataType,
RefID: "3", // this will be non-core with an error
Status: cloudmigration.ItemStatusError,
@ -406,6 +410,7 @@ func Test_NonCoreDataSourcesHaveWarning(t *testing.T) {
SnapshotUID: snapshotUid,
},
{
Name: "4 name",
Type: cloudmigration.DatasourceDataType,
RefID: "4", // this will be deleted
Status: cloudmigration.ItemStatusOK,

View File

@ -212,13 +212,14 @@ func (s *Service) buildSnapshot(ctx context.Context, signedInUser *user.SignedIn
resourcesGroupedByType := make(map[cloudmigration.MigrateDataType][]snapshot.MigrateDataRequestItemDTO, 0)
for i, item := range migrationData.Items {
resourcesGroupedByType[item.Type] = append(resourcesGroupedByType[item.Type], snapshot.MigrateDataRequestItemDTO{
Name: item.Name,
Type: snapshot.MigrateDataType(item.Type),
RefID: item.RefID,
Name: item.Name,
Data: item.Data,
})
localSnapshotResource[i] = cloudmigration.CloudMigrationResource{
Name: item.Name,
Type: item.Type,
RefID: item.RefID,
Status: cloudmigration.ItemStatusPending,

View File

@ -68,6 +68,7 @@ type CloudMigrationResource struct {
ID int64 `xorm:"pk autoincr 'id'"`
UID string `xorm:"uid"`
Name string `xorm:"name" json:"name"`
Type MigrateDataType `xorm:"resource_type" json:"type"`
RefID string `xorm:"resource_uid" json:"refId"`
Status ItemStatus `xorm:"status" json:"status"`

View File

@ -158,4 +158,10 @@ func addCloudMigrationsMigrations(mg *Migrator) {
// -- delete the snapshot result column while still in the experimental phase
mg.AddMigration("delete cloud_migration_snapshot.result column", NewRawSQLMigration("ALTER TABLE cloud_migration_snapshot DROP COLUMN result"))
mg.AddMigration("add cloud_migration_resource.name column", NewAddColumnMigration(migrationResourceTable, &Column{
Name: "name",
Type: DB_Text,
Nullable: true,
}))
}

View File

@ -16868,6 +16868,9 @@
"message": {
"type": "string"
},
"name": {
"type": "string"
},
"refId": {
"type": "string"
},

View File

@ -7095,6 +7095,9 @@
"message": {
"type": "string"
},
"name": {
"type": "string"
},
"refId": {
"type": "string"
},