fix: sqlite3 batch create or update (#1463)

Co-authored-by: 曲源成 <quyc@goodrain.com>
This commit is contained in:
Quyc 2022-11-29 14:06:02 +08:00 committed by GitHub
parent 3b0c2a4063
commit 5a80f6fcf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 291 additions and 94 deletions

View File

@ -154,9 +154,16 @@ func (t *ThirdPartySvcDiscoveryCfgDaoImpl) CreateOrUpdate3rdSvcDiscoveryCfgInBat
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, cfg := range cfgs {
if err := t.DB.Create(&cfg).Error; err != nil {
logrus.Error("batch create or update cfgs error:", err)
return err
if ok := t.DB.Where("ID=? ", cfg.ID).Find(&cfg).RecordNotFound(); !ok {
if err := t.DB.Model(&cfg).Where("ID = ?", cfg.ID).Update(cfg).Error; err != nil {
logrus.Error("batch Update or update cfg error:", err)
return err
}
} else {
if err := t.DB.Create(&cfg).Error; err != nil {
logrus.Error("batch create cfg error:", err)
return err
}
}
}
return nil

View File

@ -82,10 +82,17 @@ func (a *AppConfigGroupDaoImpl) DeleteByAppID(appID string) error {
func (a *AppConfigGroupDaoImpl) CreateOrUpdateConfigGroupsInBatch(cgroups []*model.ApplicationConfigGroup) error {
dbType := a.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, cg := range cgroups {
if err := a.DB.Create(&cg).Error; err != nil {
logrus.Error("batch create or update cgroups error:", err)
return err
for _, cgroup := range cgroups {
if ok := a.DB.Where("ID=? ", cgroup.ID).Find(&cgroup).RecordNotFound(); !ok {
if err := a.DB.Model(&cgroup).Where("ID = ?", cgroup.ID).Update(cgroup).Error; err != nil {
logrus.Error("batch Update or update cgroup error:", err)
return err
}
} else {
if err := a.DB.Create(&cgroup).Error; err != nil {
logrus.Error("batch create cgroup error:", err)
return err
}
}
}
return nil
@ -156,10 +163,17 @@ func (a *AppConfigGroupServiceDaoImpl) DeleteByAppID(appID string) error {
func (a *AppConfigGroupServiceDaoImpl) CreateOrUpdateConfigGroupServicesInBatch(cgservices []*model.ConfigGroupService) error {
dbType := a.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, cgs := range cgservices {
if err := a.DB.Create(&cgs).Error; err != nil {
logrus.Error("batch create or update cgservices error:", err)
return err
for _, cgservice := range cgservices {
if ok := a.DB.Where("ID=? ", cgservice.ID).Find(&cgservice).RecordNotFound(); !ok {
if err := a.DB.Model(&cgservice).Where("ID = ?", cgservice.ID).Update(cgservice).Error; err != nil {
logrus.Error("batch Update or update cgservice error:", err)
return err
}
} else {
if err := a.DB.Create(&cgservice).Error; err != nil {
logrus.Error("batch create cgservice error:", err)
return err
}
}
}
return nil
@ -233,10 +247,17 @@ func (a *AppConfigGroupItemDaoImpl) DeleteByAppID(appID string) error {
func (a *AppConfigGroupItemDaoImpl) CreateOrUpdateConfigGroupItemsInBatch(cgitems []*model.ConfigGroupItem) error {
dbType := a.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, cgi := range cgitems {
if err := a.DB.Create(&cgi).Error; err != nil {
logrus.Error("batch create or update cgservices error:", err)
return err
for _, cgitem := range cgitems {
if ok := a.DB.Where("ID=? ", cgitem.ID).Find(&cgitem).RecordNotFound(); !ok {
if err := a.DB.Model(&cgitem).Where("ID = ?", cgitem.ID).Update(cgitem).Error; err != nil {
logrus.Error("batch Update or update cgitem error:", err)
return err
}
} else {
if err := a.DB.Create(&cgitem).Error; err != nil {
logrus.Error("batch create cgitem error:", err)
return err
}
}
}
return nil

View File

@ -68,6 +68,7 @@ func (c *EventDaoImpl) CreateEventsInBatch(events []*model.ServiceEvent) error {
dbType := c.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, event := range events {
event := event
if err := c.DB.Create(&event).Error; err != nil {
logrus.Error("batch create or update events error:", err)
return err
@ -117,7 +118,7 @@ func (c *EventDaoImpl) UpdateInBatch(events []*model.ServiceEvent) error {
dbType := c.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, event := range events {
if err := c.DB.Update(&event).Error; err != nil {
if err := c.DB.Model(&event).Where("ID = ?", event.ID).Update(event).Error; err != nil {
logrus.Error("batch Update or update events error:", err)
return err
}

View File

@ -154,9 +154,16 @@ func (c *RuleExtensionDaoImpl) CreateOrUpdateRuleExtensionsInBatch(exts []*model
dbType := c.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, ext := range exts {
if err := c.DB.Create(&ext).Error; err != nil {
logrus.Error("batch Update or update exts error:", err)
return err
if ok := c.DB.Where("ID=? ", ext.ID).Find(&ext).RecordNotFound(); !ok {
if err := c.DB.Model(&ext).Where("ID = ?", ext.ID).Update(ext).Error; err != nil {
logrus.Error("batch Update or update ext error:", err)
return err
}
} else {
if err := c.DB.Create(&ext).Error; err != nil {
logrus.Error("batch create ext error:", err)
return err
}
}
}
return nil
@ -306,10 +313,17 @@ func (h *HTTPRuleDaoImpl) DeleteByComponentIDs(componentIDs []string) error {
func (h *HTTPRuleDaoImpl) CreateOrUpdateHTTPRuleInBatch(httpRules []*model.HTTPRule) error {
dbType := h.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, ext := range httpRules {
if err := h.DB.Create(&ext).Error; err != nil {
logrus.Error("batch Update or update httpRules error:", err)
return err
for _, httpRule := range httpRules {
if ok := h.DB.Where("ID=? ", httpRule.ID).Find(&httpRule).RecordNotFound(); !ok {
if err := h.DB.Model(&httpRule).Where("ID = ?", httpRule.ID).Update(httpRule).Error; err != nil {
logrus.Error("batch Update or update httpRule error:", err)
return err
}
} else {
if err := h.DB.Create(&httpRule).Error; err != nil {
logrus.Error("batch create httpRule error:", err)
return err
}
}
}
return nil
@ -364,10 +378,17 @@ func (h *HTTPRuleRewriteDaoTmpl) UpdateModel(mo model.Interface) error {
func (h *HTTPRuleRewriteDaoTmpl) CreateOrUpdateHTTPRuleRewriteInBatch(httpRuleRewrites []*model.HTTPRuleRewrite) error {
dbType := h.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, httpRuleRewrites := range httpRuleRewrites {
if err := h.DB.Create(&httpRuleRewrites).Error; err != nil {
logrus.Error("batch Update or update httpRules error:", err)
return err
for _, httpRuleRewrite := range httpRuleRewrites {
if ok := h.DB.Where("ID=? ", httpRuleRewrite.ID).Find(&httpRuleRewrite).RecordNotFound(); !ok {
if err := h.DB.Model(&httpRuleRewrite).Where("ID = ?", httpRuleRewrite.ID).Update(httpRuleRewrite).Error; err != nil {
logrus.Error("batch Update or update httpRuleRewrite error:", err)
return err
}
} else {
if err := h.DB.Create(&httpRuleRewrite).Error; err != nil {
logrus.Error("batch create httpRuleRewrite error:", err)
return err
}
}
}
return nil
@ -531,9 +552,16 @@ func (t *TCPRuleDaoTmpl) CreateOrUpdateTCPRuleInBatch(tcpRules []*model.TCPRule)
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, tcpRule := range tcpRules {
if err := t.DB.Create(&tcpRule).Error; err != nil {
logrus.Error("batch Update or update tcpRules error:", err)
return err
if ok := t.DB.Where("ID=? ", tcpRule.ID).Find(&tcpRule).RecordNotFound(); !ok {
if err := t.DB.Model(&tcpRule).Where("ID = ?", tcpRule.ID).Update(tcpRule).Error; err != nil {
logrus.Error("batch Update or update tcpRule error:", err)
return err
}
} else {
if err := t.DB.Create(&tcpRule).Error; err != nil {
logrus.Error("batch create tcpRule error:", err)
return err
}
}
}
return nil
@ -601,9 +629,16 @@ func (t *GwRuleConfigDaoImpl) CreateOrUpdateGwRuleConfigsInBatch(ruleConfigs []*
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, ruleConfig := range ruleConfigs {
if err := t.DB.Create(&ruleConfig).Error; err != nil {
logrus.Error("batch Update or update ruleConfigs error:", err)
return err
if ok := t.DB.Where("ID=? ", ruleConfig.ID).Find(&ruleConfig).RecordNotFound(); !ok {
if err := t.DB.Model(&ruleConfig).Where("ID = ?", ruleConfig.ID).Update(ruleConfig).Error; err != nil {
logrus.Error("batch Update or update ruleConfig error:", err)
return err
}
} else {
if err := t.DB.Create(&ruleConfig).Error; err != nil {
logrus.Error("batch create ruleConfig error:", err)
return err
}
}
}
return nil

View File

@ -126,9 +126,16 @@ func (t *ServiceProbeDaoImpl) CreateOrUpdateProbesInBatch(probes []*model.Tenant
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, probe := range probes {
if err := t.DB.Create(&probe).Error; err != nil {
logrus.Error("batch Update or update probes error:", err)
return err
if ok := t.DB.Where("ID=? ", probe.ID).Find(&probe).RecordNotFound(); !ok {
if err := t.DB.Model(&probe).Where("ID = ?", probe.ID).Update(probe).Error; err != nil {
logrus.Error("batch Update or update probe error:", err)
return err
}
} else {
if err := t.DB.Create(&probe).Error; err != nil {
logrus.Error("batch create probe error:", err)
return err
}
}
}
return nil

View File

@ -63,9 +63,16 @@ func (t *TenantServiceMonitorDaoImpl) CreateOrUpdateMonitorInBatch(monitors []*m
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, monitor := range monitors {
if err := t.DB.Create(&monitor).Error; err != nil {
logrus.Error("batch Update or update monitors error:", err)
return err
if ok := t.DB.Where("ID=?", monitor.ID).Find(&monitor).RecordNotFound(); !ok {
if err := t.DB.Model(&monitor).Where("ID = ?", monitor.ID).Update(monitor).Error; err != nil {
logrus.Error("batch Update or update monitor error:", err)
return err
}
} else {
if err := t.DB.Create(&monitor).Error; err != nil {
logrus.Error("batch create monitor error:", err)
return err
}
}
}
return nil

View File

@ -111,9 +111,16 @@ func (t *PluginDaoImpl) CreateOrUpdatePluginsInBatch(plugins []*model.TenantPlug
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, plugin := range plugins {
if err := t.DB.Create(&plugin).Error; err != nil {
logrus.Error("batch create or update plugin error:", err)
return err
if ok := t.DB.Where("ID=? ", plugin.ID).Find(&plugin).RecordNotFound(); !ok {
if err := t.DB.Model(&plugin).Where("ID = ?", plugin.ID).Update(plugin).Error; err != nil {
logrus.Error("batch Update or update plugin error:", err)
return err
}
} else {
if err := t.DB.Create(&plugin).Error; err != nil {
logrus.Error("batch create plugin error:", err)
return err
}
}
}
return nil
@ -336,10 +343,17 @@ func (t *PluginBuildVersionDaoImpl) GetLastBuildVersionByVersionID(pluginID, ver
func (t *PluginBuildVersionDaoImpl) CreateOrUpdatePluginBuildVersionsInBatch(buildVersions []*model.TenantPluginBuildVersion) error {
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, version := range buildVersions {
if err := t.DB.Create(&version).Error; err != nil {
logrus.Error("batch create or update buildVersions error:", err)
return err
for _, buildVersion := range buildVersions {
if ok := t.DB.Where("ID=? ", buildVersion.ID).Find(&buildVersion).RecordNotFound(); !ok {
if err := t.DB.Model(&buildVersion).Where("ID = ?", buildVersion.ID).Update(buildVersion).Error; err != nil {
logrus.Error("batch Update or update buildVersion error:", err)
return err
}
} else {
if err := t.DB.Create(&buildVersion).Error; err != nil {
logrus.Error("batch create buildVersion error:", err)
return err
}
}
}
return nil
@ -451,10 +465,17 @@ func (t *PluginVersionEnvDaoImpl) DeleteByComponentIDs(componentIDs []string) er
func (t *PluginVersionEnvDaoImpl) CreateOrUpdatePluginVersionEnvsInBatch(versionEnvs []*model.TenantPluginVersionEnv) error {
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, env := range versionEnvs {
if err := t.DB.Create(&env).Error; err != nil {
logrus.Error("batch create or update versionEnvs error:", err)
return err
for _, versionEnv := range versionEnvs {
if ok := t.DB.Where("ID=? ", versionEnv.ID).Find(&versionEnv).RecordNotFound(); !ok {
if err := t.DB.Model(&versionEnv).Where("ID = ?", versionEnv.ID).Update(versionEnv).Error; err != nil {
logrus.Error("batch Update or update versionEnv error:", err)
return err
}
} else {
if err := t.DB.Create(&versionEnv).Error; err != nil {
logrus.Error("batch create versionEnv error:", err)
return err
}
}
}
return nil
@ -547,10 +568,17 @@ func (t *PluginVersionConfigDaoImpl) DeleteByComponentIDs(componentIDs []string)
func (t *PluginVersionConfigDaoImpl) CreateOrUpdatePluginVersionConfigsInBatch(versionConfigs []*model.TenantPluginVersionDiscoverConfig) error {
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, config := range versionConfigs {
if err := t.DB.Create(&config).Error; err != nil {
logrus.Error("batch create or update versionConfigs error:", err)
return err
for _, versionConfig := range versionConfigs {
if ok := t.DB.Where("ID=? ", versionConfig.ID).Find(&versionConfig).RecordNotFound(); !ok {
if err := t.DB.Model(&versionConfig).Where("ID = ?", versionConfig.ID).Update(versionConfig).Error; err != nil {
logrus.Error("batch Update or update versionConfig error:", err)
return err
}
} else {
if err := t.DB.Create(&versionConfig).Error; err != nil {
logrus.Error("batch create versionConfig error:", err)
return err
}
}
}
return nil
@ -679,9 +707,16 @@ func (t *TenantServicePluginRelationDaoImpl) CreateOrUpdatePluginRelsInBatch(rel
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, relation := range relations {
if err := t.DB.Create(&relation).Error; err != nil {
logrus.Error("batch create or update relations error:", err)
return err
if ok := t.DB.Where("ID=? ", relation.ID).Find(&relation).RecordNotFound(); !ok {
if err := t.DB.Model(&relation).Where("ID = ?", relation.ID).Update(relation).Error; err != nil {
logrus.Error("batch Update or update relation error:", err)
return err
}
} else {
if err := t.DB.Create(&relation).Error; err != nil {
logrus.Error("batch create relation error:", err)
return err
}
}
}
return nil
@ -866,10 +901,17 @@ func (t *TenantServicesStreamPluginPortDaoImpl) DeleteByComponentIDs(componentID
func (t *TenantServicesStreamPluginPortDaoImpl) CreateOrUpdateStreamPluginPortsInBatch(spPorts []*model.TenantServicesStreamPluginPort) error {
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, volRel := range spPorts {
if err := t.DB.Create(&volRel).Error; err != nil {
logrus.Error("batch create or update spPorts error:", err)
return err
for _, spPort := range spPorts {
if ok := t.DB.Where("ID=? ", spPort.ID).Find(&spPort).RecordNotFound(); !ok {
if err := t.DB.Model(&spPort).Where("ID = ?", spPort.ID).Update(spPort).Error; err != nil {
logrus.Error("batch Update or update spPort error:", err)
return err
}
} else {
if err := t.DB.Create(&spPort).Error; err != nil {
logrus.Error("batch create spPort error:", err)
return err
}
}
}
return nil

View File

@ -571,9 +571,16 @@ func (t *TenantServicesDaoImpl) CreateOrUpdateComponentsInBatch(components []*mo
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, component := range components {
if err := t.DB.Create(&component).Error; err != nil {
logrus.Error("batch Update or update components error:", err)
return err
if ok := t.DB.Where("ID=? ", component.ID).Find(&component).RecordNotFound(); !ok {
if err := t.DB.Model(&component).Where("ID = ?", component.ID).Update(component).Error; err != nil {
logrus.Error("batch Update or update spPort error:", err)
return err
}
} else {
if err := t.DB.Create(&component).Error; err != nil {
logrus.Error("batch create spPort error:", err)
return err
}
}
}
return nil
@ -697,9 +704,16 @@ func (t *TenantServicesPortDaoImpl) CreateOrUpdatePortsInBatch(ports []*model.Te
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, port := range ports {
if err := t.DB.Create(&port).Error; err != nil {
logrus.Error("batch Update or update ports error:", err)
return err
if ok := t.DB.Where("ID=? ", port.ID).Find(&port).RecordNotFound(); !ok {
if err := t.DB.Model(&port).Where("ID = ?", port.ID).Update(port).Error; err != nil {
logrus.Error("batch Update or update port error:", err)
return err
}
} else {
if err := t.DB.Create(&port).Error; err != nil {
logrus.Error("batch create port error:", err)
return err
}
}
}
return nil
@ -934,9 +948,16 @@ func (t *TenantServiceRelationDaoImpl) CreateOrUpdateRelationsInBatch(relations
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, relation := range relations {
if err := t.DB.Create(&relation).Error; err != nil {
logrus.Error("batch Update or update relations error:", err)
return err
if ok := t.DB.Where("ID=? ", relation.ID).Find(&relation).RecordNotFound(); !ok {
if err := t.DB.Model(&relation).Where("ID = ?", relation.ID).Update(relation).Error; err != nil {
logrus.Error("batch Update or update relation error:", err)
return err
}
} else {
if err := t.DB.Create(&relation).Error; err != nil {
logrus.Error("batch create relation error:", err)
return err
}
}
}
return nil
@ -1048,9 +1069,16 @@ func (t *TenantServiceEnvVarDaoImpl) CreateOrUpdateEnvsInBatch(envs []*model.Ten
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, env := range envs {
if err := t.DB.Create(&env).Error; err != nil {
logrus.Error("batch Update or update envs error:", err)
return err
if ok := t.DB.Where("ID=? ", env.ID).Find(&env).RecordNotFound(); !ok {
if err := t.DB.Model(&env).Where("ID = ?", env.ID).Update(env).Error; err != nil {
logrus.Error("batch Update or update env error:", err)
return err
}
} else {
if err := t.DB.Create(&env).Error; err != nil {
logrus.Error("batch create env error:", err)
return err
}
}
}
return nil
@ -1234,9 +1262,16 @@ func (t *TenantServiceMountRelationDaoImpl) CreateOrUpdateVolumeRelsInBatch(volR
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, volRel := range volRels {
if err := t.DB.Create(&volRel).Error; err != nil {
logrus.Error("batch Update or update volRels error:", err)
return err
if ok := t.DB.Where("ID=? ", volRel.ID).Find(&volRel).RecordNotFound(); !ok {
if err := t.DB.Model(&volRel).Where("ID = ?", volRel.ID).Update(volRel).Error; err != nil {
logrus.Error("batch Update or update env error:", err)
return err
}
} else {
if err := t.DB.Create(&volRel).Error; err != nil {
logrus.Error("batch create env error:", err)
return err
}
}
}
return nil
@ -1330,9 +1365,16 @@ func (t *TenantServiceVolumeDaoImpl) CreateOrUpdateVolumesInBatch(volumes []*mod
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, volume := range volumes {
if err := t.DB.Create(&volume).Error; err != nil {
logrus.Error("batch Update or update volRels error:", err)
return err
if ok := t.DB.Where("ID=? ", volume.ID).Find(&volume).RecordNotFound(); !ok {
if err := t.DB.Model(&volume).Where("ID = ?", volume.ID).Update(volume).Error; err != nil {
logrus.Error("batch Update or update volume error:", err)
return err
}
} else {
if err := t.DB.Create(&volume).Error; err != nil {
logrus.Error("batch create volume error:", err)
return err
}
}
}
return nil
@ -1485,9 +1527,16 @@ func (t *TenantServiceConfigFileDaoImpl) CreateOrUpdateConfigFilesInBatch(config
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, configFile := range configFiles {
if err := t.DB.Create(&configFile).Error; err != nil {
logrus.Error("batch Update or update configFiles error:", err)
return err
if ok := t.DB.Where("ID=? ", configFile.ID).Find(&configFile).RecordNotFound(); !ok {
if err := t.DB.Model(&configFile).Where("ID = ?", configFile.ID).Update(configFile).Error; err != nil {
logrus.Error("batch Update or update configFile error:", err)
return err
}
} else {
if err := t.DB.Create(&configFile).Error; err != nil {
logrus.Error("batch create configFile error:", err)
return err
}
}
}
return nil
@ -1860,9 +1909,16 @@ func (t *ServiceLabelDaoImpl) CreateOrUpdateLabelsInBatch(labels []*model.Tenant
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, label := range labels {
if err := t.DB.Create(&label).Error; err != nil {
logrus.Error("batch Update or update labels error:", err)
return err
if ok := t.DB.Where("ID=? ", label.ID).Find(&label).RecordNotFound(); !ok {
if err := t.DB.Model(&label).Where("ID = ?", label.ID).Update(label).Error; err != nil {
logrus.Error("batch Update or update label error:", err)
return err
}
} else {
if err := t.DB.Create(&label).Error; err != nil {
logrus.Error("batch create label error:", err)
return err
}
}
}
return nil
@ -1951,9 +2007,16 @@ func (t *TenantServceAutoscalerRulesDaoImpl) CreateOrUpdateScaleRulesInBatch(rul
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, rule := range rules {
if err := t.DB.Create(&rule).Error; err != nil {
logrus.Error("batch Update or update rules error:", err)
return err
if ok := t.DB.Where("ID=? ", rule.ID).Find(&rule).RecordNotFound(); !ok {
if err := t.DB.Model(&rule).Where("ID = ?", rule.ID).Update(rule).Error; err != nil {
logrus.Error("batch Update or update rule error:", err)
return err
}
} else {
if err := t.DB.Create(&rule).Error; err != nil {
logrus.Error("batch create rule error:", err)
return err
}
}
}
return nil
@ -2041,9 +2104,16 @@ func (t *TenantServceAutoscalerRuleMetricsDaoImpl) CreateOrUpdateScaleRuleMetric
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, metric := range metrics {
if err := t.DB.Create(&metric).Error; err != nil {
logrus.Error("batch Update or update metrics error:", err)
return err
if ok := t.DB.Where("ID=? ", metric.ID).Find(&metric).RecordNotFound(); !ok {
if err := t.DB.Model(&metric).Where("ID = ?", metric.ID).Update(metric).Error; err != nil {
logrus.Error("batch Update or update metric error:", err)
return err
}
} else {
if err := t.DB.Create(&metric).Error; err != nil {
logrus.Error("batch create metric error:", err)
return err
}
}
}
return nil
@ -2155,9 +2225,16 @@ func (t *ComponentK8sAttributeDaoImpl) CreateOrUpdateAttributesInBatch(attribute
dbType := t.DB.Dialect().GetName()
if dbType == "sqlite3" {
for _, attribute := range attributes {
if err := t.DB.Create(&attribute).Error; err != nil {
logrus.Error("batch Update or update attributes error:", err)
return err
if ok := t.DB.Where("ID=? ", attribute.ID).Find(&attribute).RecordNotFound(); !ok {
if err := t.DB.Model(&attribute).Where("ID = ?", attribute.ID).Update(attribute).Error; err != nil {
logrus.Error("batch Update or update attribute error:", err)
return err
}
} else {
if err := t.DB.Create(&attribute).Error; err != nil {
logrus.Error("batch create attribute error:", err)
return err
}
}
}
return nil