sqlite

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2021 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package sqlite implements persistent storage using the sqlite database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(path string, opts ...Option) (*gorm.DB, error)

Types

type Apply

type Apply struct {
	gorm.Model

	ExternalID string `gorm:"uniqueIndex"`

	ResourceAdditions    int
	ResourceChanges      int
	ResourceDestructions int
	Status               tfe.ApplyStatus
	StatusTimestamps     *ApplyStatusTimestamps `gorm:"embedded;embeddedPrefix:timestamp_"`

	LogsBlobID string

	// Apply belongs to a run
	RunID uint
}

Apply models a row in an applies table.

func (*Apply) FromDomain

func (model *Apply) FromDomain(domain *otf.Apply)

FromDomain updates run model fields with a run domain object's fields

func (*Apply) ToDomain

func (model *Apply) ToDomain() *otf.Apply

func (*Apply) Update

func (model *Apply) Update(fn func(*otf.Apply) error) error

Update updates the model with the supplied fn. The fn operates on the domain obj, so Update handles converting to and from a domain obj.

type ApplyList

type ApplyList []Apply

ApplyList is a list of run models

func (ApplyList) ToDomain

func (l ApplyList) ToDomain() (dl []*otf.Apply)

type ApplyStatusTimestamps

type ApplyStatusTimestamps struct {
	CanceledAt      sql.NullTime
	ErroredAt       sql.NullTime
	FinishedAt      sql.NullTime
	ForceCanceledAt sql.NullTime
	QueuedAt        sql.NullTime
	StartedAt       sql.NullTime
}

ApplyStatusTimestamps holds the timestamps for individual apply statuses.

type ConfigurationVersion

type ConfigurationVersion struct {
	gorm.Model

	ExternalID string `gorm:"uniqueIndex"`

	AutoQueueRuns    bool
	Error            string
	ErrorMessage     string
	Source           tfe.ConfigurationSource
	Speculative      bool
	Status           tfe.ConfigurationStatus
	StatusTimestamps *tfe.CVStatusTimestamps `gorm:"embedded;embeddedPrefix:timestamp_"`

	// BlobID is the ID of the binary object containing the configuration
	BlobID string

	// Configuration Version belongs to a Workspace
	WorkspaceID uint
	Workspace   *Workspace
}

ConfigurationVersion models a row in a configuration_versions table.

func (*ConfigurationVersion) FromDomain

func (model *ConfigurationVersion) FromDomain(domain *otf.ConfigurationVersion)

FromDomain updates run model fields with a run domain object's fields

func (*ConfigurationVersion) ToDomain

func (model *ConfigurationVersion) ToDomain() *otf.ConfigurationVersion

func (*ConfigurationVersion) Update

func (model *ConfigurationVersion) Update(fn func(*otf.ConfigurationVersion) error) error

Update updates the model with the supplied fn. The fn operates on the domain obj, so Update handles converting to and from a domain obj.

type ConfigurationVersionDB

type ConfigurationVersionDB struct {
	*gorm.DB
}

func NewConfigurationVersionDB

func NewConfigurationVersionDB(db *gorm.DB) *ConfigurationVersionDB

func (ConfigurationVersionDB) Create

func (ConfigurationVersionDB) Get

func (ConfigurationVersionDB) List

func (ConfigurationVersionDB) Update

Update persists an updated ConfigurationVersion to the DB. The existing run is fetched from the DB, the supplied func is invoked on the run, and the updated run is persisted back to the DB. The returned ConfigurationVersion includes any changes, including a new UpdatedAt value.

type ConfigurationVersionList

type ConfigurationVersionList []ConfigurationVersion

ConfigurationVersionList is a list of run models

func (ConfigurationVersionList) ToDomain

func (l ConfigurationVersionList) ToDomain() (dl []*otf.ConfigurationVersion)

type Option

type Option func(*gorm.Config)

func WithZeroLogger

func WithZeroLogger(logger *zerolog.Logger) Option

type Organization

