Comments: support live comments in dashboards and annotations (#44980)

This commit is contained in:
Alexander Emelin
2022-02-22 10:47:42 +03:00
committed by GitHub
parent 67c1a359d1
commit 28c30a34ad
32 changed files with 1254 additions and 18 deletions

View File

@ -0,0 +1,46 @@
package migrations
import (
. "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
)
func addCommentGroupMigrations(mg *Migrator) {
commentGroupTable := Table{
Name: "comment_group",
Columns: []*Column{
{Name: "id", Type: DB_BigInt, Nullable: false, IsPrimaryKey: true, IsAutoIncrement: true},
{Name: "org_id", Type: DB_BigInt, Nullable: false},
{Name: "object_type", Type: DB_NVarchar, Length: 10, Nullable: false},
{Name: "object_id", Type: DB_NVarchar, Length: 128, Nullable: false},
{Name: "settings", Type: DB_MediumText, Nullable: false},
{Name: "created", Type: DB_Int, Nullable: false},
{Name: "updated", Type: DB_Int, Nullable: false},
},
Indices: []*Index{
{Cols: []string{"org_id", "object_type", "object_id"}, Type: UniqueIndex},
},
}
mg.AddMigration("create comment group table", NewAddTableMigration(commentGroupTable))
mg.AddMigration("add index comment_group.org_id_object_type_object_id", NewAddIndexMigration(commentGroupTable, commentGroupTable.Indices[0]))
}
func addCommentMigrations(mg *Migrator) {
commentTable := Table{
Name: "comment",
Columns: []*Column{
{Name: "id", Type: DB_BigInt, Nullable: false, IsPrimaryKey: true, IsAutoIncrement: true},
{Name: "group_id", Type: DB_BigInt, Nullable: false},
{Name: "user_id", Type: DB_BigInt, Nullable: false},
{Name: "content", Type: DB_MediumText, Nullable: false},
{Name: "created", Type: DB_Int, Nullable: false},
{Name: "updated", Type: DB_Int, Nullable: false},
},
Indices: []*Index{
{Cols: []string{"group_id"}, Type: IndexType},
{Cols: []string{"created"}, Type: IndexType},
},
}
mg.AddMigration("create comment table", NewAddTableMigration(commentTable))
mg.AddMigration("add index comment.group_id", NewAddIndexMigration(commentTable, commentTable.Indices[0]))
mg.AddMigration("add index comment.created", NewAddIndexMigration(commentTable, commentTable.Indices[1]))
}

View File

@ -78,6 +78,13 @@ func (*OSSMigrations) AddMigration(mg *Migrator) {
accesscontrol.AddTeamMembershipMigrations(mg)
}
}
if mg.Cfg != nil && mg.Cfg.IsFeatureToggleEnabled != nil {
if mg.Cfg.IsFeatureToggleEnabled(featuremgmt.FlagDashboardComments) || mg.Cfg.IsFeatureToggleEnabled(featuremgmt.FlagAnnotationComments) {
addCommentGroupMigrations(mg)
addCommentMigrations(mg)
}
}
}
func addMigrationLogMigrations(mg *Migrator) {

View File

@ -465,6 +465,7 @@ type InitTestDBOpt struct {
var featuresEnabledDuringTests = []string{
featuremgmt.FlagDashboardPreviews,
featuremgmt.FlagDashboardComments,
}
// InitTestDBWithMigration initializes the test DB given custom migrations.

View File

@ -618,6 +618,10 @@ func (ss *SQLStore) GetSignedInUser(ctx context.Context, query *models.GetSigned
return err
}
func (ss *SQLStore) SearchUsers(ctx context.Context, query *models.SearchUsersQuery) error {
return SearchUsers(ctx, query)
}
func SearchUsers(ctx context.Context, query *models.SearchUsersQuery) error {
query.Result = models.SearchUserQueryResult{
Users: make([]*models.UserSearchHitDTO, 0),