Documentation
¶
Overview ¶
Package postgres provides PostgreSQL implementation of the store interfaces.
Index ¶
- Variables
- func NewDomainStore(db queryable) *domainStore
- type AppStore
- func (s *AppStore) Create(ctx context.Context, app *models.App) error
- func (s *AppStore) Delete(ctx context.Context, id string) error
- func (s *AppStore) Get(ctx context.Context, id string) (*models.App, error)
- func (s *AppStore) GetByName(ctx context.Context, ownerID, name string) (*models.App, error)
- func (s *AppStore) List(ctx context.Context, ownerID string) ([]*models.App, error)
- func (s *AppStore) ListByOrg(ctx context.Context, orgID string) ([]*models.App, error)
- func (s *AppStore) Update(ctx context.Context, app *models.App) error
- type BuildStore
- func (s *BuildStore) Create(ctx context.Context, build *models.BuildJob) error
- func (s *BuildStore) Get(ctx context.Context, id string) (*models.BuildJob, error)
- func (s *BuildStore) GetByDeployment(ctx context.Context, deploymentID string) (*models.BuildJob, error)
- func (s *BuildStore) List(ctx context.Context, appID string) ([]*models.BuildJob, error)
- func (s *BuildStore) ListByUser(ctx context.Context, userID string) ([]*models.BuildJob, error)
- func (s *BuildStore) ListPending(ctx context.Context) ([]*models.BuildJob, error)
- func (s *BuildStore) ListQueued(ctx context.Context) ([]*models.BuildJob, error)
- func (s *BuildStore) ListRunning(ctx context.Context) ([]*models.BuildJob, error)
- func (s *BuildStore) Update(ctx context.Context, build *models.BuildJob) error
- type Config
- type DeploymentStore
- func (s *DeploymentStore) CountByStatusAndOrg(ctx context.Context, status models.DeploymentStatus, orgID string) (int, error)
- func (s *DeploymentStore) Create(ctx context.Context, deployment *models.Deployment) error
- func (s *DeploymentStore) Get(ctx context.Context, id string) (*models.Deployment, error)
- func (s *DeploymentStore) GetLatestSuccessful(ctx context.Context, appID string) (*models.Deployment, error)
- func (s *DeploymentStore) GetNextVersion(ctx context.Context, appID, serviceName string) (int, error)
- func (s *DeploymentStore) List(ctx context.Context, appID string) ([]*models.Deployment, error)
- func (s *DeploymentStore) ListByNode(ctx context.Context, nodeID string) ([]*models.Deployment, error)
- func (s *DeploymentStore) ListByStatus(ctx context.Context, status models.DeploymentStatus) ([]*models.Deployment, error)
- func (s *DeploymentStore) ListByUser(ctx context.Context, userID string) ([]*models.Deployment, error)
- func (s *DeploymentStore) Update(ctx context.Context, deployment *models.Deployment) error
- type GitHubAccountStore
- func (s *GitHubAccountStore) Create(ctx context.Context, account *models.GitHubAccount) error
- func (s *GitHubAccountStore) Delete(ctx context.Context, id int64) error
- func (s *GitHubAccountStore) Get(ctx context.Context, id int64) (*models.GitHubAccount, error)
- func (s *GitHubAccountStore) GetByUserID(ctx context.Context, userID string) (*models.GitHubAccount, error)
- func (s *GitHubAccountStore) Update(ctx context.Context, account *models.GitHubAccount) error
- type GitHubStore
- func (s *GitHubStore) CreateInstallation(ctx context.Context, inst *models.GitHubInstallation) error
- func (s *GitHubStore) DeleteInstallation(ctx context.Context, id int64) error
- func (s *GitHubStore) GetConfig(ctx context.Context) (*models.GitHubAppConfig, error)
- func (s *GitHubStore) GetInstallation(ctx context.Context, id int64) (*models.GitHubInstallation, error)
- func (s *GitHubStore) ListInstallations(ctx context.Context, userID string) ([]*models.GitHubInstallation, error)
- func (s *GitHubStore) ResetConfig(ctx context.Context) error
- func (s *GitHubStore) SaveConfig(ctx context.Context, config *models.GitHubAppConfig) error
- type InvitationStore
- func (s *InvitationStore) Create(ctx context.Context, invitation *models.Invitation) error
- func (s *InvitationStore) Delete(ctx context.Context, id string) error
- func (s *InvitationStore) Get(ctx context.Context, id string) (*models.Invitation, error)
- func (s *InvitationStore) GetByEmail(ctx context.Context, email string) (*models.Invitation, error)
- func (s *InvitationStore) GetByToken(ctx context.Context, token string) (*models.Invitation, error)
- func (s *InvitationStore) List(ctx context.Context) ([]*models.Invitation, error)
- func (s *InvitationStore) Update(ctx context.Context, invitation *models.Invitation) error
- type LogStore
- func (s *LogStore) Create(ctx context.Context, entry *models.LogEntry) error
- func (s *LogStore) DeleteOlderThan(ctx context.Context, deploymentID string, before int64) error
- func (s *LogStore) List(ctx context.Context, deploymentID string, limit int) ([]*models.LogEntry, error)
- func (s *LogStore) ListBySource(ctx context.Context, deploymentID, source string, limit int) ([]*models.LogEntry, error)
- type NodeStore
- func (s *NodeStore) Get(ctx context.Context, id string) (*models.Node, error)
- func (s *NodeStore) List(ctx context.Context) ([]*models.Node, error)
- func (s *NodeStore) ListHealthy(ctx context.Context) ([]*models.Node, error)
- func (s *NodeStore) ListWithClosure(ctx context.Context, storePath string) ([]*models.Node, error)
- func (s *NodeStore) Register(ctx context.Context, node *models.Node) error
- func (s *NodeStore) UpdateHealth(ctx context.Context, id string, healthy bool) error
- func (s *NodeStore) UpdateHeartbeat(ctx context.Context, id string, resources *models.NodeResources) error
- func (s *NodeStore) UpdateHeartbeatWithDiskMetrics(ctx context.Context, id string, resources *models.NodeResources, ...) error
- type OrgStore
- func (s *OrgStore) AddMember(ctx context.Context, orgID, userID string, role models.Role) error
- func (s *OrgStore) Count(ctx context.Context) (int, error)
- func (s *OrgStore) Create(ctx context.Context, org *models.Organization) error
- func (s *OrgStore) Delete(ctx context.Context, id string) error
- func (s *OrgStore) Get(ctx context.Context, id string) (*models.Organization, error)
- func (s *OrgStore) GetBySlug(ctx context.Context, slug string) (*models.Organization, error)
- func (s *OrgStore) GetDefault(ctx context.Context) (*models.Organization, error)
- func (s *OrgStore) GetDefaultForUser(ctx context.Context, userID string) (*models.Organization, error)
- func (s *OrgStore) IsMember(ctx context.Context, orgID, userID string) (bool, error)
- func (s *OrgStore) List(ctx context.Context, userID string) ([]*models.Organization, error)
- func (s *OrgStore) ListMembers(ctx context.Context, orgID string) ([]*models.OrgMembership, error)
- func (s *OrgStore) RemoveMember(ctx context.Context, orgID, userID string) error
- func (s *OrgStore) Update(ctx context.Context, org *models.Organization) error
- type PostgresStore
- func (s *PostgresStore) Apps() store.AppStore
- func (s *PostgresStore) Builds() store.BuildStore
- func (s *PostgresStore) Close() error
- func (s *PostgresStore) DB() *sql.DB
- func (s *PostgresStore) Deployments() store.DeploymentStore
- func (s *PostgresStore) Domains() store.DomainStore
- func (s *PostgresStore) GitHub() store.GitHubStore
- func (s *PostgresStore) GitHubAccounts() store.GitHubAccountStore
- func (s *PostgresStore) Invitations() store.InvitationStore
- func (s *PostgresStore) Logs() store.LogStore
- func (s *PostgresStore) Nodes() store.NodeStore
- func (s *PostgresStore) Orgs() store.OrgStore
- func (s *PostgresStore) Ping(ctx context.Context) error
- func (s *PostgresStore) Secrets() store.SecretStore
- func (s *PostgresStore) Settings() store.SettingsStore
- func (s *PostgresStore) Users() store.UserStore
- func (s *PostgresStore) WithTx(ctx context.Context, fn func(store.Store) error) error
- type SecretStore
- func (s *SecretStore) Delete(ctx context.Context, appID, key string) error
- func (s *SecretStore) Get(ctx context.Context, appID, key string) ([]byte, error)
- func (s *SecretStore) GetAll(ctx context.Context, appID string) (map[string][]byte, error)
- func (s *SecretStore) List(ctx context.Context, appID string) ([]string, error)
- func (s *SecretStore) Set(ctx context.Context, appID, key string, encryptedValue []byte) error
- type SettingsStore
- type UserStore
- func (s *UserStore) Authenticate(ctx context.Context, email, password string) (*store.User, error)
- func (s *UserStore) CountByRole(ctx context.Context, role store.Role) (int, error)
- func (s *UserStore) Create(ctx context.Context, email, password string, isAdmin bool) (*store.User, error)
- func (s *UserStore) CreateWithRole(ctx context.Context, email, password string, role store.Role, invitedBy string) (*store.User, error)
- func (s *UserStore) Delete(ctx context.Context, id string) error
- func (s *UserStore) GetByEmail(ctx context.Context, email string) (*store.User, error)
- func (s *UserStore) GetByID(ctx context.Context, id string) (*store.User, error)
- func (s *UserStore) GetFirstOwner(ctx context.Context) (*store.User, error)
- func (s *UserStore) List(ctx context.Context) ([]*store.User, error)
- func (s *UserStore) Update(ctx context.Context, user *store.User) error
Constants ¶
This section is empty.
Variables ¶
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.
type BuildStore ¶
type BuildStore struct {
// contains filtered or unexported fields
}
BuildStore implements store.BuildStore using PostgreSQL.
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) ListByUser ¶
ListByUser retrieves all builds for a given user across all apps.
func (*BuildStore) ListPending ¶
ListPending retrieves all pending build jobs.
func (*BuildStore) ListQueued ¶
ListQueued retrieves all builds with status 'queued'. Used for startup recovery to resume pending builds. **Validates: Requirements 15.1**
func (*BuildStore) ListRunning ¶
ListRunning retrieves all builds with status 'running'. Used for startup recovery to identify interrupted builds. **Validates: Requirements 15.1, 15.2**
type Config ¶
type Config struct {
DSN string
MaxOpenConns int
MaxIdleConns int
ConnMaxLifetime time.Duration
ConnMaxIdleTime time.Duration
}
Config holds PostgreSQL connection configuration.
func DefaultConfig ¶
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 ¶
func (s *DeploymentStore) Get(ctx context.Context, id string) (*models.Deployment, error)
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 ¶
func (s *GitHubAccountStore) Get(ctx context.Context, id int64) (*models.GitHubAccount, error)
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 ¶
func (s *InvitationStore) Get(ctx context.Context, id string) (*models.Invitation, error)
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 ¶
func (s *InvitationStore) List(ctx context.Context) ([]*models.Invitation, error)
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) DeleteOlderThan ¶
DeleteOlderThan removes log entries older than the specified timestamp.
type NodeStore ¶
type NodeStore struct {
// contains filtered or unexported fields
}
NodeStore implements store.NodeStore using PostgreSQL.
func (*NodeStore) ListHealthy ¶
ListHealthy retrieves all healthy nodes.
func (*NodeStore) ListWithClosure ¶
ListWithClosure retrieves nodes that have a specific store path cached.
func (*NodeStore) UpdateHealth ¶
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) GetDefault ¶
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) ListMembers ¶
ListMembers retrieves all members of an organization.
func (*OrgStore) RemoveMember ¶
RemoveMember removes a user from 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.
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.
type SettingsStore ¶
type SettingsStore struct {
// contains filtered or unexported fields
}
SettingsStore implements store.SettingsStore for PostgreSQL.
type UserStore ¶
type UserStore struct {
// contains filtered or unexported fields
}
UserStore implements store.UserStore using PostgreSQL.
func (*UserStore) Authenticate ¶
Authenticate verifies credentials and returns the user.
func (*UserStore) CountByRole ¶
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) GetByEmail ¶
GetByEmail retrieves a user by email.
func (*UserStore) GetFirstOwner ¶
GetFirstOwner returns the first user with owner role, if any.