postgres

package
v0.5.9 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package postgres implementation relies on gorm for queries which is very very inefficient at the moment, we are trading convenience with performance for example in lot of select stmts, we pull all related relations as well even when we don't really need to, most of the times these relation queries even in update gets executed for no reason even if user didn't intend to update them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(dbConf config.DBConfig, writer io.Writer) (*gorm.DB, error)

Connect connect to the DB with custom configuration.

func InitTrace

func InitTrace(db *gorm.DB) error

func NewBackupRepository

func NewBackupRepository(db *gorm.DB) *backupRepository

func NewJobDeploymentRepository

func NewJobDeploymentRepository(db *gorm.DB) *jobDeploymentRepository

func NewJobSourceRepository

func NewJobSourceRepository(db *gorm.DB) store.JobSourceRepository

func NewJobSpecRepository

func NewJobSpecRepository(db *gorm.DB, adapter *JobSpecAdapter) (store.JobSpecRepository, error)

NewJobSpecRepository initializes job spec repository

func NewMigration

func NewMigration(logger log.Logger, incomingOptimusVersion, dbConnURL string) (store.Migration, error)

NewMigration initializes migration mechanism specific for postgres

func NewNamespaceRepository

func NewNamespaceRepository(db *gorm.DB, hash models.ApplicationKey) *namespaceRepository

func NewProjectResourceSpecRepository

func NewProjectResourceSpecRepository(db *gorm.DB, project models.ProjectSpec, ds models.Datastorer) *projectResourceSpecRepository

func NewReplayRepository

func NewReplayRepository(db *gorm.DB, jobAdapter *JobSpecAdapter) *replayRepository

func NewResourceSpecRepository

func NewResourceSpecRepository(db *gorm.DB, namespace models.NamespaceSpec, ds models.Datastorer, projectResourceSpecRepo store.ProjectResourceSpecRepository) *resourceSpecRepository

func NewSecretRepository

func NewSecretRepository(db *gorm.DB, hash models.ApplicationKey) *secretRepository

Types

type Backup

type Backup struct {
	ID uuid.UUID `gorm:"primary_key;type:uuid;default:uuid_generate_v4()"`

	ResourceID uuid.UUID
	Resource   Resource `gorm:"foreignKey:ResourceID"`

	Spec datatypes.JSON

	CreatedAt time.Time `gorm:"not null" json:"created_at"`
	UpdatedAt time.Time `gorm:"not null" json:"updated_at"`
}

func (Backup) FromSpec

func (Backup) FromSpec(backupSpec models.BackupSpec) (Backup, error)

func (Backup) ToSpec

func (b Backup) ToSpec(ds models.Datastorer) (models.BackupSpec, error)

type BackupDetail

type BackupDetail struct {
	Result      map[string]interface{}
	Description string
	Config      map[string]string
}

type ExecutionTree

type ExecutionTree struct {
	JobSpec    Job
	Dependents []*ExecutionTree
	Runs       []time.Time
}

type HookRun

type HookRun struct {
	HookRunID uuid.UUID `gorm:"primary_key;type:uuid;default:uuid_generate_v4()"`

	JobRunID uuid.UUID

	StartTime time.Time `gorm:"not null"`
	EndTime   time.Time

	Status        string
	Attempt       int
	JobRunAttempt int
	Duration      int64

	CreatedAt time.Time `gorm:"not null" json:"created_at"`
	UpdatedAt time.Time `gorm:"not null" json:"updated_at"`
}

type HookRunRepository

type HookRunRepository struct {
	// contains filtered or unexported fields
}

func NewHookRunRepository

func NewHookRunRepository(db *gorm.DB) *HookRunRepository

func (*HookRunRepository) GetHookRun

func (repo *HookRunRepository) GetHookRun(ctx context.Context, jobRunSpec models.JobRunSpec) (models.HookRunSpec, error)

func (*HookRunRepository) Save

func (repo *HookRunRepository) Save(ctx context.Context, event models.JobEvent, jobRunSpec models.JobRunSpec) error

func (*HookRunRepository) Update

func (repo *HookRunRepository) Update(ctx context.Context, event models.JobEvent, jobRunSpec models.JobRunSpec) error

type Job

