postgres

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package postgres provides PostgreSQL implementation of the store interfaces.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when a requested resource does not exist.
	ErrNotFound = errors.New("resource not found")

	// ErrDuplicateName is returned when attempting to create a resource with a duplicate name.
	ErrDuplicateName = errors.New("duplicate name")

	// ErrDuplicateKey is returned when attempting to create a resource with a duplicate key.
	ErrDuplicateKey = errors.New("duplicate key")

	// ErrConcurrentModification is returned when an optimistic locking conflict is detected.
	// This occurs when the version field doesn't match during an update operation.
	ErrConcurrentModification = errors.New("resource was modified by another request")
)

Common store errors.

Functions

func NewDomainStore

func NewDomainStore(db queryable) *domainStore

Types

type AppStore

type AppStore struct {
	// contains filtered or unexported fields
}

AppStore implements store.AppStore using PostgreSQL.

func (*AppStore) Create

func (s *AppStore) Create(ctx context.Context, app *models.App) error

Create creates a new application.

func (*AppStore) Delete

func (s *AppStore) Delete(ctx context.Context, id string) error

Delete soft-deletes an application by setting deleted_at.

func (*AppStore) Get

func (s *AppStore) Get(ctx context.Context, id string) (*models.App, error)

Get retrieves an application by ID.

func (*AppStore) GetByName

func (s *AppStore) GetByName(ctx context.Context, ownerID, name string) (*models.App, error)

GetByName retrieves an application by owner ID and name.

func (*AppStore) List

func (s *AppStore) List(ctx context.Context, ownerID string) ([]*models.App, error)

List retrieves all applications for a given owner.

func (*AppStore) ListByOrg

func (s *AppStore) ListByOrg(ctx context.Context, orgID string) ([]*models.App, error)

ListByOrg retrieves all applications for a given organization. Excludes soft-deleted apps.

func (*AppStore) Update

func (s *AppStore) Update(ctx context.Context, app *models.App) error

Update updates an existing application with optimistic locking. Returns ErrConcurrentModification if the version doesn't match.

type BuildStore

type BuildStore struct {
	// contains filtered or unexported fields
}

BuildStore implements store.BuildStore using PostgreSQL.

func (*BuildStore) Create

func (s *BuildStore) Create(ctx context.Context, build *models.BuildJob) error

Create creates a new build job.

func (*BuildStore) Get

func (s *BuildStore) Get(ctx context.Context, id string) (*models.BuildJob, error)

Get retrieves a build job by ID.

func (*BuildStore) GetByDeployment

func (s *BuildStore) GetByDeployment(ctx context.Context, deploymentID string) (*models.BuildJob, error)

GetByDeployment retrieves a build job by deployment ID.

func (*BuildStore) List

func (s *BuildStore) List(ctx context.Context, appID string) ([]*models.BuildJob, error)

List retrieves all builds for a given application.

func (*BuildStore) ListByUser

func (s *BuildStore) ListByUser(ctx context.Context, userID string) ([]*models.BuildJob, error)

ListByUser retrieves all builds for a given user across all apps.

func (*BuildStore) ListPending

func (s *BuildStore) ListPending(ctx context.Context) ([]*models.BuildJob, error)

ListPending retrieves all pending build jobs.

func (*BuildStore) ListQueued

func (s *BuildStore) ListQueued(ctx context.Context) ([]*models.BuildJob, error)

ListQueued retrieves all builds with status 'queued'. Used for startup recovery to resume pending builds. **Validates: Requirements 15.1**

func (*BuildStore) ListRunning

func (s *BuildStore) ListRunning(ctx context.Context) ([]*models.BuildJob, error)

ListRunning retrieves all builds with status 'running'. Used for startup recovery to identify interrupted builds. **Validates: Requirements 15.1, 15.2**

func (*BuildStore) Update

func (s *BuildStore) Update(ctx context.Context, build *models.BuildJob) error

Update updates an existing build job.

type Config

type Config struct {
	DSN             string
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
	ConnMaxIdleTime time.Duration
}

Config holds PostgreSQL connection configuration.

func DefaultConfig

func DefaultConfig(dsn string) *Config

DefaultConfig returns a Config with sensible defaults.

