package migration

import (
	"time"

	"github.com/samber/lo"
	"gorm.io/gorm"
	"gorm.io/gorm/clause"

	globaldedicatedv1 "github.com/tidbcloud/tidb-management-service/api/spec/global/dedicated/v1"
	"github.com/tidbcloud/tidb-management-service/dedicated-global-service/infra/repoimpl/schema"
)

// Batch add Gravition4 SKUs
var _ = AddDBMigrateRecord(
	"202506041700",
	func(db *gorm.DB) error {
		timestamp := time.Now()

		return db.Transaction(func(tx *gorm.DB) error {
			// Fetch the AWS provider.
			var provider *schema.Provider
			if err := db.Where("name = ?", "aws").First(&provider).Error; err != nil {
				return err
			}

			// Add instance types.
			instanceTypes := []*schema.InstanceType{
				{
					InstanceType: "c8g.xlarge",
					ProviderId:   uint64(provider.ID),
					CPUNum:       4,
					MemorySizeGi: 8,
					CpuArch:      "arm64",
				},
				{
					InstanceType: "c8g.2xlarge",
					ProviderId:   uint64(provider.ID),
					CPUNum:       8,
					MemorySizeGi: 16,
					CpuArch:      "arm64",
				},
				{
					InstanceType: "c8g.4xlarge",
					ProviderId:   uint64(provider.ID),
					CPUNum:       16,
					MemorySizeGi: 32,
					CpuArch:      "arm64",
				},
				{
					InstanceType: "c8g.8xlarge",
					ProviderId:   uint64(provider.ID),
					CPUNum:       32,
					MemorySizeGi: 64,
					CpuArch:      "arm64",
				},

				{
					InstanceType: "m8g.large",
					ProviderId:   uint64(provider.ID),
					CPUNum:       2,
					MemorySizeGi: 8,
					CpuArch:      "arm64",
				},
				{
					InstanceType: "m8g.xlarge",
					ProviderId:   uint64(provider.ID),
					CPUNum:       4,
					MemorySizeGi: 16,
					CpuArch:      "arm64",
				},
				{
					InstanceType: "m8g.2xlarge",
					ProviderId:   uint64(provider.ID),
					CPUNum:       8,
					MemorySizeGi: 32,
					CpuArch:      "arm64",
				},
				{
					InstanceType: "m8g.4xlarge",
					ProviderId:   uint64(provider.ID),
					CPUNum:       16,
					MemorySizeGi: 64,
					CpuArch:      "arm64",
				},
				{
					InstanceType: "m8g.8xlarge",
					ProviderId:   uint64(provider.ID),
					CPUNum:       32,
					MemorySizeGi: 128,
					CpuArch:      "arm64",
				},
				{
					InstanceType: "m8g.16xlarge",
					ProviderId:   uint64(provider.ID),
					CPUNum:       64,
					MemorySizeGi: 256,
					CpuArch:      "arm64",
				},

				{
					InstanceType: "r8g.2xlarge",
					ProviderId:   uint64(provider.ID),
					CPUNum:       8,
					MemorySizeGi: 64,
					CpuArch:      "arm64",
				},
				{
					InstanceType: "r8g.4xlarge",
					ProviderId:   uint64(provider.ID),
					CPUNum:       16,
					MemorySizeGi: 128,
					CpuArch:      "arm64",
				},
				{
					InstanceType: "r8g.8xlarge",
					ProviderId:   uint64(provider.ID),
					CPUNum:       32,
					MemorySizeGi: 256,
					CpuArch:      "arm64",
				},
			}
			for _, instanceType := range instanceTypes {
				instanceType.CreatedAt = timestamp
				instanceType.UpdatedAt = timestamp
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "instance_type"}},
					UpdateAll: true,
				}).Create(instanceType).Error; err != nil { // The ID will be populated in the instanceType object after successful insertion
					return err
				}
			}
			instanceTypeMap := lo.SliceToMap(
				instanceTypes,
				func(i *schema.InstanceType) (string, *schema.InstanceType) {
					return i.InstanceType, i
				},
			)

			// Fetch storage for io2 and gp3 volumes.
			var io2Storage, gp3Storage *schema.StorageTemplate
			if err := db.Where("volume_type = ?", "io2").First(&io2Storage).Error; err != nil {
				return err
			}
			if err := db.Where("volume_type = ?", "gp3").First(&gp3Storage).Error; err != nil {
				return err
			}

			// Add tidb skus.
			{
				tidbSkus := make([]*schema.ComponentTierUnit, 0, 4)

				tidbSpu16c32g := &schema.ComponentTier{
					Key:           "16C32G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIDB",
					ComponentType: "tidb",
					DisplayName:   "16 vCPU, 32 GiB",
					CPUNum:        16,
					MemorySizeGi:  32,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tidbSpu16c32g).Error; err != nil {
					return err
				}
				tidbSkus = append(tidbSkus, &schema.ComponentTierUnit{
					Key:             "aws:tidb:c8g.4xlarge",
					Priority:        999,
					ComponentType:   "tidb",
					ProviderId:      uint64(provider.ID),
					ComponentTierId: uint64(tidbSpu16c32g.ID),
					InstanceTypeId:  uint64(instanceTypeMap["c8g.4xlarge"].ID),
					DefaultNodeNum:  2,
				})

				tidbSpu16c64g := &schema.ComponentTier{
					Key:           "16C64G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIDB",
					ComponentType: "tidb",
					DisplayName:   "16 vCPU, 64 GiB",
					CPUNum:        16,
					MemorySizeGi:  64,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tidbSpu16c64g).Error; err != nil {
					return err
				}
				tidbSkus = append(tidbSkus, &schema.ComponentTierUnit{
					Key:             "aws:tidb:m8g.4xlarge",
					Priority:        999,
					ComponentType:   "tidb",
					ProviderId:      uint64(provider.ID),
					ComponentTierId: uint64(tidbSpu16c64g.ID),
					InstanceTypeId:  uint64(instanceTypeMap["m8g.4xlarge"].ID),
					DefaultNodeNum:  2,
				})

				tidbSpu32c64g := &schema.ComponentTier{
					Key:           "32C64G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIDB",
					ComponentType: "tidb",
					DisplayName:   "32 vCPU, 64 GiB",
					CPUNum:        32,
					MemorySizeGi:  64,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tidbSpu32c64g).Error; err != nil {
					return err
				}
				tidbSkus = append(tidbSkus, &schema.ComponentTierUnit{
					Key:             "aws:tidb:c8g.8xlarge",
					Priority:        999,
					ComponentType:   "tidb",
					ProviderId:      uint64(provider.ID),
					ComponentTierId: uint64(tidbSpu32c64g.ID),
					InstanceTypeId:  uint64(instanceTypeMap["c8g.8xlarge"].ID),
					DefaultNodeNum:  2,
				})

				tidbSpu32c128g := &schema.ComponentTier{
					Key:           "32C128G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIDB",
					ComponentType: "tidb",
					DisplayName:   "32 vCPU, 128 GiB",
					CPUNum:        32,
					MemorySizeGi:  128,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tidbSpu32c128g).Error; err != nil {
					return err
				}
				tidbSkus = append(tidbSkus, &schema.ComponentTierUnit{
					Key:             "aws:tidb:m8g.8xlarge",
					Priority:        999,
					ComponentType:   "tidb",
					ProviderId:      uint64(provider.ID),
					ComponentTierId: uint64(tidbSpu32c128g.ID),
					InstanceTypeId:  uint64(instanceTypeMap["m8g.8xlarge"].ID),
					DefaultNodeNum:  2,
				})

				tidbSpu2c8g := &schema.ComponentTier{
					Key:           "2C8G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIDB",
					ComponentType: "tidb",
					DisplayName:   "2 vCPU, 8 GiB",
					CPUNum:        2,
					MemorySizeGi:  8,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tidbSpu2c8g).Error; err != nil {
					return err
				}
				tidbSkus = append(tidbSkus, &schema.ComponentTierUnit{
					Key:             "aws:tidb:m8g.large",
					Priority:        999,
					ComponentType:   "tidb",
					ProviderId:      uint64(provider.ID),
					ComponentTierId: uint64(tidbSpu2c8g.ID),
					InstanceTypeId:  uint64(instanceTypeMap["m8g.large"].ID),
					DefaultNodeNum:  2,
				})

				tidbSpu4c16g := &schema.ComponentTier{
					Key:           "4C16G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIDB",
					ComponentType: "tidb",
					DisplayName:   "4 vCPU, 16 GiB",
					CPUNum:        4,
					MemorySizeGi:  16,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tidbSpu4c16g).Error; err != nil {
					return err
				}
				tidbSkus = append(tidbSkus, &schema.ComponentTierUnit{
					Key:             "aws:tidb:m8g.xlarge",
					Priority:        999,
					ComponentType:   "tidb",
					ProviderId:      uint64(provider.ID),
					ComponentTierId: uint64(tidbSpu4c16g.ID),
					InstanceTypeId:  uint64(instanceTypeMap["m8g.xlarge"].ID),
					DefaultNodeNum:  2,
				})

				tidbSpu8c16g := &schema.ComponentTier{
					Key:           "8C16G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIDB",
					ComponentType: "tidb",
					DisplayName:   "8 vCPU, 16 GiB",
					CPUNum:        8,
					MemorySizeGi:  16,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tidbSpu8c16g).Error; err != nil {
					return err
				}
				tidbSkus = append(tidbSkus, &schema.ComponentTierUnit{
					Key:             "aws:tidb:c8g.2xlarge",
					Priority:        999,
					ComponentType:   "tidb",
					ProviderId:      uint64(provider.ID),
					ComponentTierId: uint64(tidbSpu8c16g.ID),
					InstanceTypeId:  uint64(instanceTypeMap["c8g.2xlarge"].ID),
					DefaultNodeNum:  2,
				})

				tidbSpu8c32g := &schema.ComponentTier{
					Key:           "8C32G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIDB",
					ComponentType: "tidb",
					DisplayName:   "8 vCPU, 32 GiB",
					CPUNum:        8,
					MemorySizeGi:  32,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tidbSpu8c32g).Error; err != nil {
					return err
				}
				tidbSkus = append(tidbSkus, &schema.ComponentTierUnit{
					Key:             "aws:tidb:m8g.2xlarge",
					Priority:        999,
					ComponentType:   "tidb",
					ProviderId:      uint64(provider.ID),
					ComponentTierId: uint64(tidbSpu8c32g.ID),
					InstanceTypeId:  uint64(instanceTypeMap["m8g.2xlarge"].ID),
					DefaultNodeNum:  2,
				})

				tidbSpu64c256g := &schema.ComponentTier{
					Key:           "64C256G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIDB",
					ComponentType: "tidb",
					DisplayName:   "64 vCPU, 256 GiB",
					CPUNum:        64,
					MemorySizeGi:  256,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tidbSpu64c256g).Error; err != nil {
					return err
				}
				tidbSkus = append(tidbSkus, &schema.ComponentTierUnit{
					Key:             "aws:tidb:m8g.16xlarge",
					Priority:        999,
					ComponentType:   "tidb",
					ProviderId:      uint64(provider.ID),
					ComponentTierId: uint64(tidbSpu64c256g.ID),
					InstanceTypeId:  uint64(instanceTypeMap["m8g.16xlarge"].ID),
					DefaultNodeNum:  2,
				})

				for _, tidbSku := range tidbSkus {
					tidbSku.CreatedAt = timestamp
					tidbSku.UpdatedAt = timestamp
					if err := tx.Clauses(clause.OnConflict{
						Columns:   []clause.Column{{Name: "key"}},
						UpdateAll: true,
					}).Create(tidbSku).Error; err != nil {
						return err
					}
				}
			}

			// Add tikv skus.
			{
				tikvSkus := make([]*schema.ComponentTierUnit, 0, 8)

				tikvSpu16c64g := &schema.ComponentTier{
					Key:           "16C64G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIKV",
					ComponentType: "tikv",
					DisplayName:   "16 vCPU, 64 GiB",
					CPUNum:        16,
					MemorySizeGi:  64,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tikvSpu16c64g).Error; err != nil {
					return err
				}
				tikvSkus = append(tikvSkus,
					&schema.ComponentTierUnit{
						Key:                    "aws:tikv:m8g.4xlarge:gp3:16000:1000:Standard",
						Priority:               999,
						ComponentType:          "tikv",
						ProviderId:             uint64(provider.ID),
						ComponentTierId:        uint64(tikvSpu16c64g.ID),
						InstanceTypeId:         uint64(instanceTypeMap["m8g.4xlarge"].ID),
						DefaultNodeNum:         3,
						StorageTemplateId:      lo.ToPtr(uint64(gp3Storage.ID)),
						MinStorageGi:           200,
						MaxStorageGi:           4096,
						DefaultStorageGi:       500,
						MaxIops:                16000,
						MinIops:                3000,
						IopsPerGi:              4,
						MaxThroughPut:          1000,
						MinThroughPut:          125,
						ThroughputMibpsPerGi:   0.5,
						ThroughputMibpsPerIops: 0.046875,
						RaftStorageTemplateId:  lo.ToPtr(uint64(gp3Storage.ID)),
						RaftDefaultStorageGi:   40,
						RaftMinStorageGi:       40,
						RaftMaxStorageGi:       40,
						RaftDefaultIops:        3000,
						RaftMaxIops:            3000,
						RaftMinIops:            3000,
						RaftDefaultThroughPut:  125,
						RaftMaxThroughPut:      125,
						RaftMinThroughPut:      125,
					},
					&schema.ComponentTierUnit{
						Key:                    "aws:tikv:m8g.4xlarge:gp3:16000:1000:Performance",
						Priority:               999,
						ComponentType:          "tikv",
						ProviderId:             uint64(provider.ID),
						ComponentTierId:        uint64(tikvSpu16c64g.ID),
						InstanceTypeId:         uint64(instanceTypeMap["m8g.4xlarge"].ID),
						DefaultNodeNum:         3,
						StorageTemplateId:      lo.ToPtr(uint64(gp3Storage.ID)),
						MinStorageGi:           200,
						MaxStorageGi:           4096,
						DefaultStorageGi:       500,
						MaxIops:                16000,
						MinIops:                3000,
						IopsPerGi:              4,
						MaxThroughPut:          1000,
						MinThroughPut:          125,
						ThroughputMibpsPerGi:   0.5,
						ThroughputMibpsPerIops: 0.046875,
						RaftStorageTemplateId:  lo.ToPtr(uint64(io2Storage.ID)),
						RaftDefaultStorageGi:   40,
						RaftMinStorageGi:       40,
						RaftMaxStorageGi:       40,
						RaftDefaultIops:        4000,
						RaftMaxIops:            4000,
						RaftMinIops:            4000,
					},
					&schema.ComponentTierUnit{
						Key:               "aws:tikv:m8g.4xlarge:io2:8000:0",
						Priority:          999,
						ComponentType:     "tikv",
						ProviderId:        uint64(provider.ID),
						ComponentTierId:   uint64(tikvSpu16c64g.ID),
						InstanceTypeId:    uint64(instanceTypeMap["m8g.4xlarge"].ID),
						DefaultNodeNum:    3,
						StorageTemplateId: lo.ToPtr(uint64(io2Storage.ID)),
						MinStorageGi:      200,
						MaxStorageGi:      4096,
						DefaultStorageGi:  500,
						DefaultIops:       8000,
						MaxIops:           8000,
						MinIops:           8000,
					})

				tikvSpu32c128g := &schema.ComponentTier{
					Key:           "32C128G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIKV",
					ComponentType: "tikv",
					DisplayName:   "32 vCPU, 128 GiB",
					CPUNum:        32,
					MemorySizeGi:  128,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tikvSpu32c128g).Error; err != nil {
					return err
				}
				tikvSkus = append(tikvSkus,
					&schema.ComponentTierUnit{
						Key:                    "aws:tikv:m8g.8xlarge:gp3:16000:1000:Standard",
						Priority:               999,
						ComponentType:          "tikv",
						ProviderId:             uint64(provider.ID),
						ComponentTierId:        uint64(tikvSpu32c128g.ID),
						InstanceTypeId:         uint64(instanceTypeMap["m8g.8xlarge"].ID),
						DefaultNodeNum:         3,
						StorageTemplateId:      lo.ToPtr(uint64(gp3Storage.ID)),
						MinStorageGi:           200,
						MaxStorageGi:           4096,
						DefaultStorageGi:       500,
						MaxIops:                16000,
						MinIops:                3000,
						IopsPerGi:              4,
						MaxThroughPut:          1000,
						MinThroughPut:          125,
						ThroughputMibpsPerGi:   0.5,
						ThroughputMibpsPerIops: 0.046875,
						RaftStorageTemplateId:  lo.ToPtr(uint64(gp3Storage.ID)),
						RaftDefaultStorageGi:   40,
						RaftMinStorageGi:       40,
						RaftMaxStorageGi:       40,
						RaftDefaultIops:        3000,
						RaftMaxIops:            3000,
						RaftMinIops:            3000,
						RaftDefaultThroughPut:  125,
						RaftMaxThroughPut:      125,
						RaftMinThroughPut:      125,
					},
					&schema.ComponentTierUnit{
						Key:                    "aws:tikv:m8g.8xlarge:gp3:16000:1000:Performance",
						Priority:               999,
						ComponentType:          "tikv",
						ProviderId:             uint64(provider.ID),
						ComponentTierId:        uint64(tikvSpu32c128g.ID),
						InstanceTypeId:         uint64(instanceTypeMap["m8g.8xlarge"].ID),
						DefaultNodeNum:         3,
						StorageTemplateId:      lo.ToPtr(uint64(gp3Storage.ID)),
						MinStorageGi:           200,
						MaxStorageGi:           4096,
						DefaultStorageGi:       500,
						MaxIops:                16000,
						MinIops:                3000,
						IopsPerGi:              4,
						MaxThroughPut:          1000,
						MinThroughPut:          125,
						ThroughputMibpsPerGi:   0.5,
						ThroughputMibpsPerIops: 0.046875,
						RaftStorageTemplateId:  lo.ToPtr(uint64(io2Storage.ID)),
						RaftDefaultStorageGi:   40,
						RaftMinStorageGi:       40,
						RaftMaxStorageGi:       40,
						RaftDefaultIops:        4000,
						RaftMaxIops:            4000,
						RaftMinIops:            4000,
					},
					&schema.ComponentTierUnit{
						Key:               "aws:tikv:m8g.8xlarge:io2:8000:0",
						Priority:          999,
						ComponentType:     "tikv",
						ProviderId:        uint64(provider.ID),
						ComponentTierId:   uint64(tikvSpu32c128g.ID),
						InstanceTypeId:    uint64(instanceTypeMap["m8g.8xlarge"].ID),
						DefaultNodeNum:    3,
						StorageTemplateId: lo.ToPtr(uint64(io2Storage.ID)),
						MinStorageGi:      200,
						MaxStorageGi:      4096,
						DefaultStorageGi:  500,
						DefaultIops:       8000,
						MaxIops:           8000,
						MinIops:           8000,
					})

				tikvSpu2c8g := &schema.ComponentTier{
					Key:           "2C8G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIKV",
					ComponentType: "tikv",
					DisplayName:   "2 vCPU, 8 GiB",
					CPUNum:        2,
					MemorySizeGi:  8,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tikvSpu2c8g).Error; err != nil {
					return err
				}
				tikvSkus = append(tikvSkus, &schema.ComponentTierUnit{
					Key:                    "aws:tikv:m8g.large:gp3:3000:125:Standard",
					Priority:               999,
					ComponentType:          "tikv",
					ProviderId:             uint64(provider.ID),
					ComponentTierId:        uint64(tikvSpu2c8g.ID),
					InstanceTypeId:         uint64(instanceTypeMap["m8g.large"].ID),
					DefaultNodeNum:         3,
					StorageTemplateId:      lo.ToPtr(uint64(gp3Storage.ID)),
					MinStorageGi:           200,
					MaxStorageGi:           500,
					DefaultStorageGi:       200,
					MaxIops:                16000,
					MinIops:                3000,
					IopsPerGi:              4,
					MaxThroughPut:          1000,
					MinThroughPut:          125,
					ThroughputMibpsPerGi:   0.5,
					ThroughputMibpsPerIops: 0.046875,
					RaftStorageTemplateId:  lo.ToPtr(uint64(gp3Storage.ID)),
					RaftDefaultStorageGi:   40,
					RaftMinStorageGi:       40,
					RaftMaxStorageGi:       40,
					RaftDefaultIops:        3000,
					RaftMaxIops:            3000,
					RaftMinIops:            3000,
					RaftDefaultThroughPut:  125,
					RaftMaxThroughPut:      125,
					RaftMinThroughPut:      125,
				})

				tikvSpu4c16g := &schema.ComponentTier{
					Key:           "4C16G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIKV",
					ComponentType: "tikv",
					DisplayName:   "4 vCPU, 16 GiB",
					CPUNum:        4,
					MemorySizeGi:  16,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tikvSpu4c16g).Error; err != nil {
					return err
				}
				tikvSkus = append(tikvSkus, &schema.ComponentTierUnit{
					Key:                    "aws:tikv:m8g.xlarge:gp3:3000:149:Standard",
					Priority:               999,
					ComponentType:          "tikv",
					ProviderId:             uint64(provider.ID),
					ComponentTierId:        uint64(tikvSpu4c16g.ID),
					InstanceTypeId:         uint64(instanceTypeMap["m8g.xlarge"].ID),
					DefaultNodeNum:         3,
					StorageTemplateId:      lo.ToPtr(uint64(gp3Storage.ID)),
					MinStorageGi:           200,
					MaxStorageGi:           500,
					DefaultStorageGi:       2048,
					MaxIops:                16000,
					MinIops:                3000,
					IopsPerGi:              4,
					MaxThroughPut:          1000,
					MinThroughPut:          125,
					ThroughputMibpsPerGi:   0.5,
					ThroughputMibpsPerIops: 0.046875,
					RaftStorageTemplateId:  lo.ToPtr(uint64(gp3Storage.ID)),
					RaftDefaultStorageGi:   40,
					RaftMinStorageGi:       40,
					RaftMaxStorageGi:       40,
					RaftDefaultIops:        3000,
					RaftMaxIops:            3000,
					RaftMinIops:            3000,
					RaftDefaultThroughPut:  125,
					RaftMaxThroughPut:      125,
					RaftMinThroughPut:      125,
				})

				tikvSpu8c32g := &schema.ComponentTier{
					Key:           "8C32G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIKV",
					ComponentType: "tikv",
					DisplayName:   "8 vCPU, 32 GiB",
					CPUNum:        8,
					MemorySizeGi:  32,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tikvSpu8c32g).Error; err != nil {
					return err
				}
				tikvSkus = append(tikvSkus,
					&schema.ComponentTierUnit{
						Key:                    "aws:tikv:m8g.2xlarge:gp3:4000:297:Standard",
						Priority:               999,
						ComponentType:          "tikv",
						ProviderId:             uint64(provider.ID),
						ComponentTierId:        uint64(tikvSpu8c32g.ID),
						InstanceTypeId:         uint64(instanceTypeMap["m8g.2xlarge"].ID),
						DefaultNodeNum:         3,
						StorageTemplateId:      lo.ToPtr(uint64(gp3Storage.ID)),
						MinStorageGi:           200,
						MaxStorageGi:           4096,
						DefaultStorageGi:       500,
						MaxIops:                16000,
						MinIops:                3000,
						IopsPerGi:              4,
						MaxThroughPut:          1000,
						MinThroughPut:          125,
						ThroughputMibpsPerGi:   0.5,
						ThroughputMibpsPerIops: 0.046875,
						RaftStorageTemplateId:  lo.ToPtr(uint64(gp3Storage.ID)),
						RaftDefaultStorageGi:   40,
						RaftMinStorageGi:       40,
						RaftMaxStorageGi:       40,
						RaftDefaultIops:        3000,
						RaftMaxIops:            3000,
						RaftMinIops:            3000,
						RaftDefaultThroughPut:  125,
						RaftMaxThroughPut:      125,
						RaftMinThroughPut:      125,
					},
					&schema.ComponentTierUnit{
						Key:                    "aws:tikv:m8g.2xlarge:gp3:4000:297:Performance",
						Priority:               999,
						ComponentType:          "tikv",
						ProviderId:             uint64(provider.ID),
						ComponentTierId:        uint64(tikvSpu8c32g.ID),
						InstanceTypeId:         uint64(instanceTypeMap["m8g.2xlarge"].ID),
						DefaultNodeNum:         3,
						StorageTemplateId:      lo.ToPtr(uint64(gp3Storage.ID)),
						MinStorageGi:           200,
						MaxStorageGi:           4096,
						DefaultStorageGi:       500,
						MaxIops:                16000,
						MinIops:                3000,
						IopsPerGi:              4,
						MaxThroughPut:          1000,
						MinThroughPut:          125,
						ThroughputMibpsPerGi:   0.5,
						ThroughputMibpsPerIops: 0.046875,
						RaftStorageTemplateId:  lo.ToPtr(uint64(io2Storage.ID)),
						RaftDefaultStorageGi:   40,
						RaftMinStorageGi:       40,
						RaftMaxStorageGi:       40,
						RaftDefaultIops:        4000,
						RaftMaxIops:            4000,
						RaftMinIops:            4000,
					},
					&schema.ComponentTierUnit{
						Key:               "aws:tikv:m8g.2xlarge:io2:4000:0",
						Priority:          999,
						ComponentType:     "tikv",
						ProviderId:        uint64(provider.ID),
						ComponentTierId:   uint64(tikvSpu8c32g.ID),
						InstanceTypeId:    uint64(instanceTypeMap["m8g.2xlarge"].ID),
						DefaultNodeNum:    3,
						StorageTemplateId: lo.ToPtr(uint64(io2Storage.ID)),
						MinStorageGi:      200,
						MaxStorageGi:      4096,
						DefaultStorageGi:  500,
						DefaultIops:       4000,
						MaxIops:           4000,
						MinIops:           4000,
					})

				tikvSpu8c64g := &schema.ComponentTier{
					Key:           "8C64G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIKV",
					ComponentType: "tikv",
					DisplayName:   "8 vCPU, 64 GiB",
					CPUNum:        8,
					MemorySizeGi:  64,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tikvSpu8c64g).Error; err != nil {
					return err
				}
				tikvSkus = append(tikvSkus,
					&schema.ComponentTierUnit{
						Key:                    "aws:tikv:r8g.2xlarge:gp3:4000:297:Standard",
						Priority:               999,
						ComponentType:          "tikv",
						ProviderId:             uint64(provider.ID),
						ComponentTierId:        uint64(tikvSpu8c64g.ID),
						InstanceTypeId:         uint64(instanceTypeMap["r8g.2xlarge"].ID),
						DefaultNodeNum:         3,
						StorageTemplateId:      lo.ToPtr(uint64(gp3Storage.ID)),
						MinStorageGi:           200,
						MaxStorageGi:           4096,
						DefaultStorageGi:       500,
						MaxIops:                16000,
						MinIops:                3000,
						IopsPerGi:              4,
						MaxThroughPut:          1000,
						MinThroughPut:          125,
						ThroughputMibpsPerGi:   0.5,
						ThroughputMibpsPerIops: 0.046875,
						RaftStorageTemplateId:  lo.ToPtr(uint64(gp3Storage.ID)),
						RaftDefaultStorageGi:   40,
						RaftMinStorageGi:       40,
						RaftMaxStorageGi:       40,
						RaftDefaultIops:        3000,
						RaftMaxIops:            3000,
						RaftMinIops:            3000,
						RaftDefaultThroughPut:  125,
						RaftMaxThroughPut:      125,
						RaftMinThroughPut:      125,
					},
					&schema.ComponentTierUnit{
						Key:                    "aws:tikv:r8g.2xlarge:gp3:4000:297:Performance",
						Priority:               999,
						ComponentType:          "tikv",
						ProviderId:             uint64(provider.ID),
						ComponentTierId:        uint64(tikvSpu8c64g.ID),
						InstanceTypeId:         uint64(instanceTypeMap["r8g.2xlarge"].ID),
						DefaultNodeNum:         3,
						StorageTemplateId:      lo.ToPtr(uint64(gp3Storage.ID)),
						MinStorageGi:           200,
						MaxStorageGi:           4096,
						DefaultStorageGi:       500,
						MaxIops:                16000,
						MinIops:                3000,
						IopsPerGi:              4,
						MaxThroughPut:          1000,
						MinThroughPut:          125,
						ThroughputMibpsPerGi:   0.5,
						ThroughputMibpsPerIops: 0.046875,
						RaftStorageTemplateId:  lo.ToPtr(uint64(io2Storage.ID)),
						RaftDefaultStorageGi:   40,
						RaftMinStorageGi:       40,
						RaftMaxStorageGi:       40,
						RaftDefaultIops:        4000,
						RaftMaxIops:            4000,
						RaftMinIops:            4000,
					},
					&schema.ComponentTierUnit{
						Key:               "aws:tikv:r8g.2xlarge:io2:4000:0",
						Priority:          999,
						ComponentType:     "tikv",
						ProviderId:        uint64(provider.ID),
						ComponentTierId:   uint64(tikvSpu8c64g.ID),
						InstanceTypeId:    uint64(instanceTypeMap["r8g.2xlarge"].ID),
						DefaultNodeNum:    3,
						StorageTemplateId: lo.ToPtr(uint64(io2Storage.ID)),
						MinStorageGi:      200,
						MaxStorageGi:      4096,
						DefaultStorageGi:  500,
						DefaultIops:       4000,
						MaxIops:           4000,
						MinIops:           4000,
					})

				for _, tikvSku := range tikvSkus {
					tikvSku.CreatedAt = timestamp
					tikvSku.UpdatedAt = timestamp
					if err := tx.Clauses(clause.OnConflict{
						Columns:   []clause.Column{{Name: "key"}},
						UpdateAll: true,
					}).Create(tikvSku).Error; err != nil {
						return err
					}
				}
			}

			// Add tiflash skus.
			{
				tiflashSkus := make([]*schema.ComponentTierUnit, 0, 8)

				tiflashSpu16c128g := &schema.ComponentTier{
					Key:           "16C128G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIFLASH",
					ComponentType: "tiflash",
					DisplayName:   "16 vCPU, 128 GiB",
					CPUNum:        16,
					MemorySizeGi:  128,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tiflashSpu16c128g).Error; err != nil {
					return err
				}
				tiflashSkus = append(tiflashSkus,
					&schema.ComponentTierUnit{
						Key:               "aws:tiflash:r8g.4xlarge:gp3:16000:594",
						Priority:          999,
						ComponentType:     "tiflash",
						ProviderId:        uint64(provider.ID),
						ComponentTierId:   uint64(tiflashSpu16c128g.ID),
						InstanceTypeId:    uint64(instanceTypeMap["r8g.4xlarge"].ID),
						DefaultNodeNum:    0,
						StorageTemplateId: lo.ToPtr(uint64(gp3Storage.ID)),
						MinStorageGi:      200,
						MaxStorageGi:      6144,
						DefaultStorageGi:  500,
						DefaultIops:       16000,
						MaxIops:           16000,
						MinIops:           16000,
						DefaultThroughPut: lo.ToPtr(uint32(594)),
						MaxThroughPut:     594,
						MinThroughPut:     594,
					},
					&schema.ComponentTierUnit{
						Key:               "aws:tiflash:r8g.4xlarge:io2:8000:0",
						Priority:          999,
						ComponentType:     "tiflash",
						ProviderId:        uint64(provider.ID),
						ComponentTierId:   uint64(tiflashSpu16c128g.ID),
						InstanceTypeId:    uint64(instanceTypeMap["r8g.4xlarge"].ID),
						DefaultNodeNum:    0,
						StorageTemplateId: lo.ToPtr(uint64(io2Storage.ID)),
						MinStorageGi:      200,
						MaxStorageGi:      6144,
						DefaultStorageGi:  500,
						DefaultIops:       8000,
						MaxIops:           12000,
						MinIops:           8000,
					})

				tiflashSpu32c128g := &schema.ComponentTier{
					Key:           "32C128G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIFLASH",
					ComponentType: "tiflash",
					DisplayName:   "32 vCPU, 128 GiB",
					CPUNum:        32,
					MemorySizeGi:  128,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tiflashSpu32c128g).Error; err != nil {
					return err
				}
				tiflashSkus = append(tiflashSkus,
					&schema.ComponentTierUnit{
						Key:               "aws:tiflash:m8g.8xlarge:gp3:16000:1000",
						Priority:          999,
						ComponentType:     "tiflash",
						ProviderId:        uint64(provider.ID),
						ComponentTierId:   uint64(tiflashSpu32c128g.ID),
						InstanceTypeId:    uint64(instanceTypeMap["m8g.8xlarge"].ID),
						DefaultNodeNum:    0,
						StorageTemplateId: lo.ToPtr(uint64(gp3Storage.ID)),
						MinStorageGi:      200,
						MaxStorageGi:      6144,
						DefaultStorageGi:  500,
						DefaultIops:       16000,
						MaxIops:           16000,
						MinIops:           16000,
						DefaultThroughPut: lo.ToPtr(uint32(1000)),
						MaxThroughPut:     1000,
						MinThroughPut:     1000,
					},
					&schema.ComponentTierUnit{
						Key:               "aws:tiflash:m8g.8xlarge:io2:8000:0",
						Priority:          999,
						ComponentType:     "tiflash",
						ProviderId:        uint64(provider.ID),
						ComponentTierId:   uint64(tiflashSpu32c128g.ID),
						InstanceTypeId:    uint64(instanceTypeMap["m8g.8xlarge"].ID),
						DefaultNodeNum:    0,
						StorageTemplateId: lo.ToPtr(uint64(io2Storage.ID)),
						MinStorageGi:      200,
						MaxStorageGi:      6144,
						DefaultStorageGi:  500,
						DefaultIops:       8000,
						MaxIops:           12000,
						MinIops:           8000,
					})

				tiflashSpu32c256g := &schema.ComponentTier{
					Key:           "32C256G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIFLASH",
					ComponentType: "tiflash",
					DisplayName:   "32 vCPU, 256 GiB",
					CPUNum:        32,
					MemorySizeGi:  256,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tiflashSpu32c256g).Error; err != nil {
					return err
				}
				tiflashSkus = append(tiflashSkus,
					&schema.ComponentTierUnit{
						Key:               "aws:tiflash:r8g.8xlarge:gp3:16000:1000",
						Priority:          999,
						ComponentType:     "tiflash",
						ProviderId:        uint64(provider.ID),
						ComponentTierId:   uint64(tiflashSpu32c256g.ID),
						InstanceTypeId:    uint64(instanceTypeMap["r8g.8xlarge"].ID),
						DefaultNodeNum:    0,
						StorageTemplateId: lo.ToPtr(uint64(gp3Storage.ID)),
						MinStorageGi:      200,
						MaxStorageGi:      6144,
						DefaultStorageGi:  500,
						DefaultIops:       16000,
						MaxIops:           16000,
						MinIops:           16000,
						DefaultThroughPut: lo.ToPtr(uint32(1000)),
						MaxThroughPut:     1000,
						MinThroughPut:     1000,
					},
					&schema.ComponentTierUnit{
						Key:               "aws:tiflash:r8g.8xlarge:io2:8000:0",
						Priority:          999,
						ComponentType:     "tiflash",
						ProviderId:        uint64(provider.ID),
						ComponentTierId:   uint64(tiflashSpu32c256g.ID),
						InstanceTypeId:    uint64(instanceTypeMap["r8g.8xlarge"].ID),
						DefaultNodeNum:    0,
						StorageTemplateId: lo.ToPtr(uint64(io2Storage.ID)),
						MinStorageGi:      200,
						MaxStorageGi:      6144,
						DefaultStorageGi:  500,
						DefaultIops:       8000,
						MaxIops:           12000,
						MinIops:           8000,
					})

				tiflashSpu8c64g := &schema.ComponentTier{
					Key:           "8C64G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIFLASH",
					ComponentType: "tiflash",
					DisplayName:   "8 vCPU, 64 GiB",
					CPUNum:        8,
					MemorySizeGi:  64,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(tiflashSpu8c64g).Error; err != nil {
					return err
				}
				tiflashSkus = append(tiflashSkus,
					&schema.ComponentTierUnit{
						Key:               "aws:tiflash:r8g.2xlarge:gp3:12000:297",
						Priority:          999,
						ComponentType:     "tiflash",
						ProviderId:        uint64(provider.ID),
						ComponentTierId:   uint64(tiflashSpu8c64g.ID),
						InstanceTypeId:    uint64(instanceTypeMap["r8g.2xlarge"].ID),
						DefaultNodeNum:    0,
						StorageTemplateId: lo.ToPtr(uint64(gp3Storage.ID)),
						MinStorageGi:      200,
						MaxStorageGi:      6144,
						DefaultStorageGi:  500,
						DefaultIops:       12000,
						MaxIops:           12000,
						MinIops:           12000,
						DefaultThroughPut: lo.ToPtr(uint32(297)),
						MaxThroughPut:     297,
						MinThroughPut:     297,
					},
					&schema.ComponentTierUnit{
						Key:               "aws:tiflash:r8g.2xlarge:io2:8000:0",
						Priority:          999,
						ComponentType:     "tiflash",
						ProviderId:        uint64(provider.ID),
						ComponentTierId:   uint64(tiflashSpu8c64g.ID),
						InstanceTypeId:    uint64(instanceTypeMap["r8g.2xlarge"].ID),
						DefaultNodeNum:    0,
						StorageTemplateId: lo.ToPtr(uint64(io2Storage.ID)),
						MinStorageGi:      200,
						MaxStorageGi:      6144,
						DefaultStorageGi:  500,
						DefaultIops:       8000,
						MaxIops:           12000,
						MinIops:           8000,
					})

				for _, tiflashSku := range tiflashSkus {
					tiflashSku.CreatedAt = timestamp
					tiflashSku.UpdatedAt = timestamp
					if err := tx.Clauses(clause.OnConflict{
						Columns:   []clause.Column{{Name: "key"}},
						UpdateAll: true,
					}).Create(tiflashSku).Error; err != nil {
						return err
					}
				}
			}

			// Add pd skus
			var pdSku4c8g, pdSku16c32g, pdSku2c8g *schema.ComponentTierUnit
			{
				pdSpu4c8g := &schema.ComponentTier{
					Key:           "4C8G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_PD",
					ComponentType: "pd",
					DisplayName:   "4 vCPU, 8 GiB",
					CPUNum:        4,
					MemorySizeGi:  8,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(pdSpu4c8g).Error; err != nil {
					return err
				}
				pdSku4c8g = &schema.ComponentTierUnit{
					Key:               "aws:pd:c8g.xlarge:gp3:3000:125",
					Priority:          999,
					ComponentType:     "pd",
					ProviderId:        uint64(provider.ID),
					ComponentTierId:   uint64(pdSpu4c8g.ID),
					InstanceTypeId:    uint64(instanceTypeMap["c8g.xlarge"].ID),
					DefaultNodeNum:    3,
					StorageTemplateId: lo.ToPtr(uint64(gp3Storage.ID)),
					MinStorageGi:      20,
					MaxStorageGi:      20,
					DefaultStorageGi:  20,
					DefaultIops:       3000,
					MaxIops:           3000,
					MinIops:           3000,
					DefaultThroughPut: lo.ToPtr(uint32(125)),
					MaxThroughPut:     125,
					MinThroughPut:     125,
				}
				pdSku4c8g.CreatedAt = timestamp
				pdSku4c8g.UpdatedAt = timestamp

				pdSpu16c32g := &schema.ComponentTier{
					Key:           "16C32G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_PD",
					ComponentType: "pd",
					DisplayName:   "16 vCPU, 32 GiB",
					CPUNum:        16,
					MemorySizeGi:  32,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(pdSpu16c32g).Error; err != nil {
					return err
				}
				pdSku16c32g = &schema.ComponentTierUnit{
					Key:               "aws:pd:c8g.4xlarge:gp3:3000:125",
					Priority:          999,
					ComponentType:     "pd",
					ProviderId:        uint64(provider.ID),
					ComponentTierId:   uint64(pdSpu16c32g.ID),
					InstanceTypeId:    uint64(instanceTypeMap["c8g.4xlarge"].ID),
					DefaultNodeNum:    3,
					StorageTemplateId: lo.ToPtr(uint64(gp3Storage.ID)),
					MinStorageGi:      20,
					MaxStorageGi:      20,
					DefaultStorageGi:  20,
					DefaultIops:       3000,
					MaxIops:           3000,
					MinIops:           3000,
					DefaultThroughPut: lo.ToPtr(uint32(125)),
					MaxThroughPut:     125,
					MinThroughPut:     125,
				}
				pdSku16c32g.CreatedAt = timestamp
				pdSku16c32g.UpdatedAt = timestamp

				pdSpu2c8g := &schema.ComponentTier{
					Key:           "2C8G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_PD",
					ComponentType: "pd",
					DisplayName:   "2 vCPU, 8 GiB",
					CPUNum:        2,
					MemorySizeGi:  8,
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(pdSpu2c8g).Error; err != nil {
					return err
				}
				pdSku2c8g = &schema.ComponentTierUnit{
					Key:               "aws:pd:m8g.large:gp3:3000:125",
					Priority:          999,
					ComponentType:     "pd",
					ProviderId:        uint64(provider.ID),
					ComponentTierId:   uint64(pdSpu2c8g.ID),
					InstanceTypeId:    uint64(instanceTypeMap["m8g.large"].ID),
					DefaultNodeNum:    3,
					StorageTemplateId: lo.ToPtr(uint64(gp3Storage.ID)),
					MinStorageGi:      20,
					MaxStorageGi:      20,
					DefaultStorageGi:  20,
					DefaultIops:       3000,
					MaxIops:           3000,
					MinIops:           3000,
					DefaultThroughPut: lo.ToPtr(uint32(125)),
					MaxThroughPut:     125,
					MinThroughPut:     125,
				}
				pdSku2c8g.CreatedAt = timestamp
				pdSku2c8g.UpdatedAt = timestamp

				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(pdSku4c8g).Error; err != nil {
					return err
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(pdSku16c32g).Error; err != nil {
					return err
				}
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}},
					UpdateAll: true,
				}).Create(pdSku2c8g).Error; err != nil {
					return err
				}
			}

			// Add pd tikv mappings
			pdTikvMappings := []*schema.TierUnitCondition{
				{
					ComponentTierUnitId: uint64(pdSku4c8g.ID),
					Key:                 globaldedicatedv1.Sku_Condition_ATTACH_TIERUNIT.String(),
					Operator:            globaldedicatedv1.Sku_Condition_IN.String(),
					Values: `[
"aws:tikv:m8g.4xlarge:gp3:16000:1000:Standard",
"aws:tikv:m8g.4xlarge:gp3:16000:1000:Performance",
"aws:tikv:m8g.4xlarge:io2:8000:0",
"aws:tikv:m8g.2xlarge:gp3:4000:297:Standard",
"aws:tikv:m8g.2xlarge:gp3:4000:297:Performance",
"aws:tikv:m8g.2xlarge:io2:4000:0",
"aws:tikv:r8g.2xlarge:gp3:4000:297:Standard",
"aws:tikv:r8g.2xlarge:gp3:4000:297:Performance",
"aws:tikv:r8g.2xlarge:io2:4000:0"
]`,
				},
				{
					ComponentTierUnitId: uint64(pdSku16c32g.ID),
					Key:                 globaldedicatedv1.Sku_Condition_ATTACH_TIERUNIT.String(),
					Operator:            globaldedicatedv1.Sku_Condition_IN.String(),
					Values: `[
"aws:tikv:m8g.8xlarge:gp3:16000:1000:Standard",
"aws:tikv:m8g.8xlarge:gp3:16000:1000:Performance",
"aws:tikv:m8g.8xlarge:io2:8000:0"
]`,
				},
				{
					ComponentTierUnitId: uint64(pdSku2c8g.ID),
					Key:                 globaldedicatedv1.Sku_Condition_ATTACH_TIERUNIT.String(),
					Operator:            globaldedicatedv1.Sku_Condition_IN.String(),
					Values: `[
"aws:tikv:m8g.large:gp3:3000:125:Standard",
"aws:tikv:m8g.xlarge:gp3:3000:149:Standard"
]`,
				},
			}

			for _, pdTikvMapping := range pdTikvMappings {
				pdTikvMapping.CreatedAt = timestamp
				pdTikvMapping.UpdatedAt = timestamp
				if err := tx.Clauses(clause.OnConflict{
					Columns:   []clause.Column{{Name: "key"}, {Name: "component_tier_unit_id"}},
					UpdateAll: true,
				}).Create(pdTikvMapping).Error; err != nil {
					return err
				}
			}

			return nil
		})
	},
)