type Organization struct {
	gorm.Model

	ExternalID string `gorm:"uniqueIndex"`

	Name                   string
	CollaboratorAuthPolicy tfe.AuthPolicyType
	CostEstimationEnabled  bool
	Email                  string
	OwnersTeamSAMLRoleID   string
	Permissions            *tfe.OrganizationPermissions `gorm:"embedded;embeddedPrefix:permission_"`
	SAMLEnabled            bool
	SessionRemember        int
	SessionTimeout         int
	TrialExpiresAt         time.Time
	TwoFactorConformant    bool
}

Organization models a row in a organizations table.

func (*Organization) FromDomain

func (model *Organization) FromDomain(org *otf.Organization)

FromDomain updates run model fields with a run domain object's fields

func (*Organization) ToDomain

func (model *Organization) ToDomain() *otf.Organization

func (*Organization) Update

func (model *Organization) Update(fn func(*otf.Organization) error) error

Update updates the model with the supplied fn. The fn operates on the domain obj, so Update handles converting to and from a domain obj.

type OrganizationDB

type OrganizationDB struct {
	*gorm.DB
}

func NewOrganizationDB

func NewOrganizationDB(db *gorm.DB) *OrganizationDB

func (OrganizationDB) Create

func (db OrganizationDB) Create(domain *otf.Organization) (*otf.Organization, error)

Create persists a Organization to the DB.

func (OrganizationDB) Delete

func (db OrganizationDB) Delete(name string) error

func (OrganizationDB) Get

func (db OrganizationDB) Get(name string) (*otf.Organization, error)

func (OrganizationDB) List

func (OrganizationDB) Update

func (db OrganizationDB) Update(name string, fn func(*otf.Organization) error) (*otf.Organization, error)

Update persists an updated Organization to the DB. The existing org is fetched from the DB, the supplied func is invoked on the org, and the updated org is persisted back to the DB.

type OrganizationList

type OrganizationList []Organization

OrganizationList is a list of run models

func (OrganizationList) ToDomain

func (l OrganizationList) ToDomain() (dl []*otf.Organization)

type Plan

type Plan struct {
	gorm.Model

	ExternalID string `gorm:"uniqueIndex"`

	ResourceAdditions    int
	ResourceChanges      int
	ResourceDestructions int
	Status               tfe.PlanStatus
	StatusTimestamps     *PlanStatusTimestamps `gorm:"embedded;embeddedPrefix:timestamp_"`

	// The blob ID of the logs
	LogsBlobID string

	// The blob ID of the execution plan file
	PlanFileBlobID string

	// The blob ID of the execution plan file in json format
	PlanJSONBlobID string

	// Plan belongs to a run
	RunID uint
}

Plan models a row in a runs table.

func (*Plan) FromDomain

func (model *Plan) FromDomain(domain *otf.Plan)

FromDomain updates run model fields with a run domain object's fields

func (*Plan) ToDomain

func (model *Plan) ToDomain() *otf.Plan

func (*Plan) Update

func (model *Plan) Update(fn func(*otf.Plan) error) error

Update updates the model with the supplied fn. The fn operates on the domain obj, so Update handles converting to and from a domain obj.

type PlanList

type PlanList []Plan

PlanList is a list of run models

func (PlanList) ToDomain

func (l PlanList) ToDomain() (dl []*otf.Plan)

type PlanStatusTimestamps

type PlanStatusTimestamps struct {
	CanceledAt      sql.NullTime
	ErroredAt       sql.NullTime
	FinishedAt      sql.NullTime
	ForceCanceledAt sql.NullTime
	QueuedAt        sql.NullTime
	StartedAt       sql.NullTime
}

PlanStatusTimestamps holds the timestamps for individual plan statuses.

type Run