type DeploymentStore

type DeploymentStore struct {
	// contains filtered or unexported fields
}

DeploymentStore implements store.DeploymentStore using PostgreSQL.

func (*DeploymentStore) CountByStatusAndOrg

func (s *DeploymentStore) CountByStatusAndOrg(ctx context.Context, status models.DeploymentStatus, orgID string) (int, error)

CountByStatusAndOrg counts deployments by status filtered by organization.

func (*DeploymentStore) Create

func (s *DeploymentStore) Create(ctx context.Context, deployment *models.Deployment) error

Create creates a new deployment.

func (*DeploymentStore) Get

Get retrieves a deployment by ID.

func (*DeploymentStore) GetLatestSuccessful

func (s *DeploymentStore) GetLatestSuccessful(ctx context.Context, appID string) (*models.Deployment, error)

GetLatestSuccessful retrieves the most recent successful deployment for an app.

func (*DeploymentStore) GetNextVersion

func (s *DeploymentStore) GetNextVersion(ctx context.Context, appID, serviceName string) (int, error)

GetNextVersion returns the next version number for a service. Returns 1 for the first deployment, or max(version) + 1 for subsequent deployments. **Validates: Requirements 9.1, 9.2**

func (*DeploymentStore) List

func (s *DeploymentStore) List(ctx context.Context, appID string) ([]*models.Deployment, error)

List retrieves all deployments for a given application, ordered by created_at DESC.

func (*DeploymentStore) ListByNode

func (s *DeploymentStore) ListByNode(ctx context.Context, nodeID string) ([]*models.Deployment, error)

ListByNode retrieves all deployments assigned to a given node.

func (*DeploymentStore) ListByStatus

func (s *DeploymentStore) ListByStatus(ctx context.Context, status models.DeploymentStatus) ([]*models.Deployment, error)

ListByStatus retrieves all deployments with a given status.

func (*DeploymentStore) ListByUser

func (s *DeploymentStore) ListByUser(ctx context.Context, userID string) ([]*models.Deployment, error)

ListByUser retrieves all deployments for all apps owned by a given user.

func (*DeploymentStore) Update

func (s *DeploymentStore) Update(ctx context.Context, deployment *models.Deployment) error

Update updates an existing deployment.

type GitHubAccountStore

type GitHubAccountStore struct {
	// contains filtered or unexported fields
}

GitHubAccountStore implements store.GitHubAccountStore using PostgreSQL.

func (*GitHubAccountStore) Create

func (s *GitHubAccountStore) Create(ctx context.Context, account *models.GitHubAccount) error

Create saves a new GitHub account.

func (*GitHubAccountStore) Delete

func (s *GitHubAccountStore) Delete(ctx context.Context, id int64) error

Delete removes a GitHub account.

func (*GitHubAccountStore) Get

Get retrieves a GitHub account by its ID.

func (*GitHubAccountStore) GetByUserID

func (s *GitHubAccountStore) GetByUserID(ctx context.Context, userID string) (*models.GitHubAccount, error)

GetByUserID retrieves a GitHub account by its associated user ID.

func (*GitHubAccountStore) Update

func (s *GitHubAccountStore) Update(ctx context.Context, account *models.GitHubAccount) error

Update updates an existing GitHub account.

type GitHubStore

type GitHubStore struct {
	// contains filtered or unexported fields
}

GitHubStore implements store.GitHubStore using PostgreSQL.

func (*GitHubStore) CreateInstallation

func (s *GitHubStore) CreateInstallation(ctx context.Context, inst *models.GitHubInstallation) error

CreateInstallation saves a new GitHub App installation.

func (*GitHubStore) DeleteInstallation

func (s *GitHubStore) DeleteInstallation(ctx context.Context, id int64) error

DeleteInstallation removes an installation.

func (*GitHubStore) GetConfig

func (s *GitHubStore) GetConfig(ctx context.Context) (*models.GitHubAppConfig, error)

GetConfig retrieves the GitHub App configuration.

func (*GitHubStore) GetInstallation

func (s *GitHubStore) GetInstallation(ctx context.Context, id int64) (*models.GitHubInstallation, error)

GetInstallation retrieves an installation by its ID.

func (*GitHubStore) ListInstallations