type Job struct {
	ID           uuid.UUID `gorm:"primary_key;type:uuid;default:uuid_generate_v4()"`
	Version      int
	Name         string `gorm:"not null" json:"name"`
	Owner        string
	Description  string
	Labels       datatypes.JSON
	StartDate    time.Time
	EndDate      *time.Time
	Interval     *string
	Destination  string
	Dependencies datatypes.JSON
	Behavior     datatypes.JSON

	ProjectID uuid.UUID
	Project   Project `gorm:"foreignKey:ProjectID"`

	NamespaceID uuid.UUID
	Namespace   Namespace `gorm:"foreignKey:NamespaceID"`

	TaskName   string
	TaskConfig datatypes.JSON

	WindowSize       string
	WindowOffset     string
	WindowTruncateTo string

	Assets               datatypes.JSON
	Hooks                datatypes.JSON
	Metadata             datatypes.JSON
	ExternalDependencies datatypes.JSON // store external dependencies

	CreatedAt time.Time `gorm:"not null" json:"created_at"`
	UpdatedAt time.Time `gorm:"not null" json:"updated_at"`
	DeletedAt gorm.DeletedAt

	// Deprecated: do not use it unless WindowSize is empty
	OldWindowSize *int64 // duration in nanos
	// Deprecated: do not use it unless WindowOffset is empty
	OldWindowOffset *int64
}

Job are inputs from user to create a job postgres representation of the job

type JobAsset

type JobAsset struct {
	Name  string
	Value string
}

func (JobAsset) FromSpec

func (JobAsset) FromSpec(spec models.JobSpecAsset) JobAsset

func (JobAsset) ToSpec

func (a JobAsset) ToSpec() models.JobSpecAsset

type JobBehavior

type JobBehavior struct {
	DependsOnPast bool
	CatchUp       bool
	Retry         JobBehaviorRetry
	Notify        []JobBehaviorNotifier
}

type JobBehaviorNotifier

type JobBehaviorNotifier struct {
	On       string
	Config   map[string]string
	Channels []string
}

type JobBehaviorRetry

type JobBehaviorRetry struct {
	Count              int
	Delay              int64
	ExponentialBackoff bool
}

type JobDeployment

type JobDeployment struct {
	ID        uuid.UUID `gorm:"not null" json:"id"`
	ProjectID uuid.UUID `gorm:"not null" json:"project_id"`
	Project   Project   `gorm:"foreignKey:ProjectID"`

	Status  string `gorm:"not null;default:null"`
	Details datatypes.JSON

	CreatedAt time.Time `gorm:"not null" json:"created_at"`
	UpdatedAt time.Time `gorm:"not null" json:"updated_at"`
}

func (JobDeployment) FromSpec

func (JobDeployment) FromSpec(deployment models.JobDeployment) (JobDeployment, error)

func (JobDeployment) ToSpec

func (d JobDeployment) ToSpec() (models.JobDeployment, error)

type JobHook

type JobHook struct {
	Name   string
	Config datatypes.JSON
}

func (JobHook) FromSpec

func (JobHook) FromSpec(spec models.JobSpecHook) (JobHook, error)

func (JobHook) ToSpec

func (a JobHook) ToSpec(pluginRepo models.PluginRepository) (models.JobSpecHook, error)

ToSpec converts the postgres' JobHook representation to the optimus' models.JobSpecHook

type JobRunMetrics

type JobRunMetrics struct {
	JobRunID uuid.UUID `gorm:"primary_key;type:uuid;default:uuid_generate_v4()"`

	JobID uuid.UUID

	NamespaceID uuid.UUID

	ProjectID uuid.UUID

	ScheduledAt time.Time `gorm:"not null"`

	StartTime time.Time `gorm:"not null"`
	EndTime   time.Time

	Status        string
	Attempt       int
	SLAMissDelay  int
	Duration      int64
	SLADefinition int64

	CreatedAt time.Time `gorm:"not null" json:"created_at"`
	UpdatedAt time.Time `gorm:"not null" json:"updated_at"`
}

func (JobRunMetrics) TableName

func (JobRunMetrics) TableName() string

TableName overrides the table name used by User to `profiles`

type JobRunMetricsRepository

type JobRunMetricsRepository struct {
	// contains filtered or unexported fields
}

func NewJobRunMetricsRepository

func NewJobRunMetricsRepository(db *gorm.DB) *JobRunMetricsRepository

func (*JobRunMetricsRepository) Get

func (*JobRunMetricsRepository) GetByID

func (repo *JobRunMetricsRepository) GetByID(ctx context.Context, jobRunID uuid.UUID, jobSpec models.JobSpec) (models.JobRunSpec, error)

func (*JobRunMetricsRepository) GetLatestJobRunByScheduledTime

func (repo *JobRunMetricsRepository) GetLatestJobRunByScheduledTime(ctx context.Context, scheduledAt string, namespaceSpec models.NamespaceSpec, jobSpec models.JobSpec) (models.JobRunSpec, error)

GetLatestJobRunByScheduledTime get the latest jobRun instance for a given schedule time

func (*JobRunMetricsRepository) Save

func (repo *JobRunMetricsRepository) Save(ctx context.Context, event models.JobEvent, namespaceSpec models.NamespaceSpec, jobSpec models.JobSpec, slaMissDurationInSec int64) error

