dashboard_snapshot_mig.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package migrations
  2. import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
  3. func addDashboardSnapshotMigrations(mg *Migrator) {
  4. snapshotV4 := Table{
  5. Name: "dashboard_snapshot",
  6. Columns: []*Column{
  7. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  8. {Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
  9. {Name: "key", Type: DB_NVarchar, Length: 190, Nullable: false},
  10. {Name: "dashboard", Type: DB_Text, Nullable: false},
  11. {Name: "expires", Type: DB_DateTime, Nullable: false},
  12. {Name: "created", Type: DB_DateTime, Nullable: false},
  13. {Name: "updated", Type: DB_DateTime, Nullable: false},
  14. },
  15. Indices: []*Index{
  16. {Cols: []string{"key"}, Type: UniqueIndex},
  17. },
  18. }
  19. // add v4
  20. mg.AddMigration("create dashboard_snapshot table v4", NewAddTableMigration(snapshotV4))
  21. mg.AddMigration("drop table dashboard_snapshot_v4 #1", NewDropTableMigration("dashboard_snapshot"))
  22. snapshotV5 := Table{
  23. Name: "dashboard_snapshot",
  24. Columns: []*Column{
  25. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  26. {Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
  27. {Name: "key", Type: DB_NVarchar, Length: 190, Nullable: false},
  28. {Name: "delete_key", Type: DB_NVarchar, Length: 190, Nullable: false},
  29. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  30. {Name: "user_id", Type: DB_BigInt, Nullable: false},
  31. {Name: "external", Type: DB_Bool, Nullable: false},
  32. {Name: "external_url", Type: DB_NVarchar, Length: 255, Nullable: false},
  33. {Name: "dashboard", Type: DB_Text, Nullable: false},
  34. {Name: "expires", Type: DB_DateTime, Nullable: false},
  35. {Name: "created", Type: DB_DateTime, Nullable: false},
  36. {Name: "updated", Type: DB_DateTime, Nullable: false},
  37. },
  38. Indices: []*Index{
  39. {Cols: []string{"key"}, Type: UniqueIndex},
  40. {Cols: []string{"delete_key"}, Type: UniqueIndex},
  41. {Cols: []string{"user_id"}},
  42. },
  43. }
  44. mg.AddMigration("create dashboard_snapshot table v5 #2", NewAddTableMigration(snapshotV5))
  45. addTableIndicesMigrations(mg, "v5", snapshotV5)
  46. // change column type of dashboard
  47. mg.AddMigration("alter dashboard_snapshot to mediumtext v2", new(RawSqlMigration).
  48. Sqlite("SELECT 0 WHERE 0;").
  49. Postgres("SELECT 0;").
  50. Mysql("ALTER TABLE dashboard_snapshot MODIFY dashboard MEDIUMTEXT;"))
  51. mg.AddMigration("Update dashboard_snapshot table charset", NewTableCharsetMigration("dashboard_snapshot", []*Column{
  52. {Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
  53. {Name: "key", Type: DB_NVarchar, Length: 190, Nullable: false},
  54. {Name: "delete_key", Type: DB_NVarchar, Length: 190, Nullable: false},
  55. {Name: "external_url", Type: DB_NVarchar, Length: 255, Nullable: false},
  56. {Name: "dashboard", Type: DB_MediumText, Nullable: false},
  57. }))
  58. }