Browse Source

Добавлены поля компетенций, ресурсов и интересов к пользователю #9

добавление реализовано через механизм миграций.
pull/100/head
Artur Galyamov 2 years ago
parent
commit
dad801abf0
  1. 2
      models/migrations/migrations.go
  2. 28
      models/migrations/v211.go
  3. 3
      models/user/user.go

2
models/migrations/migrations.go

@ -373,6 +373,8 @@ var migrations = []Migration{
NewMigration("Increase WebAuthentication CredentialID size to 410 - NO-OPED", increaseCredentialIDTo410),
// v210 -> v211
NewMigration("v208 was completely broken - remigrate", remigrateU2FCredentials),
// v211 -> v212
NewMigration("add competences, resources, interests to user tbl", addTrustedPropsToUser),
}
// GetCurrentDBVersion returns the current db version

28
models/migrations/v211.go

@ -0,0 +1,28 @@
package migrations
import (
"fmt"
"xorm.io/xorm"
"xorm.io/xorm/schemas"
)
func addTrustedPropsToUser(engine *xorm.Engine) error {
var err error
tableName := "user"
switch engine.Dialect().URI().DBType {
case schemas.POSTGRES:
addColsQuery := fmt.Sprintf("ALTER TABLE \"%s\" ADD COLUMN competences TEXT, ADD COLUMN resources TEXT, ADD COLUMN interests TEXT;", tableName)
_, err = engine.Exec(addColsQuery)
case schemas.SQLITE:
addColsQuery := fmt.Sprintf("ALTER TABLE \"%s\" ADD COLUMN competences TEXT;\nALTER TABLE \"%s\" ADD COLUMN resources TEXT;\nALTER TABLE \"%s\" ADD COLUMN interests TEXT;", tableName, tableName, tableName)
_, err = engine.Exec(addColsQuery)
case schemas.MYSQL:
addColsQuery := fmt.Sprintf("ALTER TABLE `%s` ADD COLUMN competences TEXT, ADD COLUMN resources TEXT, ADD COLUMN interests TEXT;", tableName)
_, err = engine.Exec(addColsQuery)
}
if err != nil {
return fmt.Errorf("Ошибка добавление колонок компетенций и тд: %v", err)
} else {
return nil
}
}

3
models/user/user.go

@ -100,6 +100,9 @@ type User struct {
Salt string `xorm:"VARCHAR(32)"`
Language string `xorm:"VARCHAR(5)"`
Description string `xorm:"TEXT"`
Competences string `xorm:"TEXT"`
Resources string `xorm:"TEXT"`
Interests string `xorm:"TEXT"`
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`

Loading…
Cancel
Save