mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
chore: remove entity index again
chore: add migration note
This commit is contained in:
parent
647bf1781d
commit
8c65da9031
24
migrations/20220313_index_generation_hint.go
Normal file
24
migrations/20220313_index_generation_hint.go
Normal file
@ -0,0 +1,24 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/emvi/logbuch"
|
||||
"github.com/muety/wakapi/config"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func init() {
|
||||
const name = "20220313-index_generation_hint"
|
||||
f := migrationFunc{
|
||||
name: name,
|
||||
f: func(db *gorm.DB, cfg *config.Config) error {
|
||||
if hasRun(name, db) {
|
||||
return nil
|
||||
}
|
||||
logbuch.Info("please note: the following migrations might take a few minutes, as column types are changed and new indexes are created, have some patience")
|
||||
setHasRun(name, db)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
registerPreMigration(f)
|
||||
}
|
@ -12,7 +12,7 @@ type Heartbeat struct {
|
||||
ID uint64 `gorm:"primary_key" hash:"ignore"`
|
||||
User *User `json:"-" gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" hash:"ignore"`
|
||||
UserID string `json:"-" gorm:"not null; index:idx_time_user"`
|
||||
Entity string `json:"entity" gorm:"not null; index:idx_entity"`
|
||||
Entity string `json:"entity" gorm:"not null"`
|
||||
Type string `json:"type"`
|
||||
Category string `json:"category"`
|
||||
Project string `json:"project" gorm:"index:idx_project"`
|
||||
|
@ -1,7 +1,6 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/muety/wakapi/models"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
@ -158,16 +157,10 @@ func (r *HeartbeatRepository) CountByUsers(users []*models.User) ([]*models.Coun
|
||||
}
|
||||
|
||||
func (r HeartbeatRepository) GetEntitySetByUser(entityType uint8, user *models.User) ([]string, error) {
|
||||
columns := []string{"project", "language", "editor", "operating_system", "machine"}
|
||||
if int(entityType) >= len(columns) {
|
||||
// invalid entity type
|
||||
return nil, errors.New("invalid entity type")
|
||||
}
|
||||
|
||||
var results []string
|
||||
if err := r.db.
|
||||
Model(&models.Heartbeat{}).
|
||||
Distinct(columns[entityType]).
|
||||
Distinct(models.GetEntityColumn(entityType)).
|
||||
Where(&models.Heartbeat{UserID: user.ID}).
|
||||
Find(&results).Error; err != nil {
|
||||
return nil, err
|
||||
|
@ -1 +1 @@
|
||||
2.2.4
|
||||
2.2.5
|
Loading…
Reference in New Issue
Block a user