func (s *GitHubStore) ListInstallations(ctx context.Context, userID string) ([]*models.GitHubInstallation, error)

ListInstallations retrieves all installations for a given user.

func (*GitHubStore) ResetConfig

func (s *GitHubStore) ResetConfig(ctx context.Context) error

ResetConfig clears the GitHub App configuration and all installations.

func (*GitHubStore) SaveConfig

func (s *GitHubStore) SaveConfig(ctx context.Context, config *models.GitHubAppConfig) error

SaveConfig saves the GitHub App configuration.

type InvitationStore

type InvitationStore struct {
	// contains filtered or unexported fields
}

InvitationStore implements store.InvitationStore using PostgreSQL.

func (*InvitationStore) Create

func (s *InvitationStore) Create(ctx context.Context, invitation *models.Invitation) error

Create creates a new invitation.

func (*InvitationStore) Delete

func (s *InvitationStore) Delete(ctx context.Context, id string) error

Delete removes an invitation.

func (*InvitationStore) Get

Get retrieves an invitation by ID.

func (*InvitationStore) GetByEmail

func (s *InvitationStore) GetByEmail(ctx context.Context, email string) (*models.Invitation, error)

GetByEmail retrieves a pending invitation by email.

func (*InvitationStore) GetByToken

func (s *InvitationStore) GetByToken(ctx context.Context, token string) (*models.Invitation, error)

GetByToken retrieves an invitation by its token.

func (*InvitationStore) List

List retrieves all invitations.

func (*InvitationStore) Update

func (s *InvitationStore) Update(ctx context.Context, invitation *models.Invitation) error

Update updates an invitation.

type LogStore

type LogStore struct {
	// contains filtered or unexported fields
}

LogStore implements store.LogStore using PostgreSQL.

func (*LogStore) Create

func (s *LogStore) Create(ctx context.Context, entry *models.LogEntry) error

Create creates a new log entry.

func (*LogStore) DeleteOlderThan

func (s *LogStore) DeleteOlderThan(ctx context.Context, deploymentID string, before int64) error

DeleteOlderThan removes log entries older than the specified timestamp.

func (*LogStore) List

func (s *LogStore) List(ctx context.Context, deploymentID string, limit int) ([]*models.LogEntry, error)

List retrieves log entries for a deployment.

func (*LogStore) ListBySource

func (s *LogStore) ListBySource(ctx context.Context, deploymentID, source string, limit int) ([]*models.LogEntry, error)

ListBySource retrieves log entries filtered by source (build/runtime).

type NodeStore

type NodeStore struct {
	// contains filtered or unexported fields
}

NodeStore implements store.NodeStore using PostgreSQL.

func (*NodeStore) Get

func (s *NodeStore) Get(ctx context.Context, id string) (*models.Node, error)

Get retrieves a node by ID.

func (*NodeStore) List

func (s *NodeStore) List(ctx context.Context) ([]*models.Node, error)

List retrieves all registered nodes.

func (*NodeStore) ListHealthy

func (s *NodeStore) ListHealthy(ctx context.Context) ([]*models.Node, error)

ListHealthy retrieves all healthy nodes.

func (*NodeStore) ListWithClosure

func (s *NodeStore) ListWithClosure(ctx context.Context, storePath string) ([]*models.Node, error)

ListWithClosure retrieves nodes that have a specific store path cached.

func (*NodeStore) Register

func (s *NodeStore) Register(ctx context.Context, node *models.Node) error

Register registers a new node or updates an existing one.

func (*NodeStore) UpdateHealth

func (s *NodeStore) UpdateHealth(ctx context.Context, id string, healthy bool) error

UpdateHealth updates a node's health status.

func (*NodeStore) UpdateHeartbeat

func (s *NodeStore) UpdateHeartbeat(ctx context.Context, id string, resources *models.NodeResources) error

UpdateHeartbeat updates a node's last heartbeat timestamp and resource metrics.

func (*NodeStore) UpdateHeartbeatWithDiskMetrics

func (s *NodeStore) UpdateHeartbeatWithDiskMetrics(ctx context.Context, id string, resources *models.NodeResources, diskMetrics *models.NodeDiskMetrics) error

