Skip to content

Commit

Permalink
chore:support upload sql sync
Browse files Browse the repository at this point in the history
  • Loading branch information
taolx0 committed Sep 21, 2023
1 parent 89f55a7 commit 40d8133
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
29 changes: 29 additions & 0 deletions sqle/model/sql_manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,35 @@ func (s *Storage) GetAllSqlManageList() ([]*SqlManage, error) {
return sqlManageList, nil
}

// todo 临时方案,后续移除
func (s *Storage) InsertOrUpdateSqlManageWithNotUpdateFpCount(sqlManageList []*SqlManage) error {
args := make([]interface{}, 0, len(sqlManageList))
pattern := make([]string, 0, len(sqlManageList))
for _, sqlManage := range sqlManageList {
pattern = append(pattern, "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
args = append(args, sqlManage.SqlFingerprint, sqlManage.ProjFpSourceInstSchemaMd5, sqlManage.SqlText,
sqlManage.Source, sqlManage.AuditLevel, sqlManage.AuditResults, sqlManage.FpCount, sqlManage.FirstAppearTimestamp,
sqlManage.LastReceiveTimestamp, sqlManage.InstanceName, sqlManage.SchemaName, sqlManage.Status, sqlManage.Remark,
sqlManage.AuditPlanId, sqlManage.ProjectId, sqlManage.SqlAuditRecordId)
}

raw := fmt.Sprintf(`
INSERT INTO sql_manages (sql_fingerprint, proj_fp_source_inst_schema_md5, sql_text, source, audit_level, audit_results,
fp_count, first_appear_timestamp, last_receive_timestamp, instance_name, schema_name, status,
remark, audit_plan_id, project_id, sql_audit_record_id)
VALUES %s
ON DUPLICATE KEY UPDATE sql_text = VALUES(sql_text),
audit_plan_id = VALUES(audit_plan_id),
sql_audit_record_id = VALUES(sql_audit_record_id),
audit_level = VALUES(audit_level),
audit_results = VALUES(audit_results),
first_appear_timestamp = VALUES(first_appear_timestamp),
last_receive_timestamp = VALUES(last_receive_timestamp);`,
strings.Join(pattern, ", "))

return errors.New(errors.ConnectStorageError, s.db.Exec(raw, args...).Error)
}

func (s *Storage) InsertOrUpdateSqlManage(sqlManageList []*SqlManage) error {
args := make([]interface{}, 0, len(sqlManageList))
pattern := make([]string, 0, len(sqlManageList))
Expand Down
8 changes: 7 additions & 1 deletion sqle/server/auditplan/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ func Audit(entry *logrus.Entry, ap *model.AuditPlan) (*model.AuditPlanReportV2,
}

func UploadSQLs(entry *logrus.Entry, ap *model.AuditPlan, sqls []*SQL, isPartialSync bool) error {
// todo sync to sql manage
go func() {
err := SyncToSqlManage(sqls, ap)
if err != nil {
log.NewEntry().WithField("name", ap.Name).Errorf("schedule to save sql manage failed, error: %v", err)
}
}()

task := NewTask(entry, ap)
if isPartialSync {
return task.PartialSyncSQLs(sqls)
Expand Down
6 changes: 6 additions & 0 deletions sqle/server/auditplan/manager_ce.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package auditplan

import (
e "errors"

"github.com/actiontech/sqle/sqle/model"
)

func (sap *SyncFromAuditPlan) SyncSqlManager() error {
Expand All @@ -14,3 +16,7 @@ func (sap *SyncFromAuditPlan) SyncSqlManager() error {
func (sa *SyncFromSqlAuditRecord) SyncSqlManager() error {
return e.New("sql manage is enterprise version feature")
}

func SyncToSqlManage(sqls []*SQL, ap *model.AuditPlan) error {
return e.New("sql manage is enterprise version feature")
}

0 comments on commit 40d8133

Please sign in to comment.