Documentation
¶
Index ¶
- Constants
- Variables
- func AbortArchive(ctx context.Context, conn *pgx.Conn, archiveID, clientID uuid.UUID) (removed bool, err error)
- func BeginArchive(ctx context.Context, conn *pgx.Conn, input sqlc.InsertBuildingArchiveParams) (record sqlc.Archive, count int64, err error)
- func CompleteArchive(ctx context.Context, conn *pgx.Conn, archive ReadyArchive) error
- func CreateProjectWithClients(ctx context.Context, pool *pgxpool.Pool, input ProjectWithClientsInput) (sqlc.Project, error)
- func CreateUserWithToken(ctx context.Context, pool *pgxpool.Pool, input CreateUserWithTokenInput) (sqlc.User, error)
- func DeleteProjectWithHistory(ctx context.Context, pool *pgxpool.Pool, projectID uuid.UUID, ...) error
- func InsertLogs(ctx context.Context, pool *pgxpool.Pool, logs []LogInsert) ([]int64, error)
- func IsConstraintViolation(err error, code, constraintName string) bool
- func ListInstances(ctx context.Context, pool *pgxpool.Pool, projectID, clientID uuid.UUID) ([]string, error)
- func ReplaceLoginToken(ctx context.Context, pool *pgxpool.Pool, input ReplaceLoginTokenInput) error
- func ReplaceUserProjects(ctx context.Context, pool *pgxpool.Pool, userID uuid.UUID, ...) error
- func UpdateProjectWithClients(ctx context.Context, pool *pgxpool.Pool, input ProjectWithClientsInput) (sqlc.Project, error)
- func UpdateUserProfileWithProjects(ctx context.Context, pool *pgxpool.Pool, ...) (sqlc.User, error)
- func WithArchiveClientLock(ctx context.Context, pool *pgxpool.Pool, clientID uuid.UUID, ...) (locked bool, err error)
- func WithArchiveSchedulerLock(ctx context.Context, pool *pgxpool.Pool, fn func(*pgx.Conn) error) (locked bool, err error)
- type CreateUserWithTokenInput
- type IngestLogInsert
- type IngestLogResult
- type IngestLogStatus
- type LogInsert
- type LogReadQuery
- type LogRow
- func GetLogAnchor(ctx context.Context, pool *pgxpool.Pool, projectID, clientID uuid.UUID, ...) (LogRow, error)
- func ListLogs(ctx context.Context, pool *pgxpool.Pool, query LogReadQuery) ([]LogRow, error)
- func SearchLogs(ctx context.Context, pool *pgxpool.Pool, query LogSearchQuery) ([]LogRow, error)
- type LogSearchQuery
- type LoginTokenInput
- type ProjectWithClientsInput
- type ReadyArchive
- type ReplaceLoginTokenInput
- type StoredArchive
- type UpdateUserProfileWithProjectsInput
Constants ¶
const ( SQLStateRestrictViolation = "23001" SQLStateForeignKeyViolation = "23503" SQLStateUniqueViolation = "23505" )
Variables ¶
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 CreateUserWithToken ¶
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 InsertLogs ¶
func IsConstraintViolation ¶
func ListInstances ¶
func ReplaceLoginToken ¶
func ReplaceUserProjects ¶
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.
Types ¶
type IngestLogInsert ¶
type IngestLogResult ¶ added in v0.0.10
type IngestLogResult struct {
Ordinal int64 // One-based position in the input batch.
ID int64 // Set only for a newly inserted row.
Status IngestLogStatus
}
func InsertIngestLogs ¶
func InsertIngestLogs(ctx context.Context, pool *pgxpool.Pool, logs []IngestLogInsert) ([]IngestLogResult, error)
InsertIngestLogs checks client ownership and activity in the insert statement and returns one outcome per input row, in input order. Deduplication keys last only as long as the corresponding logs are retained.
type IngestLogStatus ¶ added in v0.0.10
type IngestLogStatus uint8
const ( IngestLogInserted IngestLogStatus = iota + 1 IngestLogDuplicate IngestLogRejectedClient )
type LogReadQuery ¶
type LogRow ¶
type LogRow struct {
ID int64
ClientID uuid.UUID
ProjectID uuid.UUID
InstanceName string
OccurredAt time.Time
SequenceNumber int64
Message string
}
func GetLogAnchor ¶
func SearchLogs ¶
type LogSearchQuery ¶
type LogSearchQuery struct {
LogReadQuery
PrimaryPattern string
RemainingPatterns []string
}
type LoginTokenInput ¶
type ProjectWithClientsInput ¶
type ReadyArchive ¶
type ReplaceLoginTokenInput ¶
type ReplaceLoginTokenInput struct {
UserID uuid.UUID
PasswordHash string
Token LoginTokenInput
}
type StoredArchive ¶
StoredArchive is a committed archive object that must be removed after the database delete commits. Keys stay internal to the configured backend.