Skip to main content

StateStore

Struct StateStore 

Source
pub struct StateStore { /* private fields */ }
Expand description

SQLite-backed state store for cfgd.

Implementations§

Source§

impl StateStore

Source

pub fn open_default() -> Result<Self>

Open or create a state store at the default location. Uses ~/.local/share/cfgd/state.db.

Source

pub fn open(path: &Path) -> Result<Self>

Open or create a state store at the given path.

Source

pub fn open_in_memory() -> Result<Self>

Create an in-memory state store (for testing).

Source

pub fn record_apply( &self, profile: &str, plan_hash: &str, status: ApplyStatus, summary: Option<&str>, ) -> Result<i64>

Record a completed apply operation.

Source

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.

Source

pub fn resolve_drift( &self, apply_id: i64, resource_type: &str, resource_id: &str, ) -> Result<()>

Resolve drift events by linking them to an apply.

Source

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.

Source

pub fn is_resource_managed( &self, resource_type: &str, resource_id: &str, ) -> Result<bool>

Check if a resource is tracked in managed_resources.

Source

pub fn last_apply(&self) -> Result<Option<ApplyRecord>>

Get the most recent apply record.

Source

pub fn get_apply(&self, apply_id: i64) -> Result<Option<ApplyRecord>>

Get a specific apply record by ID.

Source

pub fn history(&self, limit: u32) -> Result<Vec<ApplyRecord>>

Get apply history (most recent first), limited to limit entries.

Source

pub fn managed_resources(&self) -> Result<Vec<ManagedResource>>

Get all managed resources.

Source

pub fn unresolved_drift(&self) -> Result<Vec<DriftEvent>>

Get unresolved drift events.

Source

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.

Source

pub fn config_sources(&self) -> Result<Vec<ConfigSourceRecord>>

Get all config sources.

Source

pub fn config_source_by_name( &self, name: &str, ) -> Result<Option<ConfigSourceRecord>>

Get a config source by name.

Source

pub fn remove_config_source(&self, name: &str) -> Result<()>

Remove a config source from state.

Source

pub fn update_config_source_status( &self, name: &str, status: &str, ) -> Result<()>

Update the status of a config source.

Source

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).

Source

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.

Source

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.

Source

pub fn pending_decisions(&self) -> Result<Vec<PendingDecision>>

Get all unresolved pending decisions.

Source

pub fn pending_decisions_for_source( &self, source: &str, ) -> Result<Vec<PendingDecision>>

Get pending decisions for a specific source.

Source

pub fn resolve_decision(&self, resource: &str, resolution: &str) -> Result<bool>

Resolve a pending decision by resource path.

Source

pub fn resolve_decisions_for_source( &self, source: &str, resolution: &str, ) -> Result<usize>

Resolve all pending decisions for a source.

Source

pub fn resolve_all_decisions(&self, resolution: &str) -> Result<usize>

Resolve all pending decisions.

Source

pub fn source_config_hash( &self, source: &str, ) -> Result<Option<SourceConfigHash>>

Get the stored config hash for a source.

Source

pub fn set_source_config_hash( &self, source: &str, config_hash: &str, ) -> Result<()>

Upsert a source config hash.

Source

pub fn remove_source_config_hash(&self, source: &str) -> Result<()>

Remove the config hash for a source.

Source

pub fn managed_resources_by_source( &self, source_name: &str, ) -> Result<Vec<ManagedResource>>

Get managed resources from a specific source.

Source

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.

Source

pub fn module_states(&self) -> Result<Vec<ModuleStateRecord>>

Get all module states.

Source

pub fn module_state_by_name( &self, module_name: &str, ) -> Result<Option<ModuleStateRecord>>

Get module state by name.

Source

pub fn remove_module_state(&self, module_name: &str) -> Result<()>

Remove module state by name.

Source

pub fn store_file_backup( &self, apply_id: i64, file_path: &str, state: &FileState, ) -> Result<()>

Store a file backup before overwriting.

Source

pub fn get_file_backup( &self, apply_id: i64, file_path: &str, ) -> Result<Option<FileBackupRecord>>

Get a file backup by apply_id and path.

Source

pub fn get_apply_backups(&self, apply_id: i64) -> Result<Vec<FileBackupRecord>>

Get all file backups for a specific apply (for full rollback).

Source

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).

Source

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.

Source

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.

Source

pub fn prune_old_backups(&self, keep_last_n: usize) -> Result<usize>

Prune old backups, keeping only the last N applies’ worth.

Source

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.

Source

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.

Source

pub fn journal_fail(&self, journal_id: i64, error: &str) -> Result<()>

Mark a journal action as failed.

Source

pub fn journal_completed_actions( &self, apply_id: i64, ) -> Result<Vec<JournalEntry>>

Get completed actions for an apply (for rollback).

Source

pub fn journal_entries(&self, apply_id: i64) -> Result<Vec<JournalEntry>>

Get all journal entries for an apply (all statuses).

Source

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.

Source

pub fn module_deployed_files( &self, module_name: &str, ) -> Result<Vec<ModuleFileRecord>>

Get all files deployed by a module.

Source

pub fn delete_module_files(&self, module_name: &str) -> Result<()>

Delete all manifest entries for a module.

Source

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).

Source

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).

Source

pub fn latest_compliance_hash(&self) -> Result<Option<String>>

Get the content hash of the most recently stored compliance snapshot.

Source

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.

Source

pub fn get_compliance_snapshot( &self, id: i64, ) -> Result<Option<ComplianceSnapshot>>

Retrieve a full compliance snapshot by ID.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more