Provisioning: Allows specifying uid for datasource and use that in derived fields (#23585)

* Add uid to datasource

* Fix uid passing when provisioning

* Better error handling and Uid column type change

* Fix test and strict null error counts

* Add backend tests

* Add tests

* Fix strict null checks

* Update test

* Improve tests

* Update pkg/services/sqlstore/datasource.go

Co-Authored-By: Arve Knudsen <arve.knudsen@gmail.com>

* Variable rename

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Andrej Ocenas
2020-04-20 15:48:38 +02:00
committed by GitHub
co-authored by Arve Knudsen
parent d5f8d976f0
commit e5dd7efdee
34 changed files with 446 additions and 204 deletions
@@ -133,4 +133,22 @@ func addDataSourceMigration(mg *Migrator) {
const setEmptyJSONWhereNullJSON = `UPDATE data_source SET json_data = '{}' WHERE json_data is null`
mg.AddMigration("Update json_data with nulls", NewRawSqlMigration(setEmptyJSONWhereNullJSON))
// add column uid for linking
mg.AddMigration("Add uid column", NewAddColumnMigration(tableV2, &Column{
Name: "uid", Type: DB_NVarchar, Length: 40, Nullable: false, Default: "0",
}))
// Initialize as id as that is unique already
mg.AddMigration(
"Update uid value",
NewRawSqlMigration("").
Sqlite("UPDATE data_source SET uid=printf('%09d',id);").
Postgres("UPDATE data_source SET uid=lpad('' || id::text,9,'0');").
Mysql("UPDATE data_source SET uid=lpad(id,9,'0');"),
)
mg.AddMigration("Add unique index datasource_org_id_uid", NewAddIndexMigration(tableV2, &Index{
Cols: []string{"org_id", "uid"}, Type: UniqueIndex,
}))
}