From 3668072219d69246b23eec2a76db333f0881965f Mon Sep 17 00:00:00 2001 From: motatoes Date: Wed, 25 Sep 2024 17:58:48 +0100 Subject: [PATCH] modify drift app --- ee/drift/controllers/github.go | 2 +- ee/drift/dbmodels/github.go | 4 +- ee/drift/dbmodels/storage.go | 2 +- ee/drift/model/projects.gen.go | 1 + ee/drift/model/repos.gen.go | 2 +- ee/drift/model/user_settings.gen.go | 26 ++ ee/drift/model/users.gen.go | 4 +- ee/drift/models_generated/gen.go | 8 + ee/drift/models_generated/projects.gen.go | 6 +- ee/drift/models_generated/repos.gen.go | 6 +- .../models_generated/user_settings.gen.go | 400 ++++++++++++++++++ ee/drift/models_generated/users.gen.go | 18 +- 12 files changed, 464 insertions(+), 15 deletions(-) create mode 100644 ee/drift/model/user_settings.gen.go create mode 100644 ee/drift/models_generated/user_settings.gen.go diff --git a/ee/drift/controllers/github.go b/ee/drift/controllers/github.go index 0c7337b5e..2dcfe3776 100644 --- a/ee/drift/controllers/github.go +++ b/ee/drift/controllers/github.go @@ -94,7 +94,7 @@ func (mc MainController) GithubAppCallbackPage(c *gin.Context) { repoName := *repo.Name repoUrl := fmt.Sprintf("https://github.com/%v", repoFullName) - _, _, err = dbmodels.CreateOrGetDiggerRepoForGithubRepo(repoFullName, repoOwner, repoName, repoUrl, installationId64, *installation.AppID, *installation.Account.ID, *installation.Account.Login) + _, _, err = dbmodels.CreateOrGetDiggerRepoForGithubRepo(repoFullName, repoOwner, repoName, repoUrl, installationId, *installation.AppID, *installation.Account.ID, *installation.Account.Login) if err != nil { log.Printf("createOrGetDiggerRepoForGithubRepo error: %v", err) c.String(http.StatusInternalServerError, "createOrGetDiggerRepoForGithubRepo error: %v", err) diff --git a/ee/drift/dbmodels/github.go b/ee/drift/dbmodels/github.go index 2bdb512c4..271acf861 100644 --- a/ee/drift/dbmodels/github.go +++ b/ee/drift/dbmodels/github.go @@ -16,7 +16,7 @@ const ( GithubAppInstallationLinkInactive GithubAppInstallationLinkStatus = "inactive" ) -func (db *Database) GetGithubInstallationLinkForInstallationId(installationId int64) (*model.GithubAppInstallationLink, error) { +func (db *Database) GetGithubInstallationLinkForInstallationId(installationId string) (*model.GithubAppInstallationLink, error) { l := model.GithubAppInstallationLink{} err := db.GormDB.Where("github_installation_id = ? AND status=?", installationId, GithubAppInstallationLinkActive).Find(&l).Error if err != nil { @@ -28,7 +28,7 @@ func (db *Database) GetGithubInstallationLinkForInstallationId(installationId in return &l, nil } -func CreateOrGetDiggerRepoForGithubRepo(ghRepoFullName string, ghRepoOrganisation string, ghRepoName string, ghRepoUrl string, installationId int64, githubAppId int64, accountId int64, login string) (*model.Repo, *model.Organisation, error) { +func CreateOrGetDiggerRepoForGithubRepo(ghRepoFullName string, ghRepoOrganisation string, ghRepoName string, ghRepoUrl string, installationId string, githubAppId int64, accountId int64, login string) (*model.Repo, *model.Organisation, error) { link, err := DB.GetGithubInstallationLinkForInstallationId(installationId) if err != nil { log.Printf("Error fetching installation link: %v", err) diff --git a/ee/drift/dbmodels/storage.go b/ee/drift/dbmodels/storage.go index f0991bae8..9e42626a0 100644 --- a/ee/drift/dbmodels/storage.go +++ b/ee/drift/dbmodels/storage.go @@ -58,7 +58,7 @@ func (db *Database) CreateGithubInstallationLink(orgId string, installationId st return &link, nil } -func (db *Database) CreateRepo(name string, repoFullName string, repoOrganisation string, repoName string, repoUrl string, org *model.Organisation, diggerConfig string, githubInstallationId int64, githubAppId int64, accountId int64, login string) (*model.Repo, error) { +func (db *Database) CreateRepo(name string, repoFullName string, repoOrganisation string, repoName string, repoUrl string, org *model.Organisation, diggerConfig string, githubInstallationId string, githubAppId int64, accountId int64, login string) (*model.Repo, error) { var repo model.Repo // check if repo exist already, do nothing in this case result := db.GormDB.Where("name = ? AND organization_id=?", name, org.ID).Find(&repo) diff --git a/ee/drift/model/projects.gen.go b/ee/drift/model/projects.gen.go index 0af271a0c..7f7d8524a 100644 --- a/ee/drift/model/projects.gen.go +++ b/ee/drift/model/projects.gen.go @@ -27,6 +27,7 @@ type Project struct { ToUpdate int32 `gorm:"column:to_update" json:"to_update"` ToChange int32 `gorm:"column:to_change" json:"to_change"` ToDelete int32 `gorm:"column:to_delete" json:"to_delete"` + IsAcknowledged bool `gorm:"column:is_acknowledged;not null" json:"is_acknowledged"` } // TableName Project's table name diff --git a/ee/drift/model/repos.gen.go b/ee/drift/model/repos.gen.go index eb4d0d56e..355149923 100644 --- a/ee/drift/model/repos.gen.go +++ b/ee/drift/model/repos.gen.go @@ -25,7 +25,7 @@ type Repo struct { RepoOrganisation string `gorm:"column:repo_organisation" json:"repo_organisation"` RepoName string `gorm:"column:repo_name" json:"repo_name"` RepoURL string `gorm:"column:repo_url" json:"repo_url"` - GithubInstallationID int64 `gorm:"column:github_installation_id" json:"github_installation_id"` + GithubInstallationID string `gorm:"column:github_installation_id" json:"github_installation_id"` GithubAppID int64 `gorm:"column:github_app_id" json:"github_app_id"` AccountID int64 `gorm:"column:account_id" json:"account_id"` Login string `gorm:"column:login" json:"login"` diff --git a/ee/drift/model/user_settings.gen.go b/ee/drift/model/user_settings.gen.go new file mode 100644 index 000000000..132f40102 --- /dev/null +++ b/ee/drift/model/user_settings.gen.go @@ -0,0 +1,26 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package model + +import ( + "time" +) + +const TableNameUserSetting = "user_settings" + +// UserSetting mapped from table +type UserSetting struct { + ID int64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"` + CreatedAt time.Time `gorm:"column:created_at;not null;default:now()" json:"created_at"` + ScheduleType string `gorm:"column:schedule_type" json:"schedule_type"` + Schedule string `gorm:"column:schedule" json:"schedule"` + SlackNotificationURL string `gorm:"column:slack_notification_url" json:"slack_notification_url"` + UserID string `gorm:"column:user_id;not null" json:"user_id"` +} + +// TableName UserSetting's table name +func (*UserSetting) TableName() string { + return TableNameUserSetting +} diff --git a/ee/drift/model/users.gen.go b/ee/drift/model/users.gen.go index bee150336..e171f3d91 100644 --- a/ee/drift/model/users.gen.go +++ b/ee/drift/model/users.gen.go @@ -19,8 +19,10 @@ type User struct { UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"` Email string `gorm:"column:email;not null" json:"email"` - Name string `gorm:"column:name" json:"name"` OrganisationID string `gorm:"column:organisation_id" json:"organisation_id"` + ExternalID string `gorm:"column:external_id" json:"external_id"` + FirstName string `gorm:"column:first_name" json:"first_name"` + LastName string `gorm:"column:last_name" json:"last_name"` } // TableName User's table name diff --git a/ee/drift/models_generated/gen.go b/ee/drift/models_generated/gen.go index c2b5c2441..69e7b24a7 100644 --- a/ee/drift/models_generated/gen.go +++ b/ee/drift/models_generated/gen.go @@ -22,6 +22,7 @@ var ( Project *project Repo *repo User *user + UserSetting *userSetting ) func SetDefault(db *gorm.DB, opts ...gen.DOOption) { @@ -31,6 +32,7 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) { Project = &Q.Project Repo = &Q.Repo User = &Q.User + UserSetting = &Q.UserSetting } func Use(db *gorm.DB, opts ...gen.DOOption) *Query { @@ -41,6 +43,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query { Project: newProject(db, opts...), Repo: newRepo(db, opts...), User: newUser(db, opts...), + UserSetting: newUserSetting(db, opts...), } } @@ -52,6 +55,7 @@ type Query struct { Project project Repo repo User user + UserSetting userSetting } func (q *Query) Available() bool { return q.db != nil } @@ -64,6 +68,7 @@ func (q *Query) clone(db *gorm.DB) *Query { Project: q.Project.clone(db), Repo: q.Repo.clone(db), User: q.User.clone(db), + UserSetting: q.UserSetting.clone(db), } } @@ -83,6 +88,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query { Project: q.Project.replaceDB(db), Repo: q.Repo.replaceDB(db), User: q.User.replaceDB(db), + UserSetting: q.UserSetting.replaceDB(db), } } @@ -92,6 +98,7 @@ type queryCtx struct { Project IProjectDo Repo IRepoDo User IUserDo + UserSetting IUserSettingDo } func (q *Query) WithContext(ctx context.Context) *queryCtx { @@ -101,6 +108,7 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx { Project: q.Project.WithContext(ctx), Repo: q.Repo.WithContext(ctx), User: q.User.WithContext(ctx), + UserSetting: q.UserSetting.WithContext(ctx), } } diff --git a/ee/drift/models_generated/projects.gen.go b/ee/drift/models_generated/projects.gen.go index 5bd74222f..e786492af 100644 --- a/ee/drift/models_generated/projects.gen.go +++ b/ee/drift/models_generated/projects.gen.go @@ -40,6 +40,7 @@ func newProject(db *gorm.DB, opts ...gen.DOOption) project { _project.ToUpdate = field.NewInt32(tableName, "to_update") _project.ToChange = field.NewInt32(tableName, "to_change") _project.ToDelete = field.NewInt32(tableName, "to_delete") + _project.IsAcknowledged = field.NewBool(tableName, "is_acknowledged") _project.fillFieldMap() @@ -63,6 +64,7 @@ type project struct { ToUpdate field.Int32 ToChange field.Int32 ToDelete field.Int32 + IsAcknowledged field.Bool fieldMap map[string]field.Expr } @@ -92,6 +94,7 @@ func (p *project) updateTableName(table string) *project { p.ToUpdate = field.NewInt32(table, "to_update") p.ToChange = field.NewInt32(table, "to_change") p.ToDelete = field.NewInt32(table, "to_delete") + p.IsAcknowledged = field.NewBool(table, "is_acknowledged") p.fillFieldMap() @@ -108,7 +111,7 @@ func (p *project) GetFieldByName(fieldName string) (field.OrderExpr, bool) { } func (p *project) fillFieldMap() { - p.fieldMap = make(map[string]field.Expr, 13) + p.fieldMap = make(map[string]field.Expr, 14) p.fieldMap["id"] = p.ID p.fieldMap["created_at"] = p.CreatedAt p.fieldMap["updated_at"] = p.UpdatedAt @@ -122,6 +125,7 @@ func (p *project) fillFieldMap() { p.fieldMap["to_update"] = p.ToUpdate p.fieldMap["to_change"] = p.ToChange p.fieldMap["to_delete"] = p.ToDelete + p.fieldMap["is_acknowledged"] = p.IsAcknowledged } func (p project) clone(db *gorm.DB) project { diff --git a/ee/drift/models_generated/repos.gen.go b/ee/drift/models_generated/repos.gen.go index 50b52023f..447edfe58 100644 --- a/ee/drift/models_generated/repos.gen.go +++ b/ee/drift/models_generated/repos.gen.go @@ -38,7 +38,7 @@ func newRepo(db *gorm.DB, opts ...gen.DOOption) repo { _repo.RepoOrganisation = field.NewString(tableName, "repo_organisation") _repo.RepoName = field.NewString(tableName, "repo_name") _repo.RepoURL = field.NewString(tableName, "repo_url") - _repo.GithubInstallationID = field.NewInt64(tableName, "github_installation_id") + _repo.GithubInstallationID = field.NewString(tableName, "github_installation_id") _repo.GithubAppID = field.NewInt64(tableName, "github_app_id") _repo.AccountID = field.NewInt64(tableName, "account_id") _repo.Login = field.NewString(tableName, "login") @@ -63,7 +63,7 @@ type repo struct { RepoOrganisation field.String RepoName field.String RepoURL field.String - GithubInstallationID field.Int64 + GithubInstallationID field.String GithubAppID field.Int64 AccountID field.Int64 Login field.String @@ -94,7 +94,7 @@ func (r *repo) updateTableName(table string) *repo { r.RepoOrganisation = field.NewString(table, "repo_organisation") r.RepoName = field.NewString(table, "repo_name") r.RepoURL = field.NewString(table, "repo_url") - r.GithubInstallationID = field.NewInt64(table, "github_installation_id") + r.GithubInstallationID = field.NewString(table, "github_installation_id") r.GithubAppID = field.NewInt64(table, "github_app_id") r.AccountID = field.NewInt64(table, "account_id") r.Login = field.NewString(table, "login") diff --git a/ee/drift/models_generated/user_settings.gen.go b/ee/drift/models_generated/user_settings.gen.go new file mode 100644 index 000000000..6396392c2 --- /dev/null +++ b/ee/drift/models_generated/user_settings.gen.go @@ -0,0 +1,400 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package models_generated + +import ( + "context" + + "gorm.io/gorm" + "gorm.io/gorm/clause" + "gorm.io/gorm/schema" + + "gorm.io/gen" + "gorm.io/gen/field" + + "gorm.io/plugin/dbresolver" + + "github.com/diggerhq/digger/ee/drift/model" +) + +func newUserSetting(db *gorm.DB, opts ...gen.DOOption) userSetting { + _userSetting := userSetting{} + + _userSetting.userSettingDo.UseDB(db, opts...) + _userSetting.userSettingDo.UseModel(&model.UserSetting{}) + + tableName := _userSetting.userSettingDo.TableName() + _userSetting.ALL = field.NewAsterisk(tableName) + _userSetting.ID = field.NewInt64(tableName, "id") + _userSetting.CreatedAt = field.NewTime(tableName, "created_at") + _userSetting.ScheduleType = field.NewString(tableName, "schedule_type") + _userSetting.Schedule = field.NewString(tableName, "schedule") + _userSetting.SlackNotificationURL = field.NewString(tableName, "slack_notification_url") + _userSetting.UserID = field.NewString(tableName, "user_id") + + _userSetting.fillFieldMap() + + return _userSetting +} + +type userSetting struct { + userSettingDo + + ALL field.Asterisk + ID field.Int64 + CreatedAt field.Time + ScheduleType field.String + Schedule field.String + SlackNotificationURL field.String + UserID field.String + + fieldMap map[string]field.Expr +} + +func (u userSetting) Table(newTableName string) *userSetting { + u.userSettingDo.UseTable(newTableName) + return u.updateTableName(newTableName) +} + +func (u userSetting) As(alias string) *userSetting { + u.userSettingDo.DO = *(u.userSettingDo.As(alias).(*gen.DO)) + return u.updateTableName(alias) +} + +func (u *userSetting) updateTableName(table string) *userSetting { + u.ALL = field.NewAsterisk(table) + u.ID = field.NewInt64(table, "id") + u.CreatedAt = field.NewTime(table, "created_at") + u.ScheduleType = field.NewString(table, "schedule_type") + u.Schedule = field.NewString(table, "schedule") + u.SlackNotificationURL = field.NewString(table, "slack_notification_url") + u.UserID = field.NewString(table, "user_id") + + u.fillFieldMap() + + return u +} + +func (u *userSetting) GetFieldByName(fieldName string) (field.OrderExpr, bool) { + _f, ok := u.fieldMap[fieldName] + if !ok || _f == nil { + return nil, false + } + _oe, ok := _f.(field.OrderExpr) + return _oe, ok +} + +func (u *userSetting) fillFieldMap() { + u.fieldMap = make(map[string]field.Expr, 6) + u.fieldMap["id"] = u.ID + u.fieldMap["created_at"] = u.CreatedAt + u.fieldMap["schedule_type"] = u.ScheduleType + u.fieldMap["schedule"] = u.Schedule + u.fieldMap["slack_notification_url"] = u.SlackNotificationURL + u.fieldMap["user_id"] = u.UserID +} + +func (u userSetting) clone(db *gorm.DB) userSetting { + u.userSettingDo.ReplaceConnPool(db.Statement.ConnPool) + return u +} + +func (u userSetting) replaceDB(db *gorm.DB) userSetting { + u.userSettingDo.ReplaceDB(db) + return u +} + +type userSettingDo struct{ gen.DO } + +type IUserSettingDo interface { + gen.SubQuery + Debug() IUserSettingDo + WithContext(ctx context.Context) IUserSettingDo + WithResult(fc func(tx gen.Dao)) gen.ResultInfo + ReplaceDB(db *gorm.DB) + ReadDB() IUserSettingDo + WriteDB() IUserSettingDo + As(alias string) gen.Dao + Session(config *gorm.Session) IUserSettingDo + Columns(cols ...field.Expr) gen.Columns + Clauses(conds ...clause.Expression) IUserSettingDo + Not(conds ...gen.Condition) IUserSettingDo + Or(conds ...gen.Condition) IUserSettingDo + Select(conds ...field.Expr) IUserSettingDo + Where(conds ...gen.Condition) IUserSettingDo + Order(conds ...field.Expr) IUserSettingDo + Distinct(cols ...field.Expr) IUserSettingDo + Omit(cols ...field.Expr) IUserSettingDo + Join(table schema.Tabler, on ...field.Expr) IUserSettingDo + LeftJoin(table schema.Tabler, on ...field.Expr) IUserSettingDo + RightJoin(table schema.Tabler, on ...field.Expr) IUserSettingDo + Group(cols ...field.Expr) IUserSettingDo + Having(conds ...gen.Condition) IUserSettingDo + Limit(limit int) IUserSettingDo + Offset(offset int) IUserSettingDo + Count() (count int64, err error) + Scopes(funcs ...func(gen.Dao) gen.Dao) IUserSettingDo + Unscoped() IUserSettingDo + Create(values ...*model.UserSetting) error + CreateInBatches(values []*model.UserSetting, batchSize int) error + Save(values ...*model.UserSetting) error + First() (*model.UserSetting, error) + Take() (*model.UserSetting, error) + Last() (*model.UserSetting, error) + Find() ([]*model.UserSetting, error) + FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.UserSetting, err error) + FindInBatches(result *[]*model.UserSetting, batchSize int, fc func(tx gen.Dao, batch int) error) error + Pluck(column field.Expr, dest interface{}) error + Delete(...*model.UserSetting) (info gen.ResultInfo, err error) + Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + Updates(value interface{}) (info gen.ResultInfo, err error) + UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + UpdateColumns(value interface{}) (info gen.ResultInfo, err error) + UpdateFrom(q gen.SubQuery) gen.Dao + Attrs(attrs ...field.AssignExpr) IUserSettingDo + Assign(attrs ...field.AssignExpr) IUserSettingDo + Joins(fields ...field.RelationField) IUserSettingDo + Preload(fields ...field.RelationField) IUserSettingDo + FirstOrInit() (*model.UserSetting, error) + FirstOrCreate() (*model.UserSetting, error) + FindByPage(offset int, limit int) (result []*model.UserSetting, count int64, err error) + ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Scan(result interface{}) (err error) + Returning(value interface{}, columns ...string) IUserSettingDo + UnderlyingDB() *gorm.DB + schema.Tabler +} + +func (u userSettingDo) Debug() IUserSettingDo { + return u.withDO(u.DO.Debug()) +} + +func (u userSettingDo) WithContext(ctx context.Context) IUserSettingDo { + return u.withDO(u.DO.WithContext(ctx)) +} + +func (u userSettingDo) ReadDB() IUserSettingDo { + return u.Clauses(dbresolver.Read) +} + +func (u userSettingDo) WriteDB() IUserSettingDo { + return u.Clauses(dbresolver.Write) +} + +func (u userSettingDo) Session(config *gorm.Session) IUserSettingDo { + return u.withDO(u.DO.Session(config)) +} + +func (u userSettingDo) Clauses(conds ...clause.Expression) IUserSettingDo { + return u.withDO(u.DO.Clauses(conds...)) +} + +func (u userSettingDo) Returning(value interface{}, columns ...string) IUserSettingDo { + return u.withDO(u.DO.Returning(value, columns...)) +} + +func (u userSettingDo) Not(conds ...gen.Condition) IUserSettingDo { + return u.withDO(u.DO.Not(conds...)) +} + +func (u userSettingDo) Or(conds ...gen.Condition) IUserSettingDo { + return u.withDO(u.DO.Or(conds...)) +} + +func (u userSettingDo) Select(conds ...field.Expr) IUserSettingDo { + return u.withDO(u.DO.Select(conds...)) +} + +func (u userSettingDo) Where(conds ...gen.Condition) IUserSettingDo { + return u.withDO(u.DO.Where(conds...)) +} + +func (u userSettingDo) Order(conds ...field.Expr) IUserSettingDo { + return u.withDO(u.DO.Order(conds...)) +} + +func (u userSettingDo) Distinct(cols ...field.Expr) IUserSettingDo { + return u.withDO(u.DO.Distinct(cols...)) +} + +func (u userSettingDo) Omit(cols ...field.Expr) IUserSettingDo { + return u.withDO(u.DO.Omit(cols...)) +} + +func (u userSettingDo) Join(table schema.Tabler, on ...field.Expr) IUserSettingDo { + return u.withDO(u.DO.Join(table, on...)) +} + +func (u userSettingDo) LeftJoin(table schema.Tabler, on ...field.Expr) IUserSettingDo { + return u.withDO(u.DO.LeftJoin(table, on...)) +} + +func (u userSettingDo) RightJoin(table schema.Tabler, on ...field.Expr) IUserSettingDo { + return u.withDO(u.DO.RightJoin(table, on...)) +} + +func (u userSettingDo) Group(cols ...field.Expr) IUserSettingDo { + return u.withDO(u.DO.Group(cols...)) +} + +func (u userSettingDo) Having(conds ...gen.Condition) IUserSettingDo { + return u.withDO(u.DO.Having(conds...)) +} + +func (u userSettingDo) Limit(limit int) IUserSettingDo { + return u.withDO(u.DO.Limit(limit)) +} + +func (u userSettingDo) Offset(offset int) IUserSettingDo { + return u.withDO(u.DO.Offset(offset)) +} + +func (u userSettingDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IUserSettingDo { + return u.withDO(u.DO.Scopes(funcs...)) +} + +func (u userSettingDo) Unscoped() IUserSettingDo { + return u.withDO(u.DO.Unscoped()) +} + +func (u userSettingDo) Create(values ...*model.UserSetting) error { + if len(values) == 0 { + return nil + } + return u.DO.Create(values) +} + +func (u userSettingDo) CreateInBatches(values []*model.UserSetting, batchSize int) error { + return u.DO.CreateInBatches(values, batchSize) +} + +// Save : !!! underlying implementation is different with GORM +// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) +func (u userSettingDo) Save(values ...*model.UserSetting) error { + if len(values) == 0 { + return nil + } + return u.DO.Save(values) +} + +func (u userSettingDo) First() (*model.UserSetting, error) { + if result, err := u.DO.First(); err != nil { + return nil, err + } else { + return result.(*model.UserSetting), nil + } +} + +func (u userSettingDo) Take() (*model.UserSetting, error) { + if result, err := u.DO.Take(); err != nil { + return nil, err + } else { + return result.(*model.UserSetting), nil + } +} + +func (u userSettingDo) Last() (*model.UserSetting, error) { + if result, err := u.DO.Last(); err != nil { + return nil, err + } else { + return result.(*model.UserSetting), nil + } +} + +func (u userSettingDo) Find() ([]*model.UserSetting, error) { + result, err := u.DO.Find() + return result.([]*model.UserSetting), err +} + +func (u userSettingDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.UserSetting, err error) { + buf := make([]*model.UserSetting, 0, batchSize) + err = u.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { + defer func() { results = append(results, buf...) }() + return fc(tx, batch) + }) + return results, err +} + +func (u userSettingDo) FindInBatches(result *[]*model.UserSetting, batchSize int, fc func(tx gen.Dao, batch int) error) error { + return u.DO.FindInBatches(result, batchSize, fc) +} + +func (u userSettingDo) Attrs(attrs ...field.AssignExpr) IUserSettingDo { + return u.withDO(u.DO.Attrs(attrs...)) +} + +func (u userSettingDo) Assign(attrs ...field.AssignExpr) IUserSettingDo { + return u.withDO(u.DO.Assign(attrs...)) +} + +func (u userSettingDo) Joins(fields ...field.RelationField) IUserSettingDo { + for _, _f := range fields { + u = *u.withDO(u.DO.Joins(_f)) + } + return &u +} + +func (u userSettingDo) Preload(fields ...field.RelationField) IUserSettingDo { + for _, _f := range fields { + u = *u.withDO(u.DO.Preload(_f)) + } + return &u +} + +func (u userSettingDo) FirstOrInit() (*model.UserSetting, error) { + if result, err := u.DO.FirstOrInit(); err != nil { + return nil, err + } else { + return result.(*model.UserSetting), nil + } +} + +func (u userSettingDo) FirstOrCreate() (*model.UserSetting, error) { + if result, err := u.DO.FirstOrCreate(); err != nil { + return nil, err + } else { + return result.(*model.UserSetting), nil + } +} + +func (u userSettingDo) FindByPage(offset int, limit int) (result []*model.UserSetting, count int64, err error) { + result, err = u.Offset(offset).Limit(limit).Find() + if err != nil { + return + } + + if size := len(result); 0 < limit && 0 < size && size < limit { + count = int64(size + offset) + return + } + + count, err = u.Offset(-1).Limit(-1).Count() + return +} + +func (u userSettingDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { + count, err = u.Count() + if err != nil { + return + } + + err = u.Offset(offset).Limit(limit).Scan(result) + return +} + +func (u userSettingDo) Scan(result interface{}) (err error) { + return u.DO.Scan(result) +} + +func (u userSettingDo) Delete(models ...*model.UserSetting) (result gen.ResultInfo, err error) { + return u.DO.Delete(models) +} + +func (u *userSettingDo) withDO(do gen.Dao) *userSettingDo { + u.DO = *do.(*gen.DO) + return u +} diff --git a/ee/drift/models_generated/users.gen.go b/ee/drift/models_generated/users.gen.go index 7e1a531f0..0cfc80088 100644 --- a/ee/drift/models_generated/users.gen.go +++ b/ee/drift/models_generated/users.gen.go @@ -32,8 +32,10 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user { _user.UpdatedAt = field.NewTime(tableName, "updated_at") _user.DeletedAt = field.NewField(tableName, "deleted_at") _user.Email = field.NewString(tableName, "email") - _user.Name = field.NewString(tableName, "name") _user.OrganisationID = field.NewString(tableName, "organisation_id") + _user.ExternalID = field.NewString(tableName, "external_id") + _user.FirstName = field.NewString(tableName, "first_name") + _user.LastName = field.NewString(tableName, "last_name") _user.fillFieldMap() @@ -49,8 +51,10 @@ type user struct { UpdatedAt field.Time DeletedAt field.Field Email field.String - Name field.String OrganisationID field.String + ExternalID field.String + FirstName field.String + LastName field.String fieldMap map[string]field.Expr } @@ -72,8 +76,10 @@ func (u *user) updateTableName(table string) *user { u.UpdatedAt = field.NewTime(table, "updated_at") u.DeletedAt = field.NewField(table, "deleted_at") u.Email = field.NewString(table, "email") - u.Name = field.NewString(table, "name") u.OrganisationID = field.NewString(table, "organisation_id") + u.ExternalID = field.NewString(table, "external_id") + u.FirstName = field.NewString(table, "first_name") + u.LastName = field.NewString(table, "last_name") u.fillFieldMap() @@ -90,14 +96,16 @@ func (u *user) GetFieldByName(fieldName string) (field.OrderExpr, bool) { } func (u *user) fillFieldMap() { - u.fieldMap = make(map[string]field.Expr, 7) + u.fieldMap = make(map[string]field.Expr, 9) u.fieldMap["id"] = u.ID u.fieldMap["created_at"] = u.CreatedAt u.fieldMap["updated_at"] = u.UpdatedAt u.fieldMap["deleted_at"] = u.DeletedAt u.fieldMap["email"] = u.Email - u.fieldMap["name"] = u.Name u.fieldMap["organisation_id"] = u.OrganisationID + u.fieldMap["external_id"] = u.ExternalID + u.fieldMap["first_name"] = u.FirstName + u.fieldMap["last_name"] = u.LastName } func (u user) clone(db *gorm.DB) user {