model

package
v0.0.0-...-2637cd7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WorkerUseMin = iota
	WorkerBalanced
	WorkerUseMax
)

Variables

This section is empty.

Functions

func GetFromRaw

func GetFromRaw[T any](tx *gorm.DB, field string) (T, bool)

func IsForce

func IsForce(tx *gorm.DB) bool

Types

type Build

type Build struct {
	ID         uuid.UUID      `json:"id"          gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	Number     uint           `json:"number"      gorm:"index:,unique,composite:idx_builds;autoIncrement"`
	RevList    pq.StringArray `json:"rev_list"    gorm:"type:text[];not null;default:'{}'"`
	Status     BuildStatus    `json:"status"      gorm:"not null;default:0"`
	Steps      []BuildStep    `json:"steps"       gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
	PipelineID uuid.UUID      `json:"pipeline_id" gorm:"type:uuid;index:,unique,composite:idx_builds"`
	WorkerID   *uuid.UUID     `json:"worker_id"   gorm:"type:uuid"`
	CreatedAt  time.Time      `json:"created_at"  gorm:"default:now()"`
	UpdatedAt  time.Time      `json:"updated_at"  gorm:"default:now()"`
}

func (*Build) AfterCreate

func (m *Build) AfterCreate(tx *gorm.DB) error

func (*Build) BeforeUpdate

func (m *Build) BeforeUpdate(tx *gorm.DB) error

type BuildInput

type BuildInput struct {
	PipelineID string `json:"pipeline_id"`
}

type BuildLog

type BuildLog struct {
	Command     string    `json:"command"         gorm:"primaryKey"` // TODO: error: command can be bigger than limit for pk
	Idx         int       `json:"idx,omitempty"`
	Total       int       `json:"total,omitempty"`
	Output      string    `json:"output"          gorm:"not null"`
	BuildStepID uuid.UUID `json:"build_step_id"   gorm:"type:uuid;primaryKey"`
}

type BuildShort

type BuildShort struct {
	ID         uuid.UUID        `json:"id"`
	Number     uint             `json:"number"`
	RevList    pq.StringArray   `json:"rev_list"    gorm:"type:text[]"`
	Status     BuildStatus      `json:"status"`
	Steps      []BuildStepShort `json:"steps"`
	PipelineID uuid.UUID        `json:"pipeline_id"`
	WorkerID   uuid.NullUUID    `json:"worker_id,omitempty"`
	CreatedAt  time.Time        `json:"created_at"`
	UpdatedAt  time.Time        `json:"updated_at"`
}

type BuildStatus

type BuildStatus uint8
const (
	BuildScheduled BuildStatus = iota
	BuildRunning
	BuildSuccessful
	BuildFailed
	BuildCanceled
)

func (BuildStatus) String

func (s BuildStatus) String() string

type BuildStep

type BuildStep struct {
	ID        uuid.UUID     `json:"id"         gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	Number    int           `json:"number"     gorm:"not null"`
	Name      string        `json:"name"       gorm:"uniqueIndex:idx_build_steps;not null"`
	Duration  time.Duration `json:"duration"   gorm:"not null"`
	Logs      []BuildLog    `json:"logs"       gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
	BuildID   uuid.UUID     `json:"build_id"   gorm:"type:uuid;uniqueIndex:idx_build_steps;not null"`
	CreatedAt time.Time     `json:"created_at" gorm:"default:now()"`
	UpdatedAt time.Time     `json:"updated_at" gorm:"default:now()"`
}

type BuildStepShort

type BuildStepShort struct {
	Name     string        `json:"name"`
	Duration time.Duration `json:"duration"`
}

type Pipeline

type Pipeline struct {
	ID        uuid.UUID      `json:"id"         gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	Name      string         `json:"name"       gorm:"uniqueIndex:idx_pipelines;not null"`
	Branch    string         `json:"branch"     gorm:"not null"`
	LastRev   string         `json:"last_rev"   gorm:"not null"`
	Config    PipelineConfig `json:"config"     gorm:"not null;serializer:json"`
	Variables []Variable     `json:"variables"  gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
	Secrets   []Secret       `json:"secrets"    gorm:"not null"`
	Builds    []Build        `json:"builds"     gorm:"not null"`
	ProjectID uuid.UUID      `json:"project_id" gorm:"type:uuid;uniqueIndex:idx_pipelines;not null"`
	CreatedAt time.Time      `json:"created_at" gorm:"default:now()"`
	UpdatedAt time.Time      `json:"updated_at" gorm:"default:now()"`
}