func (*JobRunMetricsRepository) Update

func (repo *JobRunMetricsRepository) Update(ctx context.Context, event models.JobEvent, namespaceSpec models.NamespaceSpec, jobSpec models.JobSpec) error

type JobSource

type JobSource struct {
	JobID     uuid.UUID `gorm:"not null" json:"job_id"`
	ProjectID uuid.UUID `gorm:"not null" json:"project_id"`

	ResourceURN string `gorm:"not null" json:"resource_urn"`

	CreatedAt time.Time `gorm:"not null" json:"created_at"`
}

type JobSpecAdapter

type JobSpecAdapter struct {
	// contains filtered or unexported fields
}

func NewAdapter

func NewAdapter(pluginRepo models.PluginRepository) *JobSpecAdapter

func (JobSpecAdapter) FromJobSpec

func (JobSpecAdapter) FromJobSpec(spec models.JobSpec, resourceDestination string) (Job, error)

FromJobSpec converts the optimus representation of JobSpec to postgres' Job

func (JobSpecAdapter) ToSpec

func (adapt JobSpecAdapter) ToSpec(conf Job) (models.JobSpec, error)

ToSpec converts the postgres' Job representation to the optimus' JobSpec

type Namespace

type Namespace struct {
	ID     uuid.UUID `gorm:"primary_key;type:uuid;default:uuid_generate_v4()"`
	Name   string    `gorm:"not null;unique"`
	Config datatypes.JSON

	ProjectID uuid.UUID
	Project   Project `gorm:"foreignKey:ProjectID"`

	CreatedAt time.Time `gorm:"not null" json:"created_at"`
	UpdatedAt time.Time `gorm:"not null" json:"updated_at"`
	DeletedAt gorm.DeletedAt
}

func (Namespace) FromSpec

func (Namespace) FromSpec(spec models.NamespaceSpec) Namespace

func (Namespace) FromSpecWithProject

func (p Namespace) FromSpecWithProject(spec models.NamespaceSpec, proj models.ProjectSpec) Namespace

func (Namespace) ToSpec

func (p Namespace) ToSpec(project models.ProjectSpec) (models.NamespaceSpec, error)

func (Namespace) ToSpecWithProjectSecrets

func (p Namespace) ToSpecWithProjectSecrets(hash models.ApplicationKey) (models.NamespaceSpec, error)

type Project

type Project struct {
	ID     uuid.UUID `gorm:"primary_key;type:uuid;default:uuid_generate_v4()"`
	Name   string    `gorm:"not null;unique"`
	Config datatypes.JSON

	// Secrets are read only and will not be saved by updating it here
	Secrets []Secret

	CreatedAt time.Time `gorm:"not null" json:"created_at"`
	UpdatedAt time.Time `gorm:"not null" json:"updated_at"`
	DeletedAt gorm.DeletedAt
}

func (Project) FromSpec

func (Project) FromSpec(spec models.ProjectSpec) Project

func (Project) ToSpec

func (p Project) ToSpec() models.ProjectSpec

func (Project) ToSpecWithSecrets

func (p Project) ToSpecWithSecrets(h models.ApplicationKey) (models.ProjectSpec, error)

type ProjectRepository

type ProjectRepository struct {
	// contains filtered or unexported fields
}

func NewProjectRepository

func NewProjectRepository(db *gorm.DB, hash models.ApplicationKey) *ProjectRepository

func (*ProjectRepository) GetAll

func (repo *ProjectRepository) GetAll(ctx context.Context) ([]models.ProjectSpec, error)

func (*ProjectRepository) GetByName

func (repo *ProjectRepository) GetByName(ctx context.Context, name string) (models.ProjectSpec, error)

func (*ProjectRepository) Insert

func (repo *ProjectRepository) Insert(ctx context.Context, resource models.ProjectSpec) error

func (*ProjectRepository) Save

func (repo *ProjectRepository) Save(ctx context.Context, spec models.ProjectSpec) error

type Replay

type Replay struct {
	ID uuid.UUID `gorm:"primary_key;type:uuid;default:uuid_generate_v4()"`

	JobID uuid.UUID `gorm:"not null"`
	Job   Job       `gorm:"foreignKey:JobID"`

	StartDate     time.Time `gorm:"not null"`
	EndDate       time.Time `gorm:"not null"`
	Status        string    `gorm:"not null"`
	Message       datatypes.JSON
	ExecutionTree datatypes.JSON
	Config        datatypes.JSON

	CreatedAt time.Time `gorm:"not null" json:"created_at"`
	UpdatedAt time.Time `gorm:"not null" json:"updated_at"`
}

func (Replay) FromSpec

func (Replay) FromSpec(spec *models.ReplaySpec) (Replay, error)

