mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
SQL: Define primary key for tables without it (#22255)
The annotation_tag and alert_rule_tag tables did not have PRIMARY KEY defined what cause problems with migration to MariaDB with Galera setup with innodb_force_primary_key=1 Or MySQL > 8.0.13 with sql_require_primary_key=ON Which can manifest as follows: MariaDB Error 1173: This table type requires a primary key MySQL ERROR 3750 (HY000): Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Extra reading for curious: https://jfg-mysql.blogspot.com/2017/08/danger-no-pk-with-RBR-and-mariadb-protection.html Fixes #12971 Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
This commit is contained in:
@@ -82,6 +82,36 @@ func addAnnotationMig(mg *Migrator) {
|
||||
mg.AddMigration("Create annotation_tag table v2", NewAddTableMigration(annotationTagTable))
|
||||
mg.AddMigration("Add unique index annotation_tag.annotation_id_tag_id", NewAddIndexMigration(annotationTagTable, annotationTagTable.Indices[0]))
|
||||
|
||||
// drop dashboard indexes
|
||||
addDropAllIndicesMigrations(mg, "v2", annotationTagTable)
|
||||
// rename table
|
||||
addTableRenameMigration(mg, "annotation_tag", "annotation_tag_v2", "v2")
|
||||
|
||||
// annotation_tag v3
|
||||
annotationTagTableV3 := Table{
|
||||
Name: "annotation_tag",
|
||||
Columns: []*Column{
|
||||
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
||||
{Name: "annotation_id", Type: DB_BigInt, Nullable: false},
|
||||
{Name: "tag_id", Type: DB_BigInt, Nullable: false},
|
||||
},
|
||||
Indices: []*Index{
|
||||
{Cols: []string{"annotation_id", "tag_id"}, Type: UniqueIndex},
|
||||
},
|
||||
}
|
||||
|
||||
// recreate table
|
||||
mg.AddMigration("Create annotation_tag table v3", NewAddTableMigration(annotationTagTableV3))
|
||||
// recreate indices
|
||||
addTableIndicesMigrations(mg, "Add unique index annotation_tag.annotation_id_tag_id V3", annotationTagTableV3)
|
||||
// copy data
|
||||
mg.AddMigration("copy annotation_tag v2 to v3", NewCopyTableDataMigration("annotation_tag", "annotation_tag_v2", map[string]string{
|
||||
"annotation_id": "annotation_id",
|
||||
"tag_id": "tag_id",
|
||||
}))
|
||||
|
||||
mg.AddMigration("drop table annotation_tag_v2", NewDropTableMigration("annotation_tag_v2"))
|
||||
|
||||
//
|
||||
// clear alert text
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user