Correlations: Add legacy storage (#112038)
This commit is contained in:
@@ -54,7 +54,7 @@ func (s CorrelationsService) createCorrelation(ctx context.Context, cmd CreateCo
|
||||
}
|
||||
}
|
||||
|
||||
_, err = session.Insert(correlation)
|
||||
_, err = session.Omit("source_type", "target_type").Insert(correlation)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -121,13 +121,13 @@ func (s CorrelationsService) updateCorrelation(ctx context.Context, cmd UpdateCo
|
||||
return ErrSourceDataSourceDoesNotExists
|
||||
}
|
||||
|
||||
found, err := session.Get(&correlation)
|
||||
if !found {
|
||||
return ErrCorrelationNotFound
|
||||
}
|
||||
found, err := session.Omit("source_type", "target_type").Get(&correlation)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !found {
|
||||
return ErrCorrelationNotFound
|
||||
}
|
||||
if correlation.Provisioned {
|
||||
return ErrCorrelationReadOnly
|
||||
}
|
||||
@@ -156,7 +156,11 @@ func (s CorrelationsService) updateCorrelation(ctx context.Context, cmd UpdateCo
|
||||
}
|
||||
}
|
||||
|
||||
updateCount, err := session.Where("uid = ? AND source_uid = ?", correlation.UID, correlation.SourceUID).Limit(1).Update(correlation)
|
||||
updateCount, err := session.
|
||||
Where("uid = ? AND source_uid = ?", correlation.UID, correlation.SourceUID).
|
||||
Limit(1).
|
||||
Omit("source_type", "target_type").
|
||||
Update(correlation)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -179,20 +183,31 @@ func (s CorrelationsService) updateCorrelation(ctx context.Context, cmd UpdateCo
|
||||
func (s CorrelationsService) getCorrelation(ctx context.Context, cmd GetCorrelationQuery) (Correlation, error) {
|
||||
correlation := Correlation{
|
||||
UID: cmd.UID,
|
||||
OrgID: cmd.OrgId,
|
||||
SourceUID: cmd.SourceUID,
|
||||
}
|
||||
|
||||
err := s.SQLStore.WithTransactionalDbSession(ctx, func(session *db.Session) error {
|
||||
query := &datasources.GetDataSourceQuery{
|
||||
if cmd.SourceUID != "" {
|
||||
if _, err := s.DataSourceService.GetDataSource(ctx, &datasources.GetDataSourceQuery{
|
||||
UID: correlation.SourceUID,
|
||||
OrgID: cmd.OrgId,
|
||||
UID: cmd.SourceUID,
|
||||
}
|
||||
if _, err := s.DataSourceService.GetDataSource(ctx, query); err != nil {
|
||||
return ErrSourceDataSourceDoesNotExists
|
||||
}); err != nil {
|
||||
return Correlation{}, ErrSourceDataSourceDoesNotExists
|
||||
}
|
||||
}
|
||||
|
||||
err := s.SQLStore.WithTransactionalDbSession(ctx, func(session *db.Session) error {
|
||||
// Correlations created before the fix #72498 may have org_id = 0, but it's deprecated and will be removed in #72325
|
||||
found, err := session.Select("correlation.*").Join("", "data_source AS dss", "correlation.source_uid = dss.uid and (correlation.org_id = 0 or dss.org_id = correlation.org_id) and dss.org_id = ?", cmd.OrgId).Join("LEFT OUTER", "data_source AS dst", "correlation.target_uid = dst.uid and dst.org_id = ?", cmd.OrgId).Where("correlation.uid = ?", correlation.UID).And("correlation.source_uid = ?", correlation.SourceUID).And(VALID_TYPE_FILTER).Get(&correlation)
|
||||
sql := session.Select("correlation.*, dss.type as source_type, dst.type as target_type").
|
||||
Join("", "data_source AS dss", "correlation.source_uid = dss.uid and (correlation.org_id = 0 or dss.org_id = correlation.org_id) and dss.org_id = ?", cmd.OrgId).
|
||||
Join("LEFT OUTER", "data_source AS dst", "correlation.target_uid = dst.uid and dst.org_id = ?", cmd.OrgId).
|
||||
Where("correlation.uid = ?", correlation.UID).
|
||||
And("correlation.org_id = ?", correlation.OrgID).
|
||||
And(VALID_TYPE_FILTER)
|
||||
if correlation.SourceUID != "" {
|
||||
sql = sql.And("correlation.source_uid = ?", correlation.SourceUID)
|
||||
}
|
||||
found, err := sql.Get(&correlation)
|
||||
if !found {
|
||||
return ErrCorrelationNotFound
|
||||
}
|
||||
@@ -264,7 +279,9 @@ func (s CorrelationsService) getCorrelations(ctx context.Context, cmd GetCorrela
|
||||
offset := cmd.Limit * (cmd.Page - 1)
|
||||
|
||||
// Correlations created before the fix #72498 may have org_id = 0, but it's deprecated and will be removed in #72325
|
||||
q := session.Select("correlation.*").Join("", "data_source AS dss", "correlation.source_uid = dss.uid and (correlation.org_id = 0 or dss.org_id = correlation.org_id) and dss.org_id = ? ", cmd.OrgId).Join("LEFT OUTER", "data_source AS dst", "correlation.target_uid = dst.uid and dst.org_id = ?", cmd.OrgId)
|
||||
q := session.Select("correlation.*, dss.type as source_type, dst.type as target_type").
|
||||
Join("", "data_source AS dss", "correlation.source_uid = dss.uid and (correlation.org_id = 0 or dss.org_id = correlation.org_id) and dss.org_id = ? ", cmd.OrgId).
|
||||
Join("LEFT OUTER", "data_source AS dst", "correlation.target_uid = dst.uid and dst.org_id = ?", cmd.OrgId)
|
||||
|
||||
if len(cmd.SourceUIDs) > 0 {
|
||||
q.In("dss.uid", cmd.SourceUIDs)
|
||||
@@ -331,7 +348,7 @@ func (s CorrelationsService) createOrUpdateCorrelation(ctx context.Context, cmd
|
||||
|
||||
found := false
|
||||
err := s.SQLStore.WithDbSession(ctx, func(session *db.Session) error {
|
||||
has, err := session.Get(&correlation)
|
||||
has, err := session.Omit("source_type", "target_type").Get(&correlation)
|
||||
found = has
|
||||
return err
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user