db

package
v0.2.0 Latest Latest
Warning

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

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

README

Datastore

The Galadriel project supports two datastore engines: SQLite and Postgres. The Datastore handles all database interactions. This document outlines the procedures for generating type-safe code, handling migrations, and changing the database schema.

SQL Code Generation

We use sqlc to generate type-safe Go code for SQL queries. Sqlc configurations are defined in the sqlc.yaml file.

Whenever there are changes to the schema or queries, run the following command to regenerate the Go code:

make generate-sql-code

This command regenerates the models.gen.go, db.gen.go, querier.gen.go, and the .sql.go files.

Note: Remember to commit these regenerated files.

Database Migrations

Database migrations are managed with golang-migrate.

During the creation of a new Datastore object using the NewDatastore method, the schema version is verified, and any necessary migrations are applied.

Changing the Database Schema

Following the initial release of Galadriel, any changes to the DB schema must be handled through new files in the postgres migrations and sqlite3 migrations folders. Also, the queries in the postgres queries and sqlite queries should be updated accordingly.

To reflect the current schema version supported by Galadriel and to ensure automatic migration, remember to increment the currentDBVersion constant.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PopulateTrustDomainNames

func PopulateTrustDomainNames(ctx context.Context, datastore Datastore, relationships ...*entity.Relationship) ([]*entity.Relationship, error)

PopulateTrustDomainNames updates the TrustDomainAName and TrustDomainBName fields of each Relationship in the given slice based on their TrustDomainAID and TrustDomainBID, respectively. It fetches the trust domain names from the provided Datastore.

Types

type Datastore

type Datastore interface {
	CreateOrUpdateTrustDomain(ctx context.Context, req *entity.TrustDomain) (*entity.TrustDomain, error)
	DeleteTrustDomain(ctx context.Context, trustDomainID uuid.UUID) error
	ListTrustDomains(ctx context.Context) ([]*entity.TrustDomain, error)
	FindTrustDomainByID(ctx context.Context, trustDomainID uuid.UUID) (*entity.TrustDomain, error)
	FindTrustDomainByName(ctx context.Context, trustDomain spiffeid.TrustDomain) (*entity.TrustDomain, error)
	CreateOrUpdateBundle(ctx context.Context, req *entity.Bundle) (*entity.Bundle, error)
	FindBundleByID(ctx context.Context, bundleID uuid.UUID) (*entity.Bundle, error)
	FindBundleByTrustDomainID(ctx context.Context, trustDomainID uuid.UUID) (*entity.Bundle, error)
	ListBundles(ctx context.Context) ([]*entity.Bundle, error)
	DeleteBundle(ctx context.Context, bundleID uuid.UUID) error
	CreateJoinToken(ctx context.Context, req *entity.JoinToken) (*entity.JoinToken, error)
	FindJoinTokensByID(ctx context.Context, joinTokenID uuid.UUID) (*entity.JoinToken, error)
	FindJoinTokensByTrustDomainID(ctx context.Context, trustDomainID uuid.UUID) ([]*entity.JoinToken, error)
	ListJoinTokens(ctx context.Context) ([]*entity.JoinToken, error)
	UpdateJoinToken(ctx context.Context, joinTokenID uuid.UUID, used bool) (*entity.JoinToken, error)
	DeleteJoinToken(ctx context.Context, joinTokenID uuid.UUID) error
	FindJoinToken(ctx context.Context, token string) (*entity.JoinToken, error)
	CreateOrUpdateRelationship(ctx context.Context, req *entity.Relationship) (*entity.Relationship, error)
	FindRelationshipByID(ctx context.Context, relationshipID uuid.UUID) (*entity.Relationship, error)
	FindRelationshipsByTrustDomainID(ctx context.Context, trustDomainID uuid.UUID) ([]*entity.Relationship, error)
	ListRelationships(ctx context.Context) ([]*entity.Relationship, error)
	DeleteRelationship(ctx context.Context, relationshipID uuid.UUID) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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