25e153e4e7
* #45498: add entity events table
* #45498: add entity events service
* #45498: hook up entity events service to http server
* #45498: use `dashboards.id` rather than `uid` and `org_id` in grn
* Update pkg/services/entityevents/service.go
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
* #45498: move entityeventsservice to services/store
* #45498: add null check
* #45498: rename
* #45498: fix comment
* #45498: switch grn back to uid
* Search: listen for updates (#47719)
* #45498: wire entity event service with searchv2
* load last event id before building index for org 1
* fix service init in integration tests
* depend on required subset of event store methods
* Update pkg/services/sqlstore/migrations/entity_events_mig.go
Co-authored-by: Alexander Emelin <frvzmb@gmail.com>
* #45498: pointer receiver
* #45498: mockery!
* #45498: add entity events service to background services
* dashboard query pagination, allow queries while re-indexing
* log level cleanups, use rlock, add comments
* fix lint, check feature toggle in search v2 service
* use unix time for event created column
* add missing changes for created column
* fix integration tests init
* log re-index execution times on info level
* #45498: fix entityEventsService tests
* #45498: save events on dashboard delete
* use camel case for log labels
* formatting
* #45498: rename grn to entityid
* #45498: add `IsDisabled` to entityEventsService
* #45498: remove feature flag from migration
* better context usage, fix capacity, comments/cleanups
* replace print with logger
* Revert "#45498: remove feature flag from migration"
This reverts commit ed23968898.
* revert:revert:revert conditional feature flag
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
Co-authored-by: Alexander Emelin <frvzmb@gmail.com>
126 lines
4.1 KiB
Go
126 lines
4.1 KiB
Go
package migrations
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrations/accesscontrol"
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrations/ualert"
|
|
. "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
|
)
|
|
|
|
// --- Migration Guide line ---
|
|
// 1. Never change a migration that is committed and pushed to main
|
|
// 2. Always add new migrations (to change or undo previous migrations)
|
|
// 3. Some migrations are not yet written (rename column, table, drop table, index etc)
|
|
|
|
type OSSMigrations struct {
|
|
}
|
|
|
|
func ProvideOSSMigrations() *OSSMigrations {
|
|
return &OSSMigrations{}
|
|
}
|
|
|
|
func (*OSSMigrations) AddMigration(mg *Migrator) {
|
|
addMigrationLogMigrations(mg)
|
|
addUserMigrations(mg)
|
|
addTempUserMigrations(mg)
|
|
addStarMigrations(mg)
|
|
addOrgMigrations(mg)
|
|
addDashboardMigration(mg) // Do NOT add more migrations to this function.
|
|
addDataSourceMigration(mg)
|
|
addApiKeyMigrations(mg)
|
|
addDashboardSnapshotMigrations(mg)
|
|
addQuotaMigration(mg)
|
|
addAppSettingsMigration(mg)
|
|
addSessionMigration(mg)
|
|
addPlaylistMigrations(mg)
|
|
addPreferencesMigrations(mg)
|
|
addAlertMigrations(mg)
|
|
addAnnotationMig(mg)
|
|
addTestDataMigrations(mg)
|
|
addDashboardVersionMigration(mg)
|
|
addTeamMigrations(mg)
|
|
addDashboardAclMigrations(mg) // Do NOT add more migrations to this function.
|
|
addTagMigration(mg)
|
|
addLoginAttemptMigrations(mg)
|
|
addUserAuthMigrations(mg)
|
|
addServerlockMigrations(mg)
|
|
addUserAuthTokenMigrations(mg)
|
|
addCacheMigration(mg)
|
|
addShortURLMigrations(mg)
|
|
// TODO Delete when unified alerting is enabled by default unconditionally (Grafana v9)
|
|
if err := ualert.CheckUnifiedAlertingEnabledByDefault(mg); err != nil { // this should always go before any other ualert migration
|
|
mg.Logger.Error("failed to determine the status of alerting engine. Enable either legacy or unified alerting explicitly and try again", "err", err)
|
|
os.Exit(1)
|
|
}
|
|
ualert.AddTablesMigrations(mg)
|
|
ualert.AddDashAlertMigration(mg)
|
|
addLibraryElementsMigrations(mg)
|
|
if mg.Cfg != nil && mg.Cfg.IsFeatureToggleEnabled != nil {
|
|
if mg.Cfg.IsFeatureToggleEnabled(featuremgmt.FlagLiveConfig) {
|
|
addLiveChannelMigrations(mg)
|
|
}
|
|
if mg.Cfg.IsFeatureToggleEnabled(featuremgmt.FlagDashboardPreviews) {
|
|
addDashboardThumbsMigrations(mg)
|
|
}
|
|
}
|
|
|
|
ualert.RerunDashAlertMigration(mg)
|
|
addSecretsMigration(mg)
|
|
addKVStoreMigrations(mg)
|
|
ualert.AddDashboardUIDPanelIDMigration(mg)
|
|
accesscontrol.AddMigration(mg)
|
|
addQueryHistoryMigrations(mg)
|
|
|
|
if mg.Cfg != nil && mg.Cfg.IsFeatureToggleEnabled != nil {
|
|
if mg.Cfg.IsFeatureToggleEnabled(featuremgmt.FlagAccesscontrol) {
|
|
accesscontrol.AddTeamMembershipMigrations(mg)
|
|
accesscontrol.AddDashboardPermissionsMigrator(mg)
|
|
}
|
|
}
|
|
addQueryHistoryStarMigrations(mg)
|
|
|
|
if mg.Cfg != nil && mg.Cfg.IsFeatureToggleEnabled != nil {
|
|
if mg.Cfg.IsFeatureToggleEnabled(featuremgmt.FlagDashboardComments) || mg.Cfg.IsFeatureToggleEnabled(featuremgmt.FlagAnnotationComments) {
|
|
addCommentGroupMigrations(mg)
|
|
addCommentMigrations(mg)
|
|
}
|
|
}
|
|
|
|
addEntityEventsTableMigration(mg)
|
|
}
|
|
|
|
func addMigrationLogMigrations(mg *Migrator) {
|
|
migrationLogV1 := Table{
|
|
Name: "migration_log",
|
|
Columns: []*Column{
|
|
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
|
{Name: "migration_id", Type: DB_NVarchar, Length: 255},
|
|
{Name: "sql", Type: DB_Text},
|
|
{Name: "success", Type: DB_Bool},
|
|
{Name: "error", Type: DB_Text},
|
|
{Name: "timestamp", Type: DB_DateTime},
|
|
},
|
|
}
|
|
|
|
mg.AddMigration("create migration_log table", NewAddTableMigration(migrationLogV1))
|
|
}
|
|
|
|
func addStarMigrations(mg *Migrator) {
|
|
starV1 := Table{
|
|
Name: "star",
|
|
Columns: []*Column{
|
|
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
|
{Name: "user_id", Type: DB_BigInt, Nullable: false},
|
|
{Name: "dashboard_id", Type: DB_BigInt, Nullable: false},
|
|
},
|
|
Indices: []*Index{
|
|
{Cols: []string{"user_id", "dashboard_id"}, Type: UniqueIndex},
|
|
},
|
|
}
|
|
|
|
mg.AddMigration("create star table", NewAddTableMigration(starV1))
|
|
mg.AddMigration("add unique index star.user_id_dashboard_id", NewAddIndexMigration(starV1, starV1.Indices[0]))
|
|
}
|