code.gitea.io/gitea@v1.21.7/models/migrations/v1_19/v240.go (about)

     1  // Copyright 2022 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package v1_19 //nolint
     5  
     6  import (
     7  	"code.gitea.io/gitea/models/db"
     8  	"code.gitea.io/gitea/modules/timeutil"
     9  
    10  	"xorm.io/xorm"
    11  )
    12  
    13  func AddActionsTables(x *xorm.Engine) error {
    14  	type ActionRunner struct {
    15  		ID          int64
    16  		UUID        string `xorm:"CHAR(36) UNIQUE"`
    17  		Name        string `xorm:"VARCHAR(255)"`
    18  		OwnerID     int64  `xorm:"index"` // org level runner, 0 means system
    19  		RepoID      int64  `xorm:"index"` // repo level runner, if orgid also is zero, then it's a global
    20  		Description string `xorm:"TEXT"`
    21  		Base        int    // 0 native 1 docker 2 virtual machine
    22  		RepoRange   string // glob match which repositories could use this runner
    23  
    24  		Token     string `xorm:"-"`
    25  		TokenHash string `xorm:"UNIQUE"` // sha256 of token
    26  		TokenSalt string
    27  		// TokenLastEight string `xorm:"token_last_eight"` // it's unnecessary because we don't find runners by token
    28  
    29  		LastOnline timeutil.TimeStamp `xorm:"index"`
    30  		LastActive timeutil.TimeStamp `xorm:"index"`
    31  
    32  		// Store OS and Artch.
    33  		AgentLabels []string
    34  		// Store custom labes use defined.
    35  		CustomLabels []string
    36  
    37  		Created timeutil.TimeStamp `xorm:"created"`
    38  		Updated timeutil.TimeStamp `xorm:"updated"`
    39  		Deleted timeutil.TimeStamp `xorm:"deleted"`
    40  	}
    41  
    42  	type ActionRunnerToken struct {
    43  		ID       int64
    44  		Token    string `xorm:"UNIQUE"`
    45  		OwnerID  int64  `xorm:"index"` // org level runner, 0 means system
    46  		RepoID   int64  `xorm:"index"` // repo level runner, if orgid also is zero, then it's a global
    47  		IsActive bool
    48  
    49  		Created timeutil.TimeStamp `xorm:"created"`
    50  		Updated timeutil.TimeStamp `xorm:"updated"`
    51  		Deleted timeutil.TimeStamp `xorm:"deleted"`
    52  	}
    53  
    54  	type ActionRun struct {
    55  		ID                int64
    56  		Title             string
    57  		RepoID            int64  `xorm:"index unique(repo_index)"`
    58  		OwnerID           int64  `xorm:"index"`
    59  		WorkflowID        string `xorm:"index"`                    // the name of workflow file
    60  		Index             int64  `xorm:"index unique(repo_index)"` // a unique number for each run of a repository
    61  		TriggerUserID     int64
    62  		Ref               string
    63  		CommitSHA         string
    64  		Event             string
    65  		IsForkPullRequest bool
    66  		EventPayload      string `xorm:"LONGTEXT"`
    67  		Status            int    `xorm:"index"`
    68  		Started           timeutil.TimeStamp
    69  		Stopped           timeutil.TimeStamp
    70  		Created           timeutil.TimeStamp `xorm:"created"`
    71  		Updated           timeutil.TimeStamp `xorm:"updated"`
    72  	}
    73  
    74  	type ActionRunJob struct {
    75  		ID                int64
    76  		RunID             int64  `xorm:"index"`
    77  		RepoID            int64  `xorm:"index"`
    78  		OwnerID           int64  `xorm:"index"`
    79  		CommitSHA         string `xorm:"index"`
    80  		IsForkPullRequest bool
    81  		Name              string `xorm:"VARCHAR(255)"`
    82  		Attempt           int64
    83  		WorkflowPayload   []byte
    84  		JobID             string   `xorm:"VARCHAR(255)"` // job id in workflow, not job's id
    85  		Needs             []string `xorm:"JSON TEXT"`
    86  		RunsOn            []string `xorm:"JSON TEXT"`
    87  		TaskID            int64    // the latest task of the job
    88  		Status            int      `xorm:"index"`
    89  		Started           timeutil.TimeStamp
    90  		Stopped           timeutil.TimeStamp
    91  		Created           timeutil.TimeStamp `xorm:"created"`
    92  		Updated           timeutil.TimeStamp `xorm:"updated index"`
    93  	}
    94  
    95  	type Repository struct {
    96  		NumActionRuns       int `xorm:"NOT NULL DEFAULT 0"`
    97  		NumClosedActionRuns int `xorm:"NOT NULL DEFAULT 0"`
    98  	}
    99  
   100  	type ActionRunIndex db.ResourceIndex
   101  
   102  	type ActionTask struct {
   103  		ID       int64
   104  		JobID    int64
   105  		Attempt  int64
   106  		RunnerID int64              `xorm:"index"`
   107  		Status   int                `xorm:"index"`
   108  		Started  timeutil.TimeStamp `xorm:"index"`
   109  		Stopped  timeutil.TimeStamp
   110  
   111  		RepoID            int64  `xorm:"index"`
   112  		OwnerID           int64  `xorm:"index"`
   113  		CommitSHA         string `xorm:"index"`
   114  		IsForkPullRequest bool
   115  
   116  		TokenHash      string `xorm:"UNIQUE"` // sha256 of token
   117  		TokenSalt      string
   118  		TokenLastEight string `xorm:"index token_last_eight"`
   119  
   120  		LogFilename  string  // file name of log
   121  		LogInStorage bool    // read log from database or from storage
   122  		LogLength    int64   // lines count
   123  		LogSize      int64   // blob size
   124  		LogIndexes   []int64 `xorm:"LONGBLOB"` // line number to offset
   125  		LogExpired   bool    // files that are too old will be deleted
   126  
   127  		Created timeutil.TimeStamp `xorm:"created"`
   128  		Updated timeutil.TimeStamp `xorm:"updated index"`
   129  	}
   130  
   131  	type ActionTaskStep struct {
   132  		ID        int64
   133  		Name      string `xorm:"VARCHAR(255)"`
   134  		TaskID    int64  `xorm:"index unique(task_index)"`
   135  		Index     int64  `xorm:"index unique(task_index)"`
   136  		RepoID    int64  `xorm:"index"`
   137  		Status    int    `xorm:"index"`
   138  		LogIndex  int64
   139  		LogLength int64
   140  		Started   timeutil.TimeStamp
   141  		Stopped   timeutil.TimeStamp
   142  		Created   timeutil.TimeStamp `xorm:"created"`
   143  		Updated   timeutil.TimeStamp `xorm:"updated"`
   144  	}
   145  
   146  	type dbfsMeta struct {
   147  		ID              int64  `xorm:"pk autoincr"`
   148  		FullPath        string `xorm:"VARCHAR(500) UNIQUE NOT NULL"`
   149  		BlockSize       int64  `xorm:"BIGINT NOT NULL"`
   150  		FileSize        int64  `xorm:"BIGINT NOT NULL"`
   151  		CreateTimestamp int64  `xorm:"BIGINT NOT NULL"`
   152  		ModifyTimestamp int64  `xorm:"BIGINT NOT NULL"`
   153  	}
   154  
   155  	type dbfsData struct {
   156  		ID         int64  `xorm:"pk autoincr"`
   157  		Revision   int64  `xorm:"BIGINT NOT NULL"`
   158  		MetaID     int64  `xorm:"BIGINT index(meta_offset) NOT NULL"`
   159  		BlobOffset int64  `xorm:"BIGINT index(meta_offset) NOT NULL"`
   160  		BlobSize   int64  `xorm:"BIGINT NOT NULL"`
   161  		BlobData   []byte `xorm:"BLOB NOT NULL"`
   162  	}
   163  
   164  	return x.Sync(
   165  		new(ActionRunner),
   166  		new(ActionRunnerToken),
   167  		new(ActionRun),
   168  		new(ActionRunJob),
   169  		new(Repository),
   170  		new(ActionRunIndex),
   171  		new(ActionTask),
   172  		new(ActionTaskStep),
   173  		new(dbfsMeta),
   174  		new(dbfsData),
   175  	)
   176  }