db

package
v0.0.0-...-7b190fc Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 14 Imported by: 12

README

Database

ER Diagram

erDiagram
    "tf_provider" {
        string id PK
        string name
    }
    "tf_resource_types" {
        string id PK
        string provider_id FK
        string resource_type
        string taxonomy_id
    }
    "tf_resource_attributes" {
        string id PK
        string resource_type_id FK
        string provider_id FK
        string attribute_path
        string data_type
        string description
        bool optional
        bool computed
    }
    "tf_resource_attributes_mappings" {
        string id PK
        string input_attribute_id FK
        string output_attribute_id FK
    }
    "tf_modules" {
        string id PK
        string taxonomy_id FK
        string module_name
        string source
        string description
    }
    "tf_module_attributes" {
        string id PK
        string module_id FK
        string module_attribute_name
        string description
        string related_resource_type_attribute_id FK
        bool optional
        bool computed
    }
    "taxonomies" {
        string taxonomy_id PK
        string taxonomy_level_1
        string taxonomy_level_2
        string taxonomy_level_3
    }
    "dependencies" {
        string id PK
        string taxonomy_id FK
        string interface_id
        string title
        string description
        json inputs
        json outputs
    }
    "platforms" {
        string id PK
        string title
        string description
        string repo_url
        string repo_directory
        string commit_sha
        string ref_label
        enum label_type
    }
    "platform_component" {
        string id PK
        string platform_id FK
        string dependency_id FK
    }

    %% Define relationships
    "tf_resource_types" ||--o{ "tf_resource_attributes" : contains
    "tf_resource_attributes" ||--|{ "tf_resource_attributes_mappings" : input
    "tf_resource_attributes" ||--|{ "tf_resource_attributes_mappings" : output
    "tf_modules" ||--o{ "tf_module_attributes" : contains
    "tf_module_attributes" }|--|| "tf_resource_attributes" : related_resource_type_attribute_id
    "taxonomies" ||--|{ "tf_resource_types" : has
    "tf_provider" ||--|{ "tf_resource_types" : has
    "dependencies" ||--|{ "taxonomies" : has
    "dependencies" ||--|{ "platform_component" : implemented_in
    "platforms" ||--|{ "platform_component" : has

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NoOpFilter

func NoOpFilter(g *gorm.DB) *gorm.DB

Types

type DB

type DB interface {
	CreateTFProvider(e *TFProvider) (uuid.UUID, error)
	CreateTFResourceType(e *TFResourceType) (uuid.UUID, error)
	CreateTFResourceAttribute(e *TFResourceAttribute) (uuid.UUID, error)
	CreateTFResourceAttributesMapping(e *TFResourceAttributesMapping) (uuid.UUID, error)
	CreateTFModule(e *TFModule) (uuid.UUID, error)
	CreateTFModuleAttribute(e *TFModuleAttribute) (uuid.UUID, error)
	CreateTaxonomy(e *Taxonomy) (uuid.UUID, error)
	CreateDependencyInterface(e *Dependency) (uuid.UUID, error)
	CreateDependencyAttribute(e *DependencyAttribute) (uuid.UUID, error)
	CreatePlatform(p *Platform) (uuid.UUID, error)
	CreatePlatformComponents(p *PlatformComponent) (uuid.UUID, error)

	// GetOrCreateTFProvider finds and updates `e` and if the record doesn't exists, it creates a new record `e` and updates ID.
	GetOrCreateTFProvider(e *TFProvider) (id uuid.UUID, isNew bool, err error)

	GetTFProvider(e *TFProvider, where *TFProvider) error
	GetTFResourceType(e *TFResourceType, where *TFResourceType) error
	GetTFResourceAttribute(e *TFResourceAttribute, where *TFResourceAttribute) error

	// QueryTFModules list terraform modules
	QueryTFModules(filterOps ...FilterOption) (result TFModules, err error)
	// QueryTFModuleAttributes list terraform module attributes
	QueryTFModuleAttributes(filterOps ...FilterOption) (result TFModuleAttributes, err error)

	QueryDependencies(filterOps ...FilterOption) (result Dependencies, err error)
	QueryTaxonomies(filterOps ...FilterOption) (result Taxonomies, err error)
	QueryPlatforms(filterOps ...FilterOption) (result Platforms, err error)
	QueryPlatformComponents(filterOps ...FilterOption) (result PlatformComponents, err error)

	Fetchdeps() []DependencyResult
	ExecuteSQLStatement(statement string) error

	CreateRelease(e *FarmRelease) (uuid.UUID, error)
	FindReleaseByRepo(e *FarmRelease, repo string) error
}

func AutoMigrate

func AutoMigrate(db *gorm.DB) (DB, error)

type Dependencies

type Dependencies []Dependency

func (Dependencies) ToProto

func (depArr Dependencies) ToProto() []*terrariumpb.Dependency

type Dependency

type Dependency struct {
	Model

	TaxonomyID  *uuid.UUID `gorm:"default:null"` // Given taxonomy's uncertain presence in YAML, setting TaxonomyID default as NULL accommodates potential absence of taxonomy data.
	InterfaceID string     `gorm:"unique"`
	Title       string     `gorm:"default:null"`
	Description string     `gorm:"default:null"`
	ExtendsID   string     `gorm:"-"` //This is yet to be finalized

	Attributes DependencyAttributes `gorm:"foreignKey:DependencyID"`
	Taxonomy   *Taxonomy            `gorm:"foreignKey:TaxonomyID"`
}

func (Dependency) GetInputs

func (d Dependency) GetInputs() *jsonschema.Node

func (Dependency) GetOutputs

func (d Dependency) GetOutputs() *jsonschema.Node

func (Dependency) ToProto

func (d Dependency) ToProto() *terrariumpb.Dependency

type DependencyAttribute

type DependencyAttribute struct {
	Model

	DependencyID uuid.UUID        `gorm:"uniqueIndex:dependency_attribute_unique"`
	Name         string           `gorm:"uniqueIndex:dependency_attribute_unique"`
	Schema       *jsonschema.Node `gorm:"type:jsonb"`
	Computed     bool             `gorm:"uniqueIndex:dependency_attribute_unique"` // true means output, false means input

	Dependency *Dependency `gorm:"foreignKey:DependencyID"`
}

func (DependencyAttribute) ToProto

type DependencyAttributeMappings

type DependencyAttributeMappings struct {
	Model

	DependencyAttributeID uuid.UUID `gorm:"uniqueIndex:dependency_attribute_mapping_unique"`
	ResourceAttributeID   uuid.UUID `gorm:"uniqueIndex:dependency_attribute_mapping_unique"`
}

type DependencyAttributes

type DependencyAttributes []DependencyAttribute

func (DependencyAttributes) GetByCompute

func (dbAttrs DependencyAttributes) GetByCompute(wantComputed bool) DependencyAttributes

func (DependencyAttributes) ToJSONSchema

func (dbAttrs DependencyAttributes) ToJSONSchema() *jsonschema.Node

func (DependencyAttributes) ToProto

type DependencyResult

type DependencyResult struct {
	DependencyID uuid.UUID
	InterfaceID  string
	Name         string
	Schema       *jsonschema.Node
	Computed     bool
}

type FarmRelease

type FarmRelease struct {
	Model
	Tag  string
	Repo string `gorm:"unique"`
}

type FilterOption

type FilterOption func(*gorm.DB) *gorm.DB

func ComponentRequestToFilters

func ComponentRequestToFilters(req *terrariumpb.ListComponentsRequest) []FilterOption

func ComponentsFilterByDependencySearch

func ComponentsFilterByDependencySearch(query string) FilterOption

func ComponentsFilterByPlatformID

func ComponentsFilterByPlatformID(ids ...string) FilterOption

func ComponentsFilterByTaxonomy

func ComponentsFilterByTaxonomy(tax *Taxonomy) FilterOption

func DependencyFilterByTaxonomy

func DependencyFilterByTaxonomy(tax *Taxonomy) FilterOption

func DependencyRequestToFilters

func DependencyRequestToFilters(req *terrariumpb.ListDependenciesRequest) []FilterOption

func DependencySearchFilter

func DependencySearchFilter(query string) FilterOption

func ModuleAttrByIDsFilter

func ModuleAttrByIDsFilter(moduleId uuid.UUID, ids ...uuid.UUID) FilterOption

func ModuleAttrSearchFilter

func ModuleAttrSearchFilter(query string) FilterOption

func ModuleByIDsFilter

func ModuleByIDsFilter(ids ...uuid.UUID) FilterOption

func ModuleNamespaceFilter

func ModuleNamespaceFilter(namespace []string) FilterOption

func ModuleSearchFilter

func ModuleSearchFilter(query string) FilterOption

func PaginateGlobalFilter

func PaginateGlobalFilter(pageSize, pageIndex int32, totalPages *int32) FilterOption

func PlatformFilterByDependencyID

func PlatformFilterByDependencyID(depIDs ...string) FilterOption

func PlatformFilterBySearch

func PlatformFilterBySearch(query string) FilterOption

PlatformFilterBySearch perform search on name & repo columns

func PlatformFilterByTaxonomy

func PlatformFilterByTaxonomy(tax *Taxonomy) FilterOption

func PlatformRequestToFilters

func PlatformRequestToFilters(req *terrpb.ListPlatformsRequest) []FilterOption

func PopulateModuleAttrMappingsFilter

func PopulateModuleAttrMappingsFilter(enable bool) FilterOption

func PopulateModuleMappingsFilter

func PopulateModuleMappingsFilter(enable bool) FilterOption

func TaxonomyByLevelsFilter

func TaxonomyByLevelsFilter(t *Taxonomy) FilterOption

func TaxonomyRequestToFilters

func TaxonomyRequestToFilters(req *terrariumpb.ListTaxonomyRequest) []FilterOption

type Model

type Model struct {
	ID        uuid.UUID `gorm:"type:uuid;primarykey"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

Model a basic GoLang struct which includes the following fields: ID, CreatedAt, UpdatedAt, DeletedAt

func (*Model) GenerateID

func (m *Model) GenerateID()

func (*Model) GetID

func (m *Model) GetID() uuid.UUID

func (*Model) SetID

func (m *Model) SetID(id uuid.UUID)

type Platform

type Platform struct {
	Model

	Title         string
	Description   string
	RepoURL       string              `gorm:"uniqueIndex:platform_ref_unique"`
	RepoDirectory string              `gorm:"uniqueIndex:platform_ref_unique"`
	CommitSHA     string              `gorm:"uniqueIndex:platform_ref_unique"`
	RefLabel      string              // can be tag/branch/commit that user wrote in the yaml. example v0.1 or main.
	LabelType     terrpb.GitLabelEnum // 1=branch, 2=tag, 3=commit

	Components []PlatformComponent `gorm:"foreignKey:PlatformID"`
}

Platform table lists all terrarium platform template references Unique constraint - the unique constraint is setup such that the git reference (gir repo, commit & directory) of a platform cannot be duplicated in the table. There may be duplicate title in the table though, which is meant for grouping the references belonging to the same platform.

func (Platform) ToProto

func (p Platform) ToProto() *terrpb.Platform

type PlatformComponent

type PlatformComponent struct {
	Model

	PlatformID   uuid.UUID `gorm:"uniqueIndex:platform_components_unique"`
	DependencyID uuid.UUID `gorm:"uniqueIndex:platform_components_unique"`

	Platform   Platform   `gorm:"foreignKey:PlatformID"`
	Dependency Dependency `gorm:"foreignKey:DependencyID"`
}

func (PlatformComponent) ToProto

type PlatformComponents

type PlatformComponents []PlatformComponent

func (PlatformComponents) ToProto

func (c PlatformComponents) ToProto() []*terrariumpb.Component

type Platforms

type Platforms []Platform

func (Platforms) ToProto

func (pArr Platforms) ToProto() []*terrpb.Platform

type TFModule

type TFModule struct {
	Model

	ModuleName  string
	Source      string  `gorm:"uniqueIndex:module_unique"`
	Version     Version `gorm:"uniqueIndex:module_unique"`
	Namespace   string
	Description string
	TaxonomyID  *uuid.UUID `gorm:"default:null"`

	Taxonomy   *Taxonomy           `gorm:"foreignKey:TaxonomyID"`
	Attributes []TFModuleAttribute `gorm:"foreignKey:ModuleID"` // Attributes of the module
}

func (TFModule) GetInputAttributesWithMappings

func (m TFModule) GetInputAttributesWithMappings() (input TFModuleAttributes)

func (TFModule) ToProto

func (m TFModule) ToProto() *terrariumpb.Module

type TFModuleAttribute

type TFModuleAttribute struct {
	Model

	ModuleID                       uuid.UUID `gorm:"uniqueIndex:module_attribute_unique"`
	ModuleAttributeName            string    `gorm:"uniqueIndex:module_attribute_unique"`
	Description                    string
	RelatedResourceTypeAttributeID uuid.UUID
	Optional                       bool
	Computed                       bool

	Module            *TFModule            `gorm:"foreignKey:ModuleID"`
	ResourceAttribute *TFResourceAttribute `gorm:"foreignKey:RelatedResourceTypeAttributeID"` // Resource attribute with relates to this module attribute
}

func (*TFModuleAttribute) AfterFind

func (ima *TFModuleAttribute) AfterFind(*gorm.DB) (err error)

func (*TFModuleAttribute) GetConnectedModuleOutputs

func (ma *TFModuleAttribute) GetConnectedModuleOutputs() TFModuleAttributes

func (TFModuleAttribute) ToProto

func (dbAttr TFModuleAttribute) ToProto() *terrariumpb.ModuleAttribute

type TFModuleAttributes

type TFModuleAttributes []TFModuleAttribute

func (TFModuleAttributes) ToProto

func (dbAttrs TFModuleAttributes) ToProto() []*terrariumpb.ModuleAttribute

type TFModules

type TFModules []TFModule

func (TFModules) ToProto

func (mArr TFModules) ToProto() []*terrariumpb.Module

type TFProvider

type TFProvider struct {
	Model

	Name string `gorm:"unique"`
}

func (*TFProvider) IsEq

func (p1 *TFProvider) IsEq(p2 *TFProvider) bool

type TFResourceAttribute

type TFResourceAttribute struct {
	Model

	ResourceTypeID uuid.UUID `gorm:"uniqueIndex:resource_attribute_unique"`
	ProviderID     uuid.UUID `gorm:"uniqueIndex:resource_attribute_unique"`
	AttributePath  string    `gorm:"uniqueIndex:resource_attribute_unique"`
	DataType       string
	Description    string
	Optional       bool
	Computed       bool

	ResourceType       TFResourceType                `gorm:"foreignKey:ResourceTypeID"`
	Provider           TFProvider                    `gorm:"foreignKey:ProviderID"`
	RelatedModuleAttrs []TFModuleAttribute           `gorm:"foreignKey:RelatedResourceTypeAttributeID"` // Module attributes that relates to this resource attribute
	OutputMappings     []TFResourceAttributesMapping `gorm:"foreignKey:InputAttributeID"`               // Mappings with another resources's output attribute
	InputMappings      []TFResourceAttributesMapping `gorm:"foreignKey:OutputAttributeID"`              // Mappings with another resources's input attribute
}

func (TFResourceAttribute) GetConnectedModuleOutputs

func (a TFResourceAttribute) GetConnectedModuleOutputs() TFModuleAttributes

type TFResourceAttributesMapping

type TFResourceAttributesMapping struct {
	Model

	InputAttributeID  uuid.UUID `gorm:"uniqueIndex:resource_attribute_mapping_unique"`
	OutputAttributeID uuid.UUID `gorm:"uniqueIndex:resource_attribute_mapping_unique"`

	InputAttribute  TFResourceAttribute `gorm:"foreignKey:InputAttributeID"`  // Resource input-attribute object
	OutputAttribute TFResourceAttribute `gorm:"foreignKey:OutputAttributeID"` // Resource attribute object that provides the input-attribute
}

type TFResourceType

type TFResourceType struct {
	Model

	ProviderID   uuid.UUID  `gorm:"uniqueIndex:resource_type_unique"`
	ResourceType string     `gorm:"uniqueIndex:resource_type_unique"`
	TaxonomyID   *uuid.UUID `gorm:"default:null"`

	Provider TFProvider `gorm:"foreignKey:ProviderID"`
	Taxonomy *Taxonomy  `gorm:"foreignKey:TaxonomyID"`
}

type Taxonomies

type Taxonomies []Taxonomy

func (Taxonomies) ToProto

func (tArr Taxonomies) ToProto() []*terrariumpb.Taxonomy

type Taxonomy

type Taxonomy struct {
	Model

	Level1 string `gorm:"uniqueIndex:taxonomy_unique"`
	Level2 string `gorm:"uniqueIndex:taxonomy_unique"`
	Level3 string `gorm:"uniqueIndex:taxonomy_unique"`
	Level4 string `gorm:"uniqueIndex:taxonomy_unique"`
	Level5 string `gorm:"uniqueIndex:taxonomy_unique"`
	Level6 string `gorm:"uniqueIndex:taxonomy_unique"`
	Level7 string `gorm:"uniqueIndex:taxonomy_unique"`
}

func TaxonomyFromLevels

func TaxonomyFromLevels(levels ...string) *Taxonomy

func (*Taxonomy) IsEq

func (t1 *Taxonomy) IsEq(t2 *Taxonomy) bool

func (*Taxonomy) ToLevels

func (t *Taxonomy) ToLevels() []string

func (*Taxonomy) ToProto

func (t *Taxonomy) ToProto() *terrariumpb.Taxonomy

type Version

type Version string

func (Version) Compare

func (v1 Version) Compare(v2 Version) int

Compare returns -1 if v1 is less then v2, 0 if both are equal and 1 if v1 is greater then v2.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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