2015-02-24 18:46:34 +08:00
|
|
|
package migrations
|
|
|
|
|
|
|
|
import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
|
|
|
|
|
|
|
// --- Migration Guide line ---
|
|
|
|
// 1. Never change a migration that is committed and pushed to master
|
|
|
|
// 2. Always add new migrations (to change or undo previous migrations)
|
2017-02-03 19:10:22 +08:00
|
|
|
// 3. Some migrations are not yet written (rename column, table, drop table, index etc)
|
2015-02-24 18:46:34 +08:00
|
|
|
|
|
|
|
func AddMigrations(mg *Migrator) {
|
|
|
|
addMigrationLogMigrations(mg)
|
|
|
|
addUserMigrations(mg)
|
2015-07-16 23:59:11 +08:00
|
|
|
addTempUserMigrations(mg)
|
2015-02-24 18:46:34 +08:00
|
|
|
addStarMigrations(mg)
|
|
|
|
addOrgMigrations(mg)
|
|
|
|
addDashboardMigration(mg)
|
|
|
|
addDataSourceMigration(mg)
|
|
|
|
addApiKeyMigrations(mg)
|
2015-03-21 20:53:16 +08:00
|
|
|
addDashboardSnapshotMigrations(mg)
|
2015-07-20 20:51:27 +08:00
|
|
|
addQuotaMigration(mg)
|
2016-01-11 04:37:11 +08:00
|
|
|
addAppSettingsMigration(mg)
|
2015-12-23 15:33:46 +08:00
|
|
|
addSessionMigration(mg)
|
2015-12-24 18:25:49 +08:00
|
|
|
addPlaylistMigrations(mg)
|
2016-03-04 17:29:46 +08:00
|
|
|
addPreferencesMigrations(mg)
|
2016-04-13 16:33:45 +08:00
|
|
|
addAlertMigrations(mg)
|
2016-08-01 16:07:00 +08:00
|
|
|
addAnnotationMig(mg)
|
2015-02-24 18:46:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func addMigrationLogMigrations(mg *Migrator) {
|
2015-02-25 01:32:29 +08:00
|
|
|
migrationLogV1 := Table{
|
|
|
|
Name: "migration_log",
|
|
|
|
Columns: []*Column{
|
2015-03-07 23:23:22 +08:00
|
|
|
{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},
|
2015-02-25 01:32:29 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
mg.AddMigration("create migration_log table", NewAddTableMigration(migrationLogV1))
|
2015-02-24 18:46:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func addStarMigrations(mg *Migrator) {
|
2015-02-25 01:32:29 +08:00
|
|
|
starV1 := Table{
|
|
|
|
Name: "star",
|
|
|
|
Columns: []*Column{
|
2015-03-07 23:23:22 +08:00
|
|
|
{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},
|
2015-02-25 01:32:29 +08:00
|
|
|
},
|
|
|
|
Indices: []*Index{
|
2015-03-07 23:23:22 +08:00
|
|
|
{Cols: []string{"user_id", "dashboard_id"}, Type: UniqueIndex},
|
2015-02-25 01:32:29 +08:00
|
|
|
},
|
|
|
|
}
|
2015-02-24 18:46:34 +08:00
|
|
|
|
2015-02-25 01:32:29 +08:00
|
|
|
mg.AddMigration("create star table", NewAddTableMigration(starV1))
|
|
|
|
mg.AddMigration("add unique index star.user_id_dashboard_id", NewAddIndexMigration(starV1, starV1.Indices[0]))
|
2015-02-24 18:46:34 +08:00
|
|
|
}
|