type Run struct {
	gorm.Model

	ExternalID string `gorm:"uniqueIndex"`

	ForceCancelAvailableAt time.Time
	IsDestroy              bool
	Message                string
	Permissions            *tfe.RunPermissions `gorm:"embedded;embeddedPrefix:permission_"`
	PositionInQueue        int
	Refresh                bool
	RefreshOnly            bool
	Status                 tfe.RunStatus
	StatusTimestamps       *RunStatusTimestamps `gorm:"embedded;embeddedPrefix:timestamp_"`

	// Comma separated list of replace addresses
	ReplaceAddrs string
	// Comma separated list of target addresses
	TargetAddrs string

	// Run has one plan
	Plan *Plan

	// Run has one apply
	Apply *Apply

	// Run belongs to a workspace
	WorkspaceID uint
	Workspace   *Workspace

	// Run belongs to a configuration version
	ConfigurationVersionID uint
	ConfigurationVersion   *ConfigurationVersion
}

Run models a row in a runs table.

func NewFromDomain

func NewFromDomain(domain *otf.Run) *Run

NewFromDomain constructs a model obj from a domain obj

func (*Run) FromDomain

func (model *Run) FromDomain(domain *otf.Run)

FromDomain updates run model fields with a run domain object's fields

func (*Run) ToDomain

func (model *Run) ToDomain() *otf.Run

func (*Run) Update

func (model *Run) Update(fn func(*otf.Run) error) error

Update updates the model with the supplied fn. The fn operates on the domain obj, so Update handles converting to and from a domain obj.

type RunDB

type RunDB struct {
	*gorm.DB
}

func NewRunDB

func NewRunDB(db *gorm.DB) *RunDB

func (RunDB) Create

func (db RunDB) Create(domain *otf.Run) (*otf.Run, error)

Create persists a Run to the DB.

func (RunDB) Get

func (db RunDB) Get(opts otf.RunGetOptions) (*otf.Run, error)

Get retrieves a Run domain obj

func (RunDB) List

func (db RunDB) List(opts otf.RunListOptions) (*otf.RunList, error)

func (RunDB) Update

func (db RunDB) Update(id string, fn func(*otf.Run) error) (*otf.Run, error)

Update persists an updated Run to the DB. The existing run is fetched from the DB, the supplied func is invoked on the run, and the updated run is persisted back to the DB. The returned Run includes any changes, including a new UpdatedAt value.

type RunList

type RunList []Run

RunList is a list of run models

func (RunList) ToDomain

func (l RunList) ToDomain() (dl []*otf.Run)

type RunStatusTimestamps

type RunStatusTimestamps struct {
	AppliedAt            sql.NullTime
	ApplyQueuedAt        sql.NullTime
	ApplyingAt           sql.NullTime
	CanceledAt           sql.NullTime
	ConfirmedAt          sql.NullTime
	CostEstimatedAt      sql.NullTime
	CostEstimatingAt     sql.NullTime
	DiscardedAt          sql.NullTime
	ErroredAt            sql.NullTime
	ForceCanceledAt      sql.NullTime
	PlanQueueableAt      sql.NullTime
	PlanQueuedAt         sql.NullTime
	PlannedAndFinishedAt sql.NullTime
	PlannedAt            sql.NullTime
	PlanningAt           sql.NullTime
	PolicyCheckedAt      sql.NullTime
	PolicySoftFailedAt   sql.NullTime
}

type StateVersion

type StateVersion struct {
	gorm.Model

	ExternalID string `gorm:"uniqueIndex"`

	Serial       int64
	VCSCommitSHA string
	VCSCommitURL string

	BlobID string

	// State version belongs to a workspace
	WorkspaceID uint
	Workspace   *Workspace

	// StateVersion has many StateVersionOutput
	Outputs []*StateVersionOutput
}

StateVersion models a row in a state versions table.

func (*StateVersion) FromDomain

func (model *StateVersion) FromDomain(domain *otf.StateVersion)

FromDomain updates state version model fields with a state version domain object's fields

func (*StateVersion) ToDomain

func (model *StateVersion) ToDomain() *otf.StateVersion

type StateVersionList

type StateVersionList []StateVersion

func (StateVersionList) ToDomain

func (l StateVersionList) ToDomain() (dl []*otf.StateVersion)

type StateVersionOutput

type StateVersionOutput struct {
	gorm.Model

	ExternalID string `gorm:"uniqueIndex"`

	Name      string
	Sensitive bool
	Type      string
	Value     string

	// StateVersionOutput belongs to State Version
	StateVersionID uint
}

