pub struct StateStore { /* private fields */ }Expand description
SQLite-backed state store for cfgd.
Implementations§
Source§impl StateStore
impl StateStore
Sourcepub fn open_default() -> Result<Self>
pub fn open_default() -> Result<Self>
Open or create a state store at the default location.
Uses ~/.local/share/cfgd/state.db.
Sourcepub fn open_in_memory() -> Result<Self>
pub fn open_in_memory() -> Result<Self>
Create an in-memory state store (for testing).
Sourcepub fn record_apply(
&self,
profile: &str,
plan_hash: &str,
status: ApplyStatus,
summary: Option<&str>,
) -> Result<i64>
pub fn record_apply( &self, profile: &str, plan_hash: &str, status: ApplyStatus, summary: Option<&str>, ) -> Result<i64>
Record a completed apply operation.
Sourcepub fn record_drift(
&self,
resource_type: &str,
resource_id: &str,
expected: Option<&str>,
actual: Option<&str>,
source: &str,
) -> Result<i64>
pub fn record_drift( &self, resource_type: &str, resource_id: &str, expected: Option<&str>, actual: Option<&str>, source: &str, ) -> Result<i64>
Record a drift event.
Sourcepub fn resolve_drift(
&self,
apply_id: i64,
resource_type: &str,
resource_id: &str,
) -> Result<()>
pub fn resolve_drift( &self, apply_id: i64, resource_type: &str, resource_id: &str, ) -> Result<()>
Resolve drift events by linking them to an apply.
Sourcepub fn upsert_managed_resource(
&self,
resource_type: &str,
resource_id: &str,
source: &str,
hash: Option<&str>,
apply_id: Option<i64>,
) -> Result<()>
pub fn upsert_managed_resource( &self, resource_type: &str, resource_id: &str, source: &str, hash: Option<&str>, apply_id: Option<i64>, ) -> Result<()>
Upsert a managed resource record.
Sourcepub fn is_resource_managed(
&self,
resource_type: &str,
resource_id: &str,
) -> Result<bool>
pub fn is_resource_managed( &self, resource_type: &str, resource_id: &str, ) -> Result<bool>
Check if a resource is tracked in managed_resources.
Sourcepub fn last_apply(&self) -> Result<Option<ApplyRecord>>
pub fn last_apply(&self) -> Result<Option<ApplyRecord>>
Get the most recent apply record.
Sourcepub fn get_apply(&self, apply_id: i64) -> Result<Option<ApplyRecord>>
pub fn get_apply(&self, apply_id: i64) -> Result<Option<ApplyRecord>>
Get a specific apply record by ID.
Sourcepub fn history(&self, limit: u32) -> Result<Vec<ApplyRecord>>
pub fn history(&self, limit: u32) -> Result<Vec<ApplyRecord>>
Get apply history (most recent first), limited to limit entries.
Sourcepub fn managed_resources(&self) -> Result<Vec<ManagedResource>>
pub fn managed_resources(&self) -> Result<Vec<ManagedResource>>
Get all managed resources.
Sourcepub fn unresolved_drift(&self) -> Result<Vec<DriftEvent>>
pub fn unresolved_drift(&self) -> Result<Vec<DriftEvent>>
Get unresolved drift events.
Sourcepub fn upsert_config_source(
&self,
name: &str,
origin_url: &str,
origin_branch: &str,
last_commit: Option<&str>,
source_version: Option<&str>,
pinned_version: Option<&str>,
) -> Result<i64>
pub fn upsert_config_source( &self, name: &str, origin_url: &str, origin_branch: &str, last_commit: Option<&str>, source_version: Option<&str>, pinned_version: Option<&str>, ) -> Result<i64>
Upsert a config source record.
Sourcepub fn config_sources(&self) -> Result<Vec<ConfigSourceRecord>>
pub fn config_sources(&self) -> Result<Vec<ConfigSourceRecord>>
Get all config sources.
Sourcepub fn config_source_by_name(
&self,
name: &str,
) -> Result<Option<ConfigSourceRecord>>
pub fn config_source_by_name( &self, name: &str, ) -> Result<Option<ConfigSourceRecord>>
Get a config source by name.
Sourcepub fn remove_config_source(&self, name: &str) -> Result<()>
pub fn remove_config_source(&self, name: &str) -> Result<()>
Remove a config source from state.
Sourcepub fn update_config_source_status(
&self,
name: &str,
status: &str,
) -> Result<()>
pub fn update_config_source_status( &self, name: &str, status: &str, ) -> Result<()>
Update the status of a config source.
Sourcepub fn record_source_apply(
&self,
source_name: &str,
apply_id: i64,
source_commit: &str,
) -> Result<()>
pub fn record_source_apply( &self, source_name: &str, apply_id: i64, source_commit: &str, ) -> Result<()>
Record a source apply (links a source’s commit to an apply).
Sourcepub fn record_source_conflict(
&self,
source_name: &str,
resource_type: &str,
resource_id: &str,
resolution: &str,
detail: Option<&str>,
) -> Result<()>
pub fn record_source_conflict( &self, source_name: &str, resource_type: &str, resource_id: &str, resolution: &str, detail: Option<&str>, ) -> Result<()>
Record a composition conflict.
Sourcepub fn upsert_pending_decision(
&self,
source: &str,
resource: &str,
tier: &str,
action: &str,
summary: &str,
) -> Result<i64>
pub fn upsert_pending_decision( &self, source: &str, resource: &str, tier: &str, action: &str, summary: &str, ) -> Result<i64>
Upsert a pending decision. If an unresolved decision already exists for this (source, resource) pair, updates the summary and resets the timestamp.
Sourcepub fn pending_decisions(&self) -> Result<Vec<PendingDecision>>
pub fn pending_decisions(&self) -> Result<Vec<PendingDecision>>
Get all unresolved pending decisions.
Sourcepub fn pending_decisions_for_source(
&self,
source: &str,
) -> Result<Vec<PendingDecision>>
pub fn pending_decisions_for_source( &self, source: &str, ) -> Result<Vec<PendingDecision>>
Get pending decisions for a specific source.
Sourcepub fn resolve_decision(&self, resource: &str, resolution: &str) -> Result<bool>
pub fn resolve_decision(&self, resource: &str, resolution: &str) -> Result<bool>
Resolve a pending decision by resource path.
Sourcepub fn resolve_decisions_for_source(
&self,
source: &str,
resolution: &str,
) -> Result<usize>
pub fn resolve_decisions_for_source( &self, source: &str, resolution: &str, ) -> Result<usize>
Resolve all pending decisions for a source.
Sourcepub fn resolve_all_decisions(&self, resolution: &str) -> Result<usize>
pub fn resolve_all_decisions(&self, resolution: &str) -> Result<usize>
Resolve all pending decisions.
Sourcepub fn source_config_hash(
&self,
source: &str,
) -> Result<Option<SourceConfigHash>>
pub fn source_config_hash( &self, source: &str, ) -> Result<Option<SourceConfigHash>>
Get the stored config hash for a source.
Sourcepub fn set_source_config_hash(
&self,
source: &str,
config_hash: &str,
) -> Result<()>
pub fn set_source_config_hash( &self, source: &str, config_hash: &str, ) -> Result<()>
Upsert a source config hash.
Sourcepub fn remove_source_config_hash(&self, source: &str) -> Result<()>
pub fn remove_source_config_hash(&self, source: &str) -> Result<()>
Remove the config hash for a source.
Sourcepub fn managed_resources_by_source(
&self,
source_name: &str,
) -> Result<Vec<ManagedResource>>
pub fn managed_resources_by_source( &self, source_name: &str, ) -> Result<Vec<ManagedResource>>
Get managed resources from a specific source.
Sourcepub fn upsert_module_state(
&self,
module_name: &str,
last_applied: Option<i64>,
packages_hash: &str,
files_hash: &str,
git_sources: Option<&str>,
status: &str,
) -> Result<()>
pub fn upsert_module_state( &self, module_name: &str, last_applied: Option<i64>, packages_hash: &str, files_hash: &str, git_sources: Option<&str>, status: &str, ) -> Result<()>
Insert or update module state.
Sourcepub fn module_states(&self) -> Result<Vec<ModuleStateRecord>>
pub fn module_states(&self) -> Result<Vec<ModuleStateRecord>>
Get all module states.
Sourcepub fn module_state_by_name(
&self,
module_name: &str,
) -> Result<Option<ModuleStateRecord>>
pub fn module_state_by_name( &self, module_name: &str, ) -> Result<Option<ModuleStateRecord>>
Get module state by name.
Sourcepub fn remove_module_state(&self, module_name: &str) -> Result<()>
pub fn remove_module_state(&self, module_name: &str) -> Result<()>
Remove module state by name.
Sourcepub fn store_file_backup(
&self,
apply_id: i64,
file_path: &str,
state: &FileState,
) -> Result<()>
pub fn store_file_backup( &self, apply_id: i64, file_path: &str, state: &FileState, ) -> Result<()>
Store a file backup before overwriting.
Sourcepub fn get_file_backup(
&self,
apply_id: i64,
file_path: &str,
) -> Result<Option<FileBackupRecord>>
pub fn get_file_backup( &self, apply_id: i64, file_path: &str, ) -> Result<Option<FileBackupRecord>>
Get a file backup by apply_id and path.
Sourcepub fn get_apply_backups(&self, apply_id: i64) -> Result<Vec<FileBackupRecord>>
pub fn get_apply_backups(&self, apply_id: i64) -> Result<Vec<FileBackupRecord>>
Get all file backups for a specific apply (for full rollback).
Sourcepub fn latest_backup_for_path(
&self,
file_path: &str,
) -> Result<Option<FileBackupRecord>>
pub fn latest_backup_for_path( &self, file_path: &str, ) -> Result<Option<FileBackupRecord>>
Get the most recent backup for a file path (for restore after removal).
Sourcepub fn file_backups_after_apply(
&self,
after_apply_id: i64,
) -> Result<Vec<FileBackupRecord>>
pub fn file_backups_after_apply( &self, after_apply_id: i64, ) -> Result<Vec<FileBackupRecord>>
Get the earliest file backup for each unique file path from applies after the given ID. This captures the state that existed right after the target apply completed, for each file that was subsequently modified. Used by rollback to restore to a prior apply’s state.
Sourcepub fn journal_entries_after_apply(
&self,
after_apply_id: i64,
) -> Result<Vec<JournalEntry>>
pub fn journal_entries_after_apply( &self, after_apply_id: i64, ) -> Result<Vec<JournalEntry>>
Get all journal entries from applies after the given ID, for rollback tracking.
Sourcepub fn prune_old_backups(&self, keep_last_n: usize) -> Result<usize>
pub fn prune_old_backups(&self, keep_last_n: usize) -> Result<usize>
Prune old backups, keeping only the last N applies’ worth.
Sourcepub fn journal_begin(
&self,
apply_id: i64,
action_index: usize,
phase: &str,
action_type: &str,
resource_id: &str,
pre_state: Option<&str>,
) -> Result<i64>
pub fn journal_begin( &self, apply_id: i64, action_index: usize, phase: &str, action_type: &str, resource_id: &str, pre_state: Option<&str>, ) -> Result<i64>
Record the start of a journal action.
Sourcepub fn journal_complete(
&self,
journal_id: i64,
post_state: Option<&str>,
script_output: Option<&str>,
) -> Result<()>
pub fn journal_complete( &self, journal_id: i64, post_state: Option<&str>, script_output: Option<&str>, ) -> Result<()>
Mark a journal action as completed, optionally storing script output.
Sourcepub fn journal_fail(&self, journal_id: i64, error: &str) -> Result<()>
pub fn journal_fail(&self, journal_id: i64, error: &str) -> Result<()>
Mark a journal action as failed.
Sourcepub fn journal_completed_actions(
&self,
apply_id: i64,
) -> Result<Vec<JournalEntry>>
pub fn journal_completed_actions( &self, apply_id: i64, ) -> Result<Vec<JournalEntry>>
Get completed actions for an apply (for rollback).
Sourcepub fn journal_entries(&self, apply_id: i64) -> Result<Vec<JournalEntry>>
pub fn journal_entries(&self, apply_id: i64) -> Result<Vec<JournalEntry>>
Get all journal entries for an apply (all statuses).
Sourcepub fn upsert_module_file(
&self,
module_name: &str,
file_path: &str,
content_hash: &str,
strategy: &str,
apply_id: i64,
) -> Result<()>
pub fn upsert_module_file( &self, module_name: &str, file_path: &str, content_hash: &str, strategy: &str, apply_id: i64, ) -> Result<()>
Record a file deployed by a module.
Sourcepub fn module_deployed_files(
&self,
module_name: &str,
) -> Result<Vec<ModuleFileRecord>>
pub fn module_deployed_files( &self, module_name: &str, ) -> Result<Vec<ModuleFileRecord>>
Get all files deployed by a module.
Sourcepub fn delete_module_files(&self, module_name: &str) -> Result<()>
pub fn delete_module_files(&self, module_name: &str) -> Result<()>
Delete all manifest entries for a module.
Sourcepub fn update_apply_status(
&self,
apply_id: i64,
status: ApplyStatus,
summary: Option<&str>,
) -> Result<()>
pub fn update_apply_status( &self, apply_id: i64, status: ApplyStatus, summary: Option<&str>, ) -> Result<()>
Update apply status (for changing “in-progress” to final status).
Sourcepub fn store_compliance_snapshot(
&self,
snapshot: &ComplianceSnapshot,
hash: &str,
) -> Result<()>
pub fn store_compliance_snapshot( &self, snapshot: &ComplianceSnapshot, hash: &str, ) -> Result<()>
Store a compliance snapshot. The caller provides the content hash
(typically sha256_hex of the serialized JSON).
Sourcepub fn latest_compliance_hash(&self) -> Result<Option<String>>
pub fn latest_compliance_hash(&self) -> Result<Option<String>>
Get the content hash of the most recently stored compliance snapshot.
Sourcepub fn compliance_history(
&self,
since: Option<&str>,
limit: u32,
) -> Result<Vec<ComplianceHistoryRow>>
pub fn compliance_history( &self, since: Option<&str>, limit: u32, ) -> Result<Vec<ComplianceHistoryRow>>
Get compliance snapshot history as summary rows.
If since is provided, only return snapshots after that ISO 8601 timestamp.
Sourcepub fn get_compliance_snapshot(
&self,
id: i64,
) -> Result<Option<ComplianceSnapshot>>
pub fn get_compliance_snapshot( &self, id: i64, ) -> Result<Option<ComplianceSnapshot>>
Retrieve a full compliance snapshot by ID.
Sourcepub fn prune_compliance_snapshots(
&self,
before_timestamp: &str,
) -> Result<usize>
pub fn prune_compliance_snapshots( &self, before_timestamp: &str, ) -> Result<usize>
Remove compliance snapshots older than the given ISO 8601 timestamp. Returns the number of rows deleted.