Documentation
¶
Overview ¶
Package state provides persistent StateStore implementations for the platform abstraction layer. It includes SQLite for single-node/local development and PostgreSQL for production multi-node deployments.
Index ¶
- type DriftReport
- type SQLiteStore
- func (s *SQLiteStore) AddDependency(ctx context.Context, dep platform.DependencyRef) error
- func (s *SQLiteStore) Close() error
- func (s *SQLiteStore) DeleteResource(ctx context.Context, contextPath, resourceName string) error
- func (s *SQLiteStore) Dependencies(ctx context.Context, contextPath, resourceName string) ([]platform.DependencyRef, error)
- func (s *SQLiteStore) GetPlan(ctx context.Context, planID string) (*platform.Plan, error)
- func (s *SQLiteStore) GetResource(ctx context.Context, contextPath, resourceName string) (*platform.ResourceOutput, error)
- func (s *SQLiteStore) ListDriftReports(ctx context.Context, contextPath string, limit int) ([]*DriftReport, error)
- func (s *SQLiteStore) ListPlans(ctx context.Context, contextPath string, limit int) ([]*platform.Plan, error)
- func (s *SQLiteStore) ListResources(ctx context.Context, contextPath string) ([]*platform.ResourceOutput, error)
- func (s *SQLiteStore) Lock(ctx context.Context, contextPath string, ttl time.Duration) (platform.LockHandle, error)
- func (s *SQLiteStore) SaveDriftReport(ctx context.Context, report *DriftReport) error
- func (s *SQLiteStore) SavePlan(ctx context.Context, plan *platform.Plan) error
- func (s *SQLiteStore) SaveResource(ctx context.Context, contextPath string, output *platform.ResourceOutput) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DriftReport ¶
type DriftReport struct {
// ID is the database identifier (set after save).
ID int64 `json:"id"`
// ContextPath is the hierarchical context path of the resource.
ContextPath string `json:"contextPath"`
// ResourceName is the name of the resource that drifted.
ResourceName string `json:"resourceName"`
// ResourceType is the provider-specific resource type.
ResourceType string `json:"resourceType"`
// Tier is the infrastructure tier the resource belongs to.
Tier platform.Tier `json:"tier"`
// DriftType classifies the drift: "changed", "added", "removed".
DriftType string `json:"driftType"`
// Expected is the desired state properties from the state store.
Expected map[string]any `json:"expected"`
// Actual is the live state properties read from the provider.
Actual map[string]any `json:"actual"`
// Diffs contains the individual field differences.
Diffs []platform.DiffEntry `json:"diffs"`
// DetectedAt is when the drift was detected.
DetectedAt time.Time `json:"detectedAt"`
// ResolvedAt is when the drift was remediated (nil if unresolved).
ResolvedAt *time.Time `json:"resolvedAt,omitempty"`
// ResolvedBy identifies who or what resolved the drift.
ResolvedBy string `json:"resolvedBy,omitempty"`
}
DriftReport represents the result of a drift detection check for a single resource.
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
SQLiteStore implements platform.StateStore using an SQLite database. It is suitable for single-node deployments and local development.
func NewSQLiteStore ¶
func NewSQLiteStore(dsn string) (*SQLiteStore, error)
NewSQLiteStore creates a new SQLite-backed state store. The dsn parameter is the path to the SQLite database file. Use ":memory:" for an in-memory database (useful for testing).
func (*SQLiteStore) AddDependency ¶
func (s *SQLiteStore) AddDependency(ctx context.Context, dep platform.DependencyRef) error
AddDependency records a cross-resource or cross-tier dependency.
func (*SQLiteStore) Close ¶
func (s *SQLiteStore) Close() error
Close closes the underlying database connection.
func (*SQLiteStore) DeleteResource ¶
func (s *SQLiteStore) DeleteResource(ctx context.Context, contextPath, resourceName string) error
DeleteResource removes a resource from state.
func (*SQLiteStore) Dependencies ¶
func (s *SQLiteStore) Dependencies(ctx context.Context, contextPath, resourceName string) ([]platform.DependencyRef, error)
Dependencies returns dependency references for resources that depend on the given resource.
func (*SQLiteStore) GetResource ¶
func (s *SQLiteStore) GetResource(ctx context.Context, contextPath, resourceName string) (*platform.ResourceOutput, error)
GetResource retrieves a resource's state by context path and resource name.
func (*SQLiteStore) ListDriftReports ¶
func (s *SQLiteStore) ListDriftReports(ctx context.Context, contextPath string, limit int) ([]*DriftReport, error)
ListDriftReports returns drift reports for a context path, ordered by detection time descending.
func (*SQLiteStore) ListPlans ¶
func (s *SQLiteStore) ListPlans(ctx context.Context, contextPath string, limit int) ([]*platform.Plan, error)
ListPlans lists plans for a context path, ordered by creation time descending.
func (*SQLiteStore) ListResources ¶
func (s *SQLiteStore) ListResources(ctx context.Context, contextPath string) ([]*platform.ResourceOutput, error)
ListResources returns all resources in a context path.
func (*SQLiteStore) Lock ¶
func (s *SQLiteStore) Lock(ctx context.Context, contextPath string, ttl time.Duration) (platform.LockHandle, error)
Lock acquires an advisory lock for a context path. SQLite advisory locks are emulated using a database row and a process-level mutex.
func (*SQLiteStore) SaveDriftReport ¶
func (s *SQLiteStore) SaveDriftReport(ctx context.Context, report *DriftReport) error
SaveDriftReport persists a drift detection report.
func (*SQLiteStore) SaveResource ¶
func (s *SQLiteStore) SaveResource(ctx context.Context, contextPath string, output *platform.ResourceOutput) error
SaveResource persists the state of a resource within a context path.