diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 6dff3e055b..4e27af4d73 100644 --- a/models/migrations/migrations.go +++ b/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 diff --git a/models/migrations/v211.go b/models/migrations/v211.go new file mode 100644 index 0000000000..7a72b4b20a --- /dev/null +++ b/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 + } +} diff --git a/models/user/user.go b/models/user/user.go index ac70c242b5..5ce5d3cbd5 100644 --- a/models/user/user.go +++ b/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"`