Add version to controller in db

This commit is contained in:
Tobias Reisinger 2026-09-02 01:31:55 +02:00
commit 9a9192213a
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
11 changed files with 57 additions and 19 deletions

View file

@ -17,6 +17,7 @@ pub struct DbController {
pub name: String,
pub relay_count: i64,
pub active: bool,
pub version: String,
}
impl DbController {
@ -58,10 +59,11 @@ impl DbController {
uid: &EmgauwaUid,
new_name: &str,
new_relay_count: i64,
new_version: &str,
) -> Result<DbController, DatabaseError> {
match DbController::get_by_uid(conn, uid).await? {
Some(tag) => Ok(tag),
None => DbController::create(conn, uid, new_name, new_relay_count).await,
None => DbController::create(conn, uid, new_name, new_relay_count, new_version).await,
}
}
@ -102,13 +104,15 @@ impl DbController {
new_uid: &EmgauwaUid,
new_name: &str,
new_relay_count: i64,
new_version: &str,
) -> Result<DbController, DatabaseError> {
sqlx::query_as!(
DbController,
"INSERT INTO controllers (uid, name, relay_count) VALUES (?, ?, ?) RETURNING *",
"INSERT INTO controllers (uid, name, relay_count, version) VALUES (?, ?, ?, ?) RETURNING *",
new_uid,
new_name,
new_relay_count,
new_version,
)
.fetch_optional(conn.deref_mut())
.await?
@ -120,11 +124,13 @@ impl DbController {
conn: &mut PoolConnection<Sqlite>,
new_name: &str,
new_relay_count: i64,
new_version: &str,
) -> Result<DbController, DatabaseError> {
sqlx::query!(
"UPDATE controllers SET name = ?, relay_count = ? WHERE id = ?",
"UPDATE controllers SET name = ?, relay_count = ?, version = ? WHERE id = ?",
new_name,
new_relay_count,
new_version,
self.id,
)
.execute(conn.deref_mut())

View file

@ -116,4 +116,4 @@ pub fn printable_relay_states(relay_states: &RelayStates) -> String {
});
});
relay_debug
}
}