postgres

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SQLStateRestrictViolation   = "23001"
	SQLStateForeignKeyViolation = "23503"
	SQLStateUniqueViolation     = "23505"
)

Variables

View Source
var (
	// ErrProjectDeleteConfirmationRequired protects projects with retained clients.
	ErrProjectDeleteConfirmationRequired = errors.New("project deletion requires its exact current name")
	// ErrProjectArchiveBusy means an archive build holds the client lock.
	ErrProjectArchiveBusy = errors.New("project archive is in progress")
	// ErrArchiveStoreMissing means archive rows exist but no store can remove them.
	ErrArchiveStoreMissing = errors.New("archive storage is not configured")
	// ErrArchiveStoreMismatch means an archive row belongs to another storage backend.
	ErrArchiveStoreMismatch = errors.New("archive storage backend does not match")
	// ErrArchiveContentCleanup means the project row is gone but a ZIP delete failed.
	ErrArchiveContentCleanup = errors.New("archive content cleanup failed")
)

Functions

func AbortArchive

func AbortArchive(ctx context.Context, conn *pgx.Conn, archiveID, clientID uuid.UUID) (removed bool, err error)

AbortArchive releases claimed logs and removes only a building row. A false result (including an already committed ready row) forbids file cleanup.

func BeginArchive

func BeginArchive(ctx context.Context, conn *pgx.Conn, input sqlc.InsertBuildingArchiveParams) (record sqlc.Archive, count int64, err error)

BeginArchive freezes the exact cohort in the same transaction as its row.

func CompleteArchive

func CompleteArchive(ctx context.Context, conn *pgx.Conn, archive ReadyArchive) error

func CreateProjectWithClients

func CreateProjectWithClients(ctx context.Context, pool *pgxpool.Pool, input ProjectWithClientsInput) (sqlc.Project, error)

func CreateUserWithToken

func CreateUserWithToken(ctx context.Context, pool *pgxpool.Pool, input CreateUserWithTokenInput) (sqlc.User, error)

func DeleteProjectWithHistory

func DeleteProjectWithHistory(ctx context.Context, pool *pgxpool.Pool, projectID uuid.UUID, confirmationName, backend string, cleanup func(context.Context, []StoredArchive) error) error

DeleteProjectWithHistory removes the project, every client, and their logs, archive rows and policies. Archive files are deleted only after that commit, while the per-client archive locks are still held. A busy lock leaves the project unchanged. Projects with clients require their exact current name, checked under the project lock so concurrent edits cannot bypass confirmation.

func IsConstraintViolation

func IsConstraintViolation(err error, code, constraintName string) bool

func ReplaceLoginToken

func ReplaceLoginToken(ctx context.Context, pool *pgxpool.Pool, input ReplaceLoginTokenInput) error

func ReplaceUserProjects

func ReplaceUserProjects(ctx context.Context, pool *pgxpool.Pool, userID uuid.UUID, projectIDs []uuid.UUID) error

func UpdateProjectWithClients

func UpdateProjectWithClients(ctx context.Context, pool *pgxpool.Pool, input ProjectWithClientsInput) (sqlc.Project, error)

func UpdateUserProfileWithProjects

func UpdateUserProfileWithProjects(ctx context.Context, pool *pgxpool.Pool, input UpdateUserProfileWithProjectsInput) (sqlc.User, error)

func WithArchiveClientLock

func WithArchiveClientLock(ctx context.Context, pool *pgxpool.Pool, clientID uuid.UUID, fn func(*pgx.Conn) error) (locked bool, err error)

WithArchiveClientLock holds a session lock and a dedicated connection for the entire build, but does not keep a transaction open during file IO. All build transactions must use this connection: losing it also loses ownership.

func WithArchiveSchedulerLock

func WithArchiveSchedulerLock(ctx context.Context, pool *pgxpool.Pool, fn func(*pgx.Conn) error) (locked bool, err error)

WithArchiveSchedulerLock lets one server instance run a scheduler pass at a time.

Types

type CreateUserWithTokenInput

type CreateUserWithTokenInput struct {
	ID                 uuid.UUID
	Username           string
	FirstName          string
	LastName           string
	PasswordHash       string
	Role               string
	NeedsPasswordReset bool
	Token              LoginTokenInput
	ProjectIDs         []uuid.UUID
}

type LoginTokenInput

type LoginTokenInput struct {
	Hash      []byte
	ExpiresAt time.Time
}

type ProjectWithClientsInput

type ProjectWithClientsInput struct {
	ID      uuid.UUID
	Name    string
	Clients []string
}

type ReadyArchive

type ReadyArchive struct {
	ID        uuid.UUID
	ClientID  uuid.UUID
	SizeBytes int64
	SHA256    []byte
	LogCount  int64
	FromAt    time.Time
	ToAt      time.Time
}

type ReplaceLoginTokenInput

type ReplaceLoginTokenInput struct {
	UserID       uuid.UUID
	PasswordHash string
	Token        LoginTokenInput
}

type StoredArchive

type StoredArchive struct {
	Backend string
	Key     string
}

StoredArchive is a committed archive object that must be removed after the database delete commits. Keys stay internal to the configured backend.

type UpdateUserProfileWithProjectsInput

type UpdateUserProfileWithProjectsInput struct {
	ID         uuid.UUID
	Username   string
	FirstName  string
	LastName   string
	Role       string
	ProjectIDs []uuid.UUID
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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