user_auth_token_mig.go 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. package migrations
  2. import (
  3. . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
  4. )
  5. func addUserAuthTokenMigrations(mg *Migrator) {
  6. userAuthTokenV1 := Table{
  7. Name: "user_auth_token",
  8. Columns: []*Column{
  9. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  10. {Name: "user_id", Type: DB_BigInt, Nullable: false},
  11. {Name: "auth_token", Type: DB_NVarchar, Length: 100, Nullable: false},
  12. {Name: "prev_auth_token", Type: DB_NVarchar, Length: 100, Nullable: false},
  13. {Name: "user_agent", Type: DB_NVarchar, Length: 255, Nullable: false},
  14. {Name: "client_ip", Type: DB_NVarchar, Length: 255, Nullable: false},
  15. {Name: "auth_token_seen", Type: DB_Bool, Nullable: false},
  16. {Name: "seen_at", Type: DB_Int, Nullable: true},
  17. {Name: "rotated_at", Type: DB_Int, Nullable: false},
  18. {Name: "created_at", Type: DB_Int, Nullable: false},
  19. {Name: "updated_at", Type: DB_Int, Nullable: false},
  20. },
  21. Indices: []*Index{
  22. {Cols: []string{"auth_token"}, Type: UniqueIndex},
  23. {Cols: []string{"prev_auth_token"}, Type: UniqueIndex},
  24. },
  25. }
  26. mg.AddMigration("create user auth token table", NewAddTableMigration(userAuthTokenV1))
  27. mg.AddMigration("add unique index user_auth_token.auth_token", NewAddIndexMigration(userAuthTokenV1, userAuthTokenV1.Indices[0]))
  28. mg.AddMigration("add unique index user_auth_token.prev_auth_token", NewAddIndexMigration(userAuthTokenV1, userAuthTokenV1.Indices[1]))
  29. }