code.gitea.io/gitea@v1.21.7/models/migrations/v1_20/v249.go (about)

     1  // Copyright 2023 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package v1_20 //nolint
     5  
     6  import (
     7  	"code.gitea.io/gitea/modules/timeutil"
     8  
     9  	"xorm.io/xorm"
    10  	"xorm.io/xorm/schemas"
    11  )
    12  
    13  type Action struct {
    14  	UserID      int64 // Receiver user id.
    15  	ActUserID   int64 // Action user id.
    16  	RepoID      int64
    17  	IsDeleted   bool               `xorm:"NOT NULL DEFAULT false"`
    18  	IsPrivate   bool               `xorm:"NOT NULL DEFAULT false"`
    19  	CreatedUnix timeutil.TimeStamp `xorm:"created"`
    20  }
    21  
    22  // TableName sets the name of this table
    23  func (a *Action) TableName() string {
    24  	return "action"
    25  }
    26  
    27  // TableIndices implements xorm's TableIndices interface
    28  func (a *Action) TableIndices() []*schemas.Index {
    29  	repoIndex := schemas.NewIndex("r_u_d", schemas.IndexType)
    30  	repoIndex.AddColumn("repo_id", "user_id", "is_deleted")
    31  
    32  	actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
    33  	actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
    34  
    35  	cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
    36  	cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
    37  
    38  	indices := []*schemas.Index{actUserIndex, repoIndex, cudIndex}
    39  
    40  	return indices
    41  }
    42  
    43  func ImproveActionTableIndices(x *xorm.Engine) error {
    44  	return x.Sync(new(Action))
    45  }