StateVersionOutput models a row in a state versions table.

func NewStateVersionOutputFromDomain

func NewStateVersionOutputFromDomain(domain *otf.StateVersionOutput) *StateVersionOutput

NewStateVersionOutputFromDomain constructs a model obj from a domain obj

func (*StateVersionOutput) ToDomain

func (model *StateVersionOutput) ToDomain() *otf.StateVersionOutput

type StateVersionOutputList

type StateVersionOutputList []StateVersionOutput

StateVersionOutputList is a list of run models

func (StateVersionOutputList) ToDomain

func (l StateVersionOutputList) ToDomain() (dl []*otf.StateVersionOutput)

type StateVersionService

type StateVersionService struct {
	*gorm.DB
}

func NewStateVersionDB

func NewStateVersionDB(db *gorm.DB) *StateVersionService

func (StateVersionService) Create

Create persists a StateVersion to the DB.

func (StateVersionService) Get

func (StateVersionService) List

type Workspace

type Workspace struct {
	gorm.Model

	ExternalID string `gorm:"uniqueIndex"`

	AllowDestroyPlan           bool
	AutoApply                  bool
	CanQueueDestroyPlan        bool
	Description                string
	Environment                string
	ExecutionMode              string
	FileTriggersEnabled        bool
	GlobalRemoteState          bool
	Locked                     bool
	MigrationEnvironment       string
	Name                       string
	Permissions                *tfe.WorkspacePermissions `gorm:"embedded;embeddedPrefix:permission_"`
	QueueAllRuns               bool
	SpeculativeEnabled         bool
	SourceName                 string
	SourceURL                  string
	StructuredRunOutputEnabled bool
	TerraformVersion           string
	TriggerPrefixes            string
	VCSRepo                    *tfe.VCSRepo `gorm:"-"`
	WorkingDirectory           string
	ResourceCount              int
	ApplyDurationAverage       time.Duration
	PlanDurationAverage        time.Duration
	PolicyCheckFailures        int
	RunFailures                int
	RunsCount                  int

	OrganizationID uint
	Organization   *Organization
}

Workspace models a row in a runs table.

func (*Workspace) FromDomain

func (model *Workspace) FromDomain(domain *otf.Workspace)

FromDomain updates workspace model fields with a workspace domain object's fields

func (*Workspace) ToDomain

func (model *Workspace) ToDomain() *otf.Workspace

func (*Workspace) Update

func (model *Workspace) Update(fn func(*otf.Workspace) error) error

Update updates the model with the supplied fn. The fn operates on the domain obj, so Update handles converting to and from a domain obj.

type WorkspaceDB

type WorkspaceDB struct {
	*gorm.DB
}

func NewWorkspaceDB

func NewWorkspaceDB(db *gorm.DB) *WorkspaceDB

func (WorkspaceDB) Create

func (db WorkspaceDB) Create(domain *otf.Workspace) (*otf.Workspace, error)

Create persists a Workspace to the DB. The returned Workspace is adorned with additional metadata, i.e. CreatedAt, UpdatedAt, etc.

func (WorkspaceDB) Delete

func (db WorkspaceDB) Delete(spec otf.WorkspaceSpecifier) error

Delete deletes a specific workspace, along with its associated records (runs etc).

func (WorkspaceDB) Get

func (WorkspaceDB) List

func (WorkspaceDB) Update

func (db WorkspaceDB) Update(spec otf.WorkspaceSpecifier, fn func(*otf.Workspace) error) (*otf.Workspace, error)

Update persists an updated Workspace to the DB. The existing run is fetched from the DB, the supplied func is invoked on the run, and the updated run is persisted back to the DB. The returned Workspace includes any changes, including a new UpdatedAt value.

type WorkspaceList

type WorkspaceList []Workspace

WorkspaceList is a list of run models

func (WorkspaceList) ToDomain

func (l WorkspaceList) ToDomain() (dl []*otf.Workspace)

Jump to

Keyboard shortcuts

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