func (Replay) ToSpec

func (p Replay) ToSpec(jobSpec models.JobSpec) (models.ReplaySpec, error)

type Resource

type Resource struct {
	ID uuid.UUID `gorm:"primary_key;type:uuid;default:uuid_generate_v4()"`

	ProjectID uuid.UUID
	Project   Project `gorm:"foreignKey:ProjectID"`

	NamespaceID uuid.UUID
	Namespace   Namespace `gorm:"foreignKey:NamespaceID"`

	Version   int
	Name      string `gorm:"not null"`
	Type      string `gorm:"not null"`
	Datastore string `gorm:"not null"`
	URN       string `gorm:"not null"`

	Spec   []byte
	Assets datatypes.JSON
	Labels datatypes.JSON

	CreatedAt time.Time `gorm:"not null" json:"created_at"`
	UpdatedAt time.Time `gorm:"not null" json:"updated_at"`
	DeletedAt gorm.DeletedAt
}

func (Resource) FromSpec

func (Resource) FromSpec(resourceSpec models.ResourceSpec) (Resource, error)

func (Resource) FromSpecWithNamespace

func (r Resource) FromSpecWithNamespace(resourceSpec models.ResourceSpec, namespace models.NamespaceSpec) (Resource, error)

func (Resource) ToSpec

type Secret

type Secret struct {
	ID        uuid.UUID `gorm:"primary_key;type:uuid;default:uuid_generate_v4()"`
	ProjectID uuid.UUID
	Project   Project `gorm:"foreignKey:ProjectID"`

	NamespaceID uuid.UUID `gorm:"default:null"`
	Namespace   Namespace `gorm:"foreignKey:NamespaceID"`

	Name  string `gorm:"not null;default:null"`
	Value string

	Type string

	CreatedAt time.Time `gorm:"not null" json:"created_at"`
	UpdatedAt time.Time `gorm:"not null" json:"updated_at"`
	DeletedAt gorm.DeletedAt
}

func (Secret) FromSpec

func (Secret) ToSecretItemInfo

func (p Secret) ToSecretItemInfo() (models.SecretItemInfo, error)

func (Secret) ToSpec

ToSpec TODO: move decryption of secret to service

type SensorRun

type SensorRun struct {
	SensorRunID uuid.UUID `gorm:"primary_key;type:uuid;default:uuid_generate_v4()"`

	JobRunID uuid.UUID

	StartTime time.Time `gorm:"not null"`
	EndTime   time.Time

	Status        string
	Attempt       int
	JobRunAttempt int
	Duration      int64

	CreatedAt time.Time `gorm:"not null" json:"created_at"`
	UpdatedAt time.Time `gorm:"not null" json:"updated_at"`
}

type SensorRunRepository

type SensorRunRepository struct {
	// contains filtered or unexported fields
}

func NewSensorRunRepository

func NewSensorRunRepository(db *gorm.DB) *SensorRunRepository

func (*SensorRunRepository) GetSensorRun

func (repo *SensorRunRepository) GetSensorRun(ctx context.Context, jobRunSpec models.JobRunSpec) (models.SensorRunSpec, error)

func (*SensorRunRepository) Save

func (repo *SensorRunRepository) Save(ctx context.Context, event models.JobEvent, jobRunSpec models.JobRunSpec) error

func (*SensorRunRepository) Update

func (repo *SensorRunRepository) Update(ctx context.Context, event models.JobEvent, jobRunSpec models.JobRunSpec) error

type TaskRun

type TaskRun struct {
	TaskRunID uuid.UUID `gorm:"primary_key;type:uuid;default:uuid_generate_v4()"`

	JobRunID uuid.UUID

	StartTime time.Time `gorm:"not null"`
	EndTime   time.Time

	Status        string
	Attempt       int
	JobRunAttempt int
	Duration      int64

	CreatedAt time.Time `gorm:"not null" json:"created_at"`
	UpdatedAt time.Time `gorm:"not null" json:"updated_at"`
}

type TaskRunRepository

type TaskRunRepository struct {
	// contains filtered or unexported fields
}

func NewTaskRunRepository

func NewTaskRunRepository(db *gorm.DB) *TaskRunRepository

func (*TaskRunRepository) GetTaskRun

func (repo *TaskRunRepository) GetTaskRun(ctx context.Context, jobRunSpec models.JobRunSpec) (models.TaskRunSpec, error)

func (*TaskRunRepository) Save

func (repo *TaskRunRepository) Save(ctx context.Context, event models.JobEvent, jobRunSpec models.JobRunSpec) error

func (*TaskRunRepository) Update

func (repo *TaskRunRepository) Update(ctx context.Context, event models.JobEvent, jobRunSpec models.JobRunSpec) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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