UpdateHeartbeatWithDiskMetrics updates a node's heartbeat with detailed disk metrics. **Validates: Requirements 20.1**

type OrgStore

type OrgStore struct {
	// contains filtered or unexported fields
}

OrgStore implements store.OrgStore using PostgreSQL.

func (*OrgStore) AddMember

func (s *OrgStore) AddMember(ctx context.Context, orgID, userID string, role models.Role) error

AddMember adds a user to an organization with a role.

func (*OrgStore) Count

func (s *OrgStore) Count(ctx context.Context) (int, error)

Count returns the total number of organizations.

func (*OrgStore) Create

func (s *OrgStore) Create(ctx context.Context, org *models.Organization) error

Create creates a new organization.

func (*OrgStore) Delete

func (s *OrgStore) Delete(ctx context.Context, id string) error

Delete deletes an organization (only if not the last one).

func (*OrgStore) Get

func (s *OrgStore) Get(ctx context.Context, id string) (*models.Organization, error)

Get retrieves an organization by ID.

func (*OrgStore) GetBySlug

func (s *OrgStore) GetBySlug(ctx context.Context, slug string) (*models.Organization, error)

GetBySlug retrieves an organization by slug.

func (*OrgStore) GetDefault

func (s *OrgStore) GetDefault(ctx context.Context) (*models.Organization, error)

GetDefault returns the default organization (first created).

func (*OrgStore) GetDefaultForUser

func (s *OrgStore) GetDefaultForUser(ctx context.Context, userID string) (*models.Organization, error)

GetDefaultForUser returns the user's default organization. Returns the first organization the user is a member of (ordered by creation date).

func (*OrgStore) IsMember

func (s *OrgStore) IsMember(ctx context.Context, orgID, userID string) (bool, error)

IsMember checks if a user is a member of an organization.

func (*OrgStore) List

func (s *OrgStore) List(ctx context.Context, userID string) ([]*models.Organization, error)

List retrieves all organizations for a user.

func (*OrgStore) ListMembers

func (s *OrgStore) ListMembers(ctx context.Context, orgID string) ([]*models.OrgMembership, error)

ListMembers retrieves all members of an organization.

func (*OrgStore) RemoveMember

func (s *OrgStore) RemoveMember(ctx context.Context, orgID, userID string) error

RemoveMember removes a user from an organization.

func (*OrgStore) Update

func (s *OrgStore) Update(ctx context.Context, org *models.Organization) error

Update updates an organization.

type PostgresStore

type PostgresStore struct {
	// contains filtered or unexported fields
}

func NewPostgresStore

func NewPostgresStore(cfg *Config, logger *slog.Logger) (*PostgresStore, error)

NewPostgresStore creates a new PostgreSQL store with the given configuration.

func (*PostgresStore) Apps

func (s *PostgresStore) Apps() store.AppStore

Apps returns the AppStore.

func (*PostgresStore) Builds

func (s *PostgresStore) Builds() store.BuildStore

Builds returns the BuildStore.

func (*PostgresStore) Close

func (s *PostgresStore) Close() error

Close closes the database connection.

func (*PostgresStore) DB

func (s *PostgresStore) DB() *sql.DB

DB returns the underlying database connection. This is useful for components that need direct database access.

func (*PostgresStore) Deployments

func (s *PostgresStore) Deployments() store.DeploymentStore

Deployments returns the DeploymentStore.

func (*PostgresStore) Domains

func (s *PostgresStore) Domains() store.DomainStore

Domains returns the DomainStore.

func (*PostgresStore) GitHub

func (s *PostgresStore) GitHub() store.GitHubStore

GitHub returns the GitHubStore.

func (*PostgresStore) GitHubAccounts

func (s *PostgresStore) GitHubAccounts() store.GitHubAccountStore

GitHubAccounts returns the GitHubAccountStore.

func (*PostgresStore) Invitations

func (s *PostgresStore) Invitations() store.InvitationStore

Invitations returns the InvitationStore.

func (*PostgresStore) Logs

func (s *PostgresStore) Logs() store.LogStore

Logs returns the LogStore.

func (*PostgresStore) Nodes

func (s *PostgresStore) Nodes() store.NodeStore

Nodes returns the NodeStore.

