From dad801abf0bc155c173f8a24503ce8f1d5e831c3 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Mon, 22 Aug 2022 16:04:11 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BF=D0=BE=D0=BB=D1=8F=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=BF=D0=B5=D1=82=D0=B5=D0=BD=D1=86=D0=B8=D0=B9,=20=D1=80?= =?UTF-8?q?=D0=B5=D1=81=D1=83=D1=80=D1=81=D0=BE=D0=B2=20=D0=B8=20=D0=B8?= =?UTF-8?q?=D0=BD=D1=82=D0=B5=D1=80=D0=B5=D1=81=D0=BE=D0=B2=20=D0=BA=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8E=20#9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit добавление реализовано через механизм миграций. --- models/migrations/migrations.go | 2 ++ models/migrations/v211.go | 28 ++++++++++++++++++++++++++++ models/user/user.go | 3 +++ 3 files changed, 33 insertions(+) create mode 100644 models/migrations/v211.go 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"`