TODO: replace cascade constraint with trigger (issue: https://github.com/go-gorm/gorm/issues/5001)

func (*Pipeline) AfterUpdate

func (m *Pipeline) AfterUpdate(tx *gorm.DB) error

func (*Pipeline) BeforeCreate

func (m *Pipeline) BeforeCreate(tx *gorm.DB) error

func (*Pipeline) BeforeDelete

func (m *Pipeline) BeforeDelete(tx *gorm.DB) error

type PipelineConfig

type PipelineConfig struct {
	System  string               `json:"system"`
	Image   string               `json:"image"`
	Steps   []PipelineConfigStep `json:"steps"`
	Cleanup []string             `json:"cleanup"`
}

type PipelineConfigStep

type PipelineConfigStep struct {
	Name     string   `json:"name"`
	Commands []string `json:"commands"`
}

type PipelineInput

type PipelineInput struct {
	Name      string         `json:"name"`
	Branch    string         `json:"branch"`
	Config    PipelineConfig `json:"config"`
	ProjectID uuid.UUID      `json:"project_id"`
}

type PipelineShort

type PipelineShort struct {
	ID        uuid.UUID `json:"id"`
	Name      string    `json:"name"`
	Branch    string    `json:"branch"`
	ProjectID uuid.UUID `json:"project_id"`
	CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
	UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
}

type Project

type Project struct {
	ID        uuid.UUID  `json:"id"         gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	Name      string     `json:"name"       gorm:"uniqueIndex:idx_projects"`
	Repo      string     `json:"repo"       gorm:"not null"`
	Variables []Variable `json:"variables"  gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
	Secrets   []Secret   `json:"secrets"    gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
	Pipelines []Pipeline `json:"pipelines"  gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
	CreatedAt time.Time  `json:"created_at" gorm:"default:now()"`
	UpdatedAt time.Time  `json:"updated_at" gorm:"default:now()"`
}

TODO: replace cascade constraint with trigger (issue: https://github.com/go-gorm/gorm/issues/5001)

func (*Project) BeforeDelete

func (m *Project) BeforeDelete(tx *gorm.DB) error

type ProjectInput

type ProjectInput struct {
	Name string `json:"name"`
	Repo string `json:"repo"`
}

type ProjectShort

type ProjectShort struct {
	ID        uuid.UUID `json:"id"`
	Name      string    `json:"name"`
	Repo      string    `json:"repo"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type Secret

type Secret struct {
	ID         uuid.UUID  `json:"id"             gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	Key        string     `json:"key"            gorm:"not null"`
	Path       string     `json:"path,omitempty"`
	ProjectID  *uuid.UUID `json:"project_id"     gorm:"type:uuid"`
	PipelineID *uuid.UUID `json:"pipeline_id"    gorm:"type:uuid"`
	Unique     string     `` /* 192-byte string literal not displayed */
	CreatedAt  time.Time  `json:"created_at"     gorm:"default:now()"`
	UpdatedAt  time.Time  `json:"updated_at"     gorm:"default:now()"`
}

func (*Secret) AfterCreate

func (m *Secret) AfterCreate(tx *gorm.DB) error

func (*Secret) AfterDelete

func (m *Secret) AfterDelete(tx *gorm.DB) error

func (*Secret) AfterUpdate

func (m *Secret) AfterUpdate(tx *gorm.DB) error

func (*Secret) BeforeCreate

func (m *Secret) BeforeCreate(tx *gorm.DB) error

type SecretInput

type SecretInput struct {
	Key        string     `json:"key"`
	Value      string     `json:"value"`
	Path       string     `json:"path"`
	ProjectID  *uuid.UUID `json:"project_id"`
	PipelineID *uuid.UUID `json:"pipeline_id"`
}

type User

type User struct {
	ID        uuid.UUID `json:"id"         gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	Username  string    `json:"username"   gorm:"uniqueIndex:idx_users"`
	CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
	UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
}

TODO: rbac

func (*User) BeforeDelete

func (m *User) BeforeDelete(tx *gorm.DB) error

func (*User) BeforeUpdate

func (m *User) BeforeUpdate(tx *gorm.DB) error

type UserInput

type UserInput struct {
	Username string `json:"username"`
}

type Variable

type Variable struct {
	ID         uuid.UUID  `json:"id"             gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	Key        string     `json:"key"            gorm:"not null"`
	Value      string     `json:"value"          gorm:"not null"`
	Path       string     `json:"path,omitempty"`
	ProjectID  *uuid.UUID `json:"project_id"     gorm:"type:uuid"`
	PipelineID *uuid.UUID `json:"pipeline_id"    gorm:"type:uuid"`
	Unique     string     `` /* 194-byte string literal not displayed */
	CreatedAt  time.Time  `json:"created_at"     gorm:"default:now()"`
	UpdatedAt  time.Time  `json:"updated_at"     gorm:"default:now()"`
}

func (*Variable) AfterUpdate

func (m *Variable) AfterUpdate(tx *gorm.DB) error

func (*Variable) BeforeCreate

func (m *Variable) BeforeCreate(tx *gorm.DB) error

type VariableInput

type VariableInput struct {
	Key        string     `json:"key"`
	Value      string     `json:"value"`
	Path       string     `json:"path"`
	ProjectID  *uuid.UUID `json:"project_id"`
	PipelineID *uuid.UUID `json:"pipeline_id"`
}

type Worker

type Worker struct {
	ID           uuid.UUID      `json:"id"            gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	Name         string         `json:"name"          gorm:"uniqueIndex:idx_workers;not null"`
	Address      string         `json:"address"       gorm:"not null"`
	System       string         `json:"system"        gorm:"not null"`
	Username     string         `json:"username"      gorm:"not null"`
	Type         WorkerType     `json:"type"          gorm:"not null"`
	Status       WorkerStatus   `json:"status"        gorm:"not null;default:0"`
	Strategy     WorkerStrategy `json:"strategy"      gorm:"not null;default:0"`
	ActiveBuilds int            `json:"active_builds" gorm:"not null;default:0"`
	Capacity     int            `json:"capacity"      gorm:"not null;default:0"`
	Builds       []Build        `json:"builds"        gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;not null"`
	CreatedAt    time.Time      `json:"created_at"    gorm:"default:now()"`
	UpdatedAt    time.Time      `json:"updated_at"    gorm:"default:now()"`
}

func (*Worker) AfterCreate

func (m *Worker) AfterCreate(tx *gorm.DB) error

func (*Worker) AfterDelete

func (m *Worker) AfterDelete(tx *gorm.DB) error

func (*Worker) AfterSave

func (m *Worker) AfterSave(tx *gorm.DB) error

func (*Worker) AfterUpdate

func (m *Worker) AfterUpdate(tx *gorm.DB) error

func (*Worker) BeforeCreate

func (m *Worker) BeforeCreate(tx *gorm.DB) error

func (*Worker) BeforeDelete

func (m *Worker) BeforeDelete(tx *gorm.DB) error

func (*Worker) BeforeUpdate

func (m *Worker) BeforeUpdate(tx *gorm.DB) error

type WorkerInput

type WorkerInput struct {
	Name       string     `json:"name"`
	Address    string     `json:"address"`
	System     string     `json:"system"`
	Type       WorkerType `json:"type"`
	Username   string     `json:"username"`
	PrivateKey string     `json:"private_key"`
	Capacity   int        `json:"capacity"`
}

type WorkerShort

type WorkerShort struct {
	ID           uuid.UUID      `json:"id"`
	Name         string         `json:"name"`
	Address      string         `json:"address"`
	System       string         `json:"system"`
	Username     string         `json:"username"`
	Type         WorkerType     `json:"type"`
	Status       WorkerStatus   `json:"status"`
	Strategy     WorkerStrategy `json:"strategy"`
	ActiveBuilds int            `json:"active_builds"`
	Capacity     int            `json:"capacity"`
	CreatedAt    time.Time      `json:"created_at"`
	UpdatedAt    time.Time      `json:"updated_at"`
}

type WorkerStatus

type WorkerStatus int
const (
	WorkerIdle WorkerStatus = iota
	WorkerUsed
	WorkerUnreachable
)

type WorkerStrategy

type WorkerStrategy int

type WorkerType

type WorkerType int
const (
	WorkerStatic WorkerType = iota
	WorkerDockerHost
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL