db

package
v0.0.0-...-b264059 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: Apache-2.0 Imports: 21 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// LogrusGormLogger default GormLogger instance for Gorm logging through Logrus
	LogrusGormLogger = GormLogger{
		LogLevel:      logger.Warn,
		SlowThreshold: 200 * time.Millisecond,
	}
)

Functions

This section is empty.

Types

type Database

type Database struct {
	*gorm.DB
	// contains filtered or unexported fields
}

Database is a wrapping structure to *gorm.DB

func Init

func Init(config config.DBConfig, debug bool) *Database

Init setups up the Database and a pointer to it

func (*Database) Close

func (db *Database) Close()

Close get generic database interface *sql.DB from the current *gorm.DB and close it

func (*Database) DefaultVersion

func (db *Database) DefaultVersion(lineage string) (version string, err error)

DefaultVersion returns the default VersionID for a given Lineage Copied and adapted from github.com/hashicorp/terraform/command/jsonstate/state.go

func (*Database) GetLineageActivity

func (db *Database) GetLineageActivity(lineage string) (states []types.StateStat)

GetLineageActivity returns a slice of StateStat from the Database for a given lineage representing the State activity over time (Versions)

func (*Database) GetLineages

func (db *Database) GetLineages(limitStr string) (lineages []types.Lineage)

GetLineages retrieves all Lineage from the database

func (*Database) GetPlan

func (db *Database) GetPlan(id string) (plans types.Plan)

GetPlan retrieves a specific Plan by his ID from the database

func (*Database) GetPlans

func (db *Database) GetPlans(lineage, limitStr, pageStr string) (plans []types.Plan, page int, total int)

GetPlans retrieves all Plan of a lineage from the database

func (*Database) GetPlansSummary

func (db *Database) GetPlansSummary(lineage, limitStr, pageStr string) (plans []types.Plan, page int, total int)

GetPlansSummary retrieves a summary of all Plans of a lineage from the database

func (*Database) GetState

func (db *Database) GetState(lineage, versionID string) (state types.State)

GetState retrieves a State from the database by its path and versionID

func (*Database) InsertPlan

func (db *Database) InsertPlan(plan []byte) error

InsertPlan inserts a Terraform plan with associated information in the Database

func (*Database) InsertState

func (db *Database) InsertState(path string, versionID string, sf *statefile.File) error

InsertState inserts a Terraform State in the Database

func (*Database) InsertVersion

func (db *Database) InsertVersion(version *state.Version) error

InsertVersion inserts an AWS S3 Version in the Database

func (*Database) KnownVersions

func (db *Database) KnownVersions() (versions []string)

KnownVersions returns a slice of all known Versions in the Database

func (*Database) ListAttributeKeys

func (db *Database) ListAttributeKeys(resourceType string) (results []string, err error)

ListAttributeKeys lists all Resource Attribute keys for a given Resource type from the Database

func (*Database) ListResourceNames

func (db *Database) ListResourceNames() ([]string, error)

ListResourceNames lists all Resource names from the Database

func (*Database) ListResourceTypes

func (db *Database) ListResourceTypes() ([]string, error)

ListResourceTypes lists all Resource types from the Database

func (*Database) ListResourceTypesWithCount

func (db *Database) ListResourceTypesWithCount() (results []map[string]string, err error)

ListResourceTypesWithCount returns a list of Resource types with associated counts from the Database

func (*Database) ListStateStats

func (db *Database) ListStateStats(query url.Values) (states []types.StateStat, page int, total int)

ListStateStats returns a slice of StateStat, along with paging information

func (*Database) ListStatesVersions

func (db *Database) ListStatesVersions() (statesVersions map[string][]string)

ListStatesVersions returns a map of Version IDs to a slice of State paths from the Database

func (*Database) ListTerraformVersionsWithCount

func (db *Database) ListTerraformVersionsWithCount(query url.Values) (results []map[string]string, err error)

ListTerraformVersionsWithCount returns a slice of maps of Terraform versions mapped to the count of most recent State paths using them. ListTerraformVersionsWithCount also takes a query with possible parameter 'orderBy' to sort results. Default sorting is by descending version number.

func (*Database) ListTfVersions

func (db *Database) ListTfVersions() ([]string, error)

ListTfVersions lists all Terraform versions from the Database

func (*Database) MigrateLineage

func (db *Database) MigrateLineage() error

MigrateLineage is a migration function to update db and its data to the new lineage db scheme. It will update State table data, delete "lineage" column and add corresponding Lineage entries

func (*Database) SearchAttribute

func (db *Database) SearchAttribute(query url.Values) (results []types.SearchResult, page int, total int)

SearchAttribute returns a slice of SearchResult given a query The query might contain parameters 'type', 'name', 'key', 'value' and 'tf_version' SearchAttribute also returns paging information: the page number and the total results

func (*Database) UpdateState

func (db *Database) UpdateState(st types.State) error

UpdateState update a Terraform State in the Database with Lineage foreign constraint It will also insert Lineage entry in the db if needed. This method is only use during the Lineage migration since States are immutable

type GormLogger

type GormLogger struct {
	LogLevel      logger.LogLevel
	SlowThreshold time.Duration
}

GormLogger is a wrapper class that implement Gorm logger interface

func (*GormLogger) Error

func (l *GormLogger) Error(ctx context.Context, msg string, data ...interface{})

Error print error messages

func (*GormLogger) Info

func (l *GormLogger) Info(ctx context.Context, msg string, data ...interface{})

Info print info

func (*GormLogger) LogMode

func (l *GormLogger) LogMode(level logger.LogLevel) logger.Interface

LogMode log mode

func (*GormLogger) Trace

func (l *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

Trace print sql message

func (*GormLogger) Warn

func (l *GormLogger) Warn(ctx context.Context, msg string, data ...interface{})

Warn print warn messages

Jump to

Keyboard shortcuts

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