mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
SQL Datasources: Fix annotation migration (#59438)
This commit is contained in:
parent
110fdf4da9
commit
71e4a8261d
28
public/app/features/plugins/sql/utils/migration.test.ts
Normal file
28
public/app/features/plugins/sql/utils/migration.test.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { QueryFormat } from '../types';
|
||||
|
||||
import migrateAnnotation from './migration';
|
||||
|
||||
describe('Annotation migration', () => {
|
||||
const annotation = {
|
||||
datasource: {
|
||||
uid: 'P4FDCC188E688367F',
|
||||
type: 'mysql',
|
||||
},
|
||||
enable: false,
|
||||
hide: false,
|
||||
iconColor: 'rgba(0, 211, 255, 1)',
|
||||
limit: 100,
|
||||
name: 'Single',
|
||||
rawQuery:
|
||||
"SELECT\n createdAt as time,\n 'single' as text,\n hostname as tags\nFROM\n grafana_metric\nWHERE\n $__timeFilter(createdAt)\nORDER BY time\nLIMIT 1\n",
|
||||
showIn: 0,
|
||||
tags: [],
|
||||
type: 'tags',
|
||||
};
|
||||
|
||||
it('should migrate from old format to new', () => {
|
||||
const newAnnotationFormat = migrateAnnotation(annotation);
|
||||
expect(newAnnotationFormat.target?.format).toBe(QueryFormat.Table);
|
||||
expect(newAnnotationFormat.target?.rawSql).toBe(annotation.rawQuery);
|
||||
});
|
||||
});
|
@ -1,6 +1,6 @@
|
||||
import { AnnotationQuery } from '@grafana/data';
|
||||
import { EditorMode } from '@grafana/experimental';
|
||||
|
||||
import { applyQueryDefaults } from '../defaults';
|
||||
import { SQLQuery } from '../types';
|
||||
|
||||
export default function migrateAnnotation(annotation: AnnotationQuery<SQLQuery>) {
|
||||
@ -10,12 +10,7 @@ export default function migrateAnnotation(annotation: AnnotationQuery<SQLQuery>)
|
||||
return annotation;
|
||||
}
|
||||
|
||||
const newQuery: SQLQuery = {
|
||||
...(annotation.target ?? {}),
|
||||
refId: annotation.target?.refId ?? 'Anno',
|
||||
editorMode: EditorMode.Code,
|
||||
rawSql: oldQuery,
|
||||
};
|
||||
const newQuery = applyQueryDefaults({ refId: 'Annotation', ...(annotation.target ?? {}), rawSql: oldQuery });
|
||||
|
||||
return {
|
||||
...annotation,
|
||||
|
Loading…
Reference in New Issue
Block a user