Documentation
¶
Overview ¶
Package databases manages Postgres and Redis database provisioning.
Index ¶
- func ValidateName(name string) error
- type CreateRequest
- type Database
- type Manager
- func (m *Manager) Create(ctx context.Context, tenantID string, req CreateRequest) (*Database, error)
- func (m *Manager) Delete(ctx context.Context, tenantID, dbID string) error
- func (m *Manager) Get(ctx context.Context, tenantID, dbID string) (*Database, error)
- func (m *Manager) GetConnectionString(ctx context.Context, tenantID, dbID string) (string, error)
- func (m *Manager) List(ctx context.Context, tenantID string) ([]*Database, error)
- func (m *Manager) ListPaginated(ctx context.Context, tenantID string, limit, offset int) ([]*Database, error)
- func (m *Manager) ReconcileStale()
- func (m *Manager) StartAllForTenant(ctx context.Context, tenantID string)
- func (m *Manager) StopAllForTenant(ctx context.Context, tenantID string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateName ¶
ValidateName checks that a database name is safe for use as a Docker container/volume suffix: 1-63 characters, starts with a letter, only alphanumeric plus hyphens/underscores, cannot end with a hyphen.
Types ¶
type CreateRequest ¶
type CreateRequest struct {
Name string `json:"name"`
Type string `json:"type"` // "postgres" or "redis"
}
CreateRequest holds parameters for creating a database.
type Database ¶
type Database struct {
ID string `json:"id"`
TenantID string `json:"tenant_id"`
Name string `json:"name"`
Type string `json:"type"`
Status string `json:"status"`
ContainerID string `json:"-"`
Host string `json:"host,omitempty"`
Port int `json:"port,omitempty"`
DBName string `json:"db_name,omitempty"`
Username string `json:"username,omitempty"`
ConnectionString string `json:"connection_string,omitempty"` // only populated on create + explicit get
VolumeName string `json:"-"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
Database represents a provisioned database.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages database lifecycle.
func NewManager ¶
NewManager creates a database manager.
func (*Manager) Create ¶
func (m *Manager) Create(ctx context.Context, tenantID string, req CreateRequest) (*Database, error)
Create provisions a new database.
func (*Manager) Delete ¶
Delete destroys a database: stops container, removes volume, deletes record. Only deletes the DB record after Docker cleanup succeeds to avoid orphaning resources.
func (*Manager) Get ¶
Get returns a database by ID, scoped to tenant. Connection string NOT included.
func (*Manager) GetConnectionString ¶
GetConnectionString returns the decrypted connection string.
func (*Manager) ListPaginated ¶
func (m *Manager) ListPaginated(ctx context.Context, tenantID string, limit, offset int) ([]*Database, error)
ListPaginated returns databases for a tenant with limit and offset.
func (*Manager) ReconcileStale ¶
func (m *Manager) ReconcileStale()
ReconcileStale marks databases stuck in "provisioning" as "failed" and attempts to clean up their Docker resources. Called on startup.
func (*Manager) StartAllForTenant ¶
StartAllForTenant recreates the containers of a tenant's stopped databases (see StopAllForTenant) from the stored config, reusing each database's volume, port and password. Failures mark that database "failed" and are logged; the remaining databases are still processed.
func (*Manager) StopAllForTenant ¶
StopAllForTenant stops and removes all database containers for the tenant, updating each record's status to "stopped". The database records are kept so they can be restarted if the tenant is ever reactivated. Errors are logged but do not abort processing of remaining databases.