aboutsummaryrefslogtreecommitdiffstats
path: root/src/database/mod.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-08-19 02:45:49 +0200
committersalmonik <salmonik@tuta.io>2026-08-19 02:45:49 +0200
commit850fad62f12b4e764f5e64036db35259237994cb (patch)
treed5b25e9c00f01e3fd19f47b0270a88e1e5f5576e /src/database/mod.rs
parentfeat: local TTS via piper subprocess with Google fallback (diff)
downloadsenator-sperma-850fad62f12b4e764f5e64036db35259237994cb.tar.gz
senator-sperma-850fad62f12b4e764f5e64036db35259237994cb.zip
fix: Various cron fixes
Not saving full URL Not using autocompletion content, just label
Diffstat (limited to '')
-rw-r--r--src/database/mod.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/database/mod.rs b/src/database/mod.rs
index e803da9..0674477 100644
--- a/src/database/mod.rs
+++ b/src/database/mod.rs
@@ -43,7 +43,7 @@ async fn run_migrations(pool: &DbPool) -> Result<()> {
43 43
44 sqlx::query( 44 sqlx::query(
45 "CREATE TABLE IF NOT EXISTS cron_jobs ( 45 "CREATE TABLE IF NOT EXISTS cron_jobs (
46 id INTEGER PRIMARY KEY AUTOINCREMENT, 46 id INTEGER PRIMARY KEY,
47 cron_expression TEXT NOT NULL, 47 cron_expression TEXT NOT NULL,
48 type TEXT NOT NULL CHECK(type IN ('audio', 'wiadomość')), 48 type TEXT NOT NULL CHECK(type IN ('audio', 'wiadomość')),
49 channel_id INTEGER NOT NULL, 49 channel_id INTEGER NOT NULL,
@@ -189,9 +189,24 @@ pub async fn add_cron_job(
189 audio_filename: Option<&str>, 189 audio_filename: Option<&str>,
190 message: Option<&str>, 190 message: Option<&str>,
191) -> Result<i64> { 191) -> Result<i64> {
192 // Find the lowest unused ID to reuse freed slots
193 let existing: Vec<i64> = sqlx::query_scalar("SELECT id FROM cron_jobs ORDER BY id")
194 .fetch_all(pool)
195 .await?;
196
197 let next_id = existing.iter().enumerate().find_map(|(i, &id)| {
198 let expected = (i as i64) + 1;
199 if id != expected {
200 Some(expected)
201 } else {
202 None
203 }
204 }).unwrap_or(existing.len() as i64 + 1);
205
192 let result = sqlx::query( 206 let result = sqlx::query(
193 "INSERT INTO cron_jobs (cron_expression, type, channel_id, audio_filename, message) VALUES (?, ?, ?, ?, ?)", 207 "INSERT INTO cron_jobs (id, cron_expression, type, channel_id, audio_filename, message) VALUES (?, ?, ?, ?, ?, ?)",
194 ) 208 )
209 .bind(next_id)
195 .bind(cron_expression) 210 .bind(cron_expression)
196 .bind(r#type) 211 .bind(r#type)
197 .bind(channel_id) 212 .bind(channel_id)