This commit is contained in:
Mateusz Gruszczyński
2026-09-01 22:20:10 +02:00
parent 1cb62c8d0b
commit 16e0d94564
47 changed files with 2565 additions and 117 deletions
+6 -1
View File
@@ -1,7 +1,7 @@
impl Db {
pub fn export_configuration(&self, settings: RuntimeSettings) -> Result<ConfigurationExport> {
Ok(ConfigurationExport {
format_version: 1,
format_version: 2,
exported_at: Utc::now(),
settings,
devices: self.list_devices()?,
@@ -9,6 +9,7 @@ impl Db {
groups: self.list_groups()?,
schedules: self.list_schedules()?,
automations: self.list_automations()?,
flows: self.list_flows()?,
})
}
@@ -36,6 +37,10 @@ impl Db {
let payload = Self::to_json(item)?;
tx.execute(queries::UPSERT_AUTOMATION, params![item.id, payload, item.updated_at.to_rfc3339()])?;
}
for flow in &export.flows {
let payload = Self::to_json(flow)?;
tx.execute(queries::UPSERT_FLOW, params![flow.id, payload, flow.updated_at.to_rfc3339()])?;
}
let settings_json = Self::to_json(&export.settings)?;
tx.execute(queries::UPSERT_RUNTIME_SETTINGS, params![settings_json, Utc::now().to_rfc3339()])?;
tx.commit()?;
+38
View File
@@ -0,0 +1,38 @@
impl Db {
pub fn list_flows(&self) -> Result<Vec<Flow>> {
self.list_payloads(queries::LIST_FLOWS)
}
pub fn get_flow(&self, id: &str) -> Result<Option<Flow>> {
self.get_payload(queries::GET_FLOW, id)
}
pub fn replace_flow_outputs(&self, flow: &Flow, schedules: &[Schedule], automations: &[Automation]) -> Result<()> {
let mut conn = self.lock()?;
let tx = conn.transaction()?;
tx.execute(queries::DELETE_SCHEDULES_BY_FLOW_ID, [flow.id.as_str()])?;
tx.execute(queries::DELETE_AUTOMATIONS_BY_FLOW_ID, [flow.id.as_str()])?;
for schedule in schedules {
let payload = Self::to_json(schedule)?;
tx.execute(queries::UPSERT_SCHEDULE, params![schedule.id, schedule.zone_id, payload, schedule.updated_at.to_rfc3339()])?;
}
for item in automations {
let payload = Self::to_json(item)?;
tx.execute(queries::UPSERT_AUTOMATION, params![item.id, payload, item.updated_at.to_rfc3339()])?;
}
let payload = Self::to_json(flow)?;
tx.execute(queries::UPSERT_FLOW, params![flow.id, payload, flow.updated_at.to_rfc3339()])?;
tx.commit()?;
Ok(())
}
pub fn delete_flow(&self, id: &str) -> Result<bool> {
let mut conn = self.lock()?;
let tx = conn.transaction()?;
tx.execute(queries::DELETE_SCHEDULES_BY_FLOW_ID, [id])?;
tx.execute(queries::DELETE_AUTOMATIONS_BY_FLOW_ID, [id])?;
let changed = tx.execute(queries::DELETE_FLOW, [id])? > 0;
tx.commit()?;
Ok(changed)
}
}