Correlations: Add organization id (#72258)
* Add org_id to correlations * Add tests * Allow org_id to be null in case org_id=0 is used * Create organization to ensure stable id is generated * Fix linting * Ensure backwards compatibility * Add deprecation information * Migrate correlations indices * Default org_id when migrating * Remove redundant default * Make PK non-nullable
This commit is contained in:
@@ -29,4 +29,34 @@ func addCorrelationsMigrations(mg *Migrator) {
|
||||
mg.AddMigration("add correlation config column", NewAddColumnMigration(correlationsV1, &Column{
|
||||
Name: "config", Type: DB_Text, Nullable: true,
|
||||
}))
|
||||
|
||||
// v2: adding org_id column and recreating indices
|
||||
correlationsV2 := Table{
|
||||
Name: "correlation",
|
||||
Columns: []*Column{
|
||||
{Name: "uid", Type: DB_NVarchar, Length: 40, Nullable: false, IsPrimaryKey: true},
|
||||
// All existing records will have '0' assigned
|
||||
{Name: "org_id", Type: DB_BigInt, IsPrimaryKey: true, Default: "0"},
|
||||
{Name: "source_uid", Type: DB_NVarchar, Length: 40, Nullable: false, IsPrimaryKey: true},
|
||||
// Nullable because in the future we want to have correlations to external resources
|
||||
{Name: "target_uid", Type: DB_NVarchar, Length: 40, Nullable: true},
|
||||
{Name: "label", Type: DB_Text, Nullable: false},
|
||||
{Name: "description", Type: DB_Text, Nullable: false},
|
||||
{Name: "config", Type: DB_Text, Nullable: true},
|
||||
},
|
||||
Indices: []*Index{
|
||||
{Cols: []string{"uid"}},
|
||||
{Cols: []string{"source_uid"}},
|
||||
{Cols: []string{"org_id"}},
|
||||
},
|
||||
}
|
||||
|
||||
addTableReplaceMigrations(mg, correlationsV1, correlationsV2, 2, map[string]string{
|
||||
"uid": "uid",
|
||||
"source_uid": "source_uid",
|
||||
"target_uid": "target_uid",
|
||||
"label": "label",
|
||||
"description": "description",
|
||||
"config": "config",
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user