func (*PostgresStore) Orgs

func (s *PostgresStore) Orgs() store.OrgStore

Orgs returns the OrgStore.

func (*PostgresStore) Ping

func (s *PostgresStore) Ping(ctx context.Context) error

Ping verifies database connectivity.

func (*PostgresStore) Secrets

func (s *PostgresStore) Secrets() store.SecretStore

Secrets returns the SecretStore.

func (*PostgresStore) Settings

func (s *PostgresStore) Settings() store.SettingsStore

Settings returns the SettingsStore.

func (*PostgresStore) Users

func (s *PostgresStore) Users() store.UserStore

Users returns the UserStore.

func (*PostgresStore) WithTx

func (s *PostgresStore) WithTx(ctx context.Context, fn func(store.Store) error) error

WithTx executes the given function within a database transaction.

type SecretStore

type SecretStore struct {
	// contains filtered or unexported fields
}

SecretStore implements store.SecretStore using PostgreSQL.

func (*SecretStore) Delete

func (s *SecretStore) Delete(ctx context.Context, appID, key string) error

Delete removes a secret.

func (*SecretStore) Get

func (s *SecretStore) Get(ctx context.Context, appID, key string) ([]byte, error)

Get retrieves a secret by app ID and key.

func (*SecretStore) GetAll

func (s *SecretStore) GetAll(ctx context.Context, appID string) (map[string][]byte, error)

GetAll retrieves all secrets for an application as a map.

func (*SecretStore) List

func (s *SecretStore) List(ctx context.Context, appID string) ([]string, error)

List retrieves all secret keys for an application.

func (*SecretStore) Set

func (s *SecretStore) Set(ctx context.Context, appID, key string, encryptedValue []byte) error

Set creates or updates a secret for an application.

type SettingsStore

type SettingsStore struct {
	// contains filtered or unexported fields
}

SettingsStore implements store.SettingsStore for PostgreSQL.

func (*SettingsStore) Get

func (s *SettingsStore) Get(ctx context.Context, key string) (string, error)

Get retrieves a setting by key.

func (*SettingsStore) GetAll

func (s *SettingsStore) GetAll(ctx context.Context) (map[string]string, error)

GetAll retrieves all global settings.

func (*SettingsStore) Set

func (s *SettingsStore) Set(ctx context.Context, key, value string) error

Set sets a setting key-value pair.

type UserStore

type UserStore struct {
	// contains filtered or unexported fields
}

UserStore implements store.UserStore using PostgreSQL.

func (*UserStore) Authenticate

func (s *UserStore) Authenticate(ctx context.Context, email, password string) (*store.User, error)

Authenticate verifies credentials and returns the user.

func (*UserStore) CountByRole

func (s *UserStore) CountByRole(ctx context.Context, role store.Role) (int, error)

CountByRole returns the number of users with a specific role.

func (*UserStore) Create

func (s *UserStore) Create(ctx context.Context, email, password string, isAdmin bool) (*store.User, error)

Create creates a new user with hashed password. Deprecated: Use CreateWithRole instead.

func (*UserStore) CreateWithRole

func (s *UserStore) CreateWithRole(ctx context.Context, email, password string, role store.Role, invitedBy string) (*store.User, error)

CreateWithRole creates a new user with hashed password and specified role.

func (*UserStore) Delete

func (s *UserStore) Delete(ctx context.Context, id string) error

Delete removes a user by ID.

func (*UserStore) GetByEmail

func (s *UserStore) GetByEmail(ctx context.Context, email string) (*store.User, error)

GetByEmail retrieves a user by email.

func (*UserStore) GetByID

func (s *UserStore) GetByID(ctx context.Context, id string) (*store.User, error)

GetByID retrieves a user by ID.

func (*UserStore) GetFirstOwner

func (s *UserStore) GetFirstOwner(ctx context.Context) (*store.User, error)

GetFirstOwner returns the first user with owner role, if any.

func (*UserStore) List

func (s *UserStore) List(ctx context.Context) ([]*store.User, error)

List retrieves all users.

func (*UserStore) Update

func (s *UserStore) Update(ctx context.Context, user *store.User) error

Update updates an existing user's information.

Jump to

Keyboard shortcuts

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