mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Bug Fix: Respect data source version when provisioning (#77428)
This commit is contained in:
parent
b13395afbc
commit
82a7e1229a
@ -157,6 +157,8 @@ datasources:
|
||||
password:
|
||||
# <string> Sets the basic authorization password.
|
||||
basicAuthPassword:
|
||||
# <int> Sets the version. Used to compare versions when
|
||||
# updating. Ignored when creating a new data source.
|
||||
version: 1
|
||||
# <bool> Allows users to edit data sources from the
|
||||
# Grafana UI.
|
||||
|
@ -80,7 +80,11 @@ func (dc *DatasourceProvisioner) provisionDataSources(ctx context.Context, cfg *
|
||||
updateCmd := createUpdateCommand(ds, dataSource.ID)
|
||||
dc.log.Debug("updating datasource from configuration", "name", updateCmd.Name, "uid", updateCmd.UID)
|
||||
if _, err := dc.store.UpdateDataSource(ctx, updateCmd); err != nil {
|
||||
return err
|
||||
if errors.Is(err, datasources.ErrDataSourceUpdatingOldVersion) {
|
||||
dc.log.Debug("ignoring old version of datasource", "name", updateCmd.Name, "uid", updateCmd.UID)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -243,6 +243,7 @@ func createUpdateCommand(ds *upsertDataSourceFromConfig, id int64) *datasources.
|
||||
|
||||
return &datasources.UpdateDataSourceCommand{
|
||||
ID: id,
|
||||
Version: ds.Version,
|
||||
UID: ds.UID,
|
||||
OrgID: ds.OrgID,
|
||||
Name: ds.Name,
|
||||
|
@ -13,3 +13,11 @@ func TestUIDFromNames(t *testing.T) {
|
||||
require.Equal(t, safeUIDFromName("AAA"), "PCB1AD2119D8FAFB6")
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateUpdateCommand(t *testing.T) {
|
||||
t.Run("includes the version in the command", func(t *testing.T) {
|
||||
ds := &upsertDataSourceFromConfig{OrgID: 1, Version: 1, Name: "test"}
|
||||
cmd := createUpdateCommand(ds, 1)
|
||||
require.Equal(t, 1, cmd.Version)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user