login_attempt_mig.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package migrations
  2. import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
  3. func addLoginAttemptMigrations(mg *Migrator) {
  4. loginAttemptV1 := Table{
  5. Name: "login_attempt",
  6. Columns: []*Column{
  7. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  8. {Name: "username", Type: DB_NVarchar, Length: 190, Nullable: false},
  9. {Name: "ip_address", Type: DB_NVarchar, Length: 30, Nullable: false},
  10. {Name: "created", Type: DB_DateTime, Nullable: false},
  11. },
  12. Indices: []*Index{
  13. {Cols: []string{"username"}},
  14. },
  15. }
  16. // create table
  17. mg.AddMigration("create login attempt table", NewAddTableMigration(loginAttemptV1))
  18. // add indices
  19. mg.AddMigration("add index login_attempt.username", NewAddIndexMigration(loginAttemptV1, loginAttemptV1.Indices[0]))
  20. loginAttemptV2 := Table{
  21. Name: "login_attempt",
  22. Columns: []*Column{
  23. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  24. {Name: "username", Type: DB_NVarchar, Length: 190, Nullable: false},
  25. {Name: "ip_address", Type: DB_NVarchar, Length: 30, Nullable: false},
  26. {Name: "created", Type: DB_Int, Default: "0", Nullable: false},
  27. },
  28. Indices: []*Index{
  29. {Cols: []string{"username"}},
  30. },
  31. }
  32. addTableReplaceMigrations(mg, loginAttemptV1, loginAttemptV2, 2, map[string]string{
  33. "id": "id",
  34. "username": "username",
  35. "ip_address": "ip_address",
  36. })
  37. }