user_auth_mig.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package migrations
  2. import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
  3. func addUserAuthMigrations(mg *Migrator) {
  4. userAuthV1 := Table{
  5. Name: "user_auth",
  6. Columns: []*Column{
  7. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  8. {Name: "user_id", Type: DB_BigInt, Nullable: false},
  9. {Name: "auth_module", Type: DB_NVarchar, Length: 190, Nullable: false},
  10. {Name: "auth_id", Type: DB_NVarchar, Length: 100, Nullable: false},
  11. {Name: "created", Type: DB_DateTime, Nullable: false},
  12. },
  13. Indices: []*Index{
  14. {Cols: []string{"auth_module", "auth_id"}},
  15. },
  16. }
  17. // create table
  18. mg.AddMigration("create user auth table", NewAddTableMigration(userAuthV1))
  19. // add indices
  20. addTableIndicesMigrations(mg, "v1", userAuthV1)
  21. mg.AddMigration("alter user_auth.auth_id to length 190", NewRawSqlMigration("").
  22. Postgres("ALTER TABLE user_auth ALTER COLUMN auth_id TYPE VARCHAR(190);").
  23. Mysql("ALTER TABLE user_auth MODIFY auth_id VARCHAR(190);"))
  24. mg.AddMigration("Add OAuth access token to user_auth", NewAddColumnMigration(userAuthV1, &Column{
  25. Name: "o_auth_access_token", Type: DB_Text, Nullable: true,
  26. }))
  27. mg.AddMigration("Add OAuth refresh token to user_auth", NewAddColumnMigration(userAuthV1, &Column{
  28. Name: "o_auth_refresh_token", Type: DB_Text, Nullable: true,
  29. }))
  30. mg.AddMigration("Add OAuth token type to user_auth", NewAddColumnMigration(userAuthV1, &Column{
  31. Name: "o_auth_token_type", Type: DB_Text, Nullable: true,
  32. }))
  33. mg.AddMigration("Add OAuth expiry to user_auth", NewAddColumnMigration(userAuthV1, &Column{
  34. Name: "o_auth_expiry", Type: DB_DateTime, Nullable: true,
  35. }))
  36. mg.AddMigration("Add index to user_id column in user_auth", NewAddIndexMigration(userAuthV1, &Index{
  37. Cols: []string{"user_id"},
  38. }))
  39. }