From 074ddd3893bd373048050ef912af51aeb3c66178 Mon Sep 17 00:00:00 2001 From: jakobst1n Date: Fri, 8 Sep 2023 18:49:10 +0200 Subject: Remove database in query, as that should be configurable (#2) --- Cargo.toml | 2 +- src/database.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e30a97c..dfbf227 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rss-watcher" -version = "0.3.1" +version = "0.3.2" edition = "2021" [dependencies] diff --git a/src/database.rs b/src/database.rs index 67157ae..cd097eb 100644 --- a/src/database.rs +++ b/src/database.rs @@ -120,7 +120,7 @@ fn run_migrations_v2(tx: &mut Transaction, version: i64) { if version < 2 { warn!("Running migrations to v2"); let mut q; - q = "ALTER TABLE `rss_watcher`.`rss-watcher-feeds` \ + q = "ALTER TABLE `rss-watcher-feeds` \ CHANGE COLUMN `title` `title` VARCHAR(255) NOT NULL DEFAULT '{{title}}: {{entry.title}}' , \ CHANGE COLUMN `message` `message` VARCHAR(255) NOT NULL DEFAULT '{{entry.summary}}';"; -- cgit v1.2.3 From 617bb0662f85f4c6c0f78fe39d5a33a2bd9a8b61 Mon Sep 17 00:00:00 2001 From: jakobst1n Date: Fri, 8 Sep 2023 19:06:07 +0200 Subject: Add query which sets sql_mode for the version row to be inserted (#2) --- Cargo.lock | 2 +- src/database.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index d6f81d2..07dc10b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1585,7 +1585,7 @@ dependencies = [ [[package]] name = "rss-watcher" -version = "0.1.0" +version = "0.3.2" dependencies = [ "chrono", "env_logger", diff --git a/src/database.rs b/src/database.rs index cd097eb..83d3fea 100644 --- a/src/database.rs +++ b/src/database.rs @@ -75,6 +75,10 @@ fn table_create(conn: &mut Conn) { error!("Could not create table! ({:#?}", x); process::exit(1); } + if let Err(x) = tx.query_drop("SET SESSION sql_mode='NO_AUTO_VALUE_ON_ZERO'") { + error!("Could not set NO_AUTO_VALUE_ON_ZERO sql_mode for session, you might have to change the id of this row manually from 1 to 0! ({:#?}", x); + process::exit(1); + } q = "INSERT INTO `rss-watcher-feeds` (id, url, last_fetch, -- cgit v1.2.3 From 4d9bc3406cb001bd239fdd2e9c66d255b0a56bdf Mon Sep 17 00:00:00 2001 From: jakobst1n Date: Fri, 8 Sep 2023 19:40:42 +0200 Subject: Change to allow the `version` column to have id 0 or 1, remove sql_mode setting (#2) --- src/database.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/database.rs b/src/database.rs index 83d3fea..2cd3c3f 100644 --- a/src/database.rs +++ b/src/database.rs @@ -75,10 +75,6 @@ fn table_create(conn: &mut Conn) { error!("Could not create table! ({:#?}", x); process::exit(1); } - if let Err(x) = tx.query_drop("SET SESSION sql_mode='NO_AUTO_VALUE_ON_ZERO'") { - error!("Could not set NO_AUTO_VALUE_ON_ZERO sql_mode for session, you might have to change the id of this row manually from 1 to 0! ({:#?}", x); - process::exit(1); - } q = "INSERT INTO `rss-watcher-feeds` (id, url, last_fetch, @@ -102,7 +98,7 @@ fn table_create(conn: &mut Conn) { * Select the row in the table describing the database version. */ fn get_db_version(conn: &mut Conn) -> i64 { - let q = "SELECT `last_fetch` from `rss-watcher-feeds` WHERE `id`=0 AND `url` LIKE 'version'"; + let q = "SELECT `last_fetch` from `rss-watcher-feeds` WHERE (`id`=0 OR `id`=1) AND `url` LIKE 'version'"; let res: Result> = conn.query_first(q); if let Err(x) = res { error!("Could not get current version from database ({:#?})...", x); @@ -110,7 +106,7 @@ fn get_db_version(conn: &mut Conn) -> i64 { } let res_res = res.unwrap(); if let None = res_res { - error!("Row with id=0 and url='version' does not exist, something is wrong!"); + error!("Row with (id=0 or id=1) and url='version' does not exist, something is wrong!"); error!("Please fix your database manually!"); process::exit(1); } @@ -133,7 +129,7 @@ fn run_migrations_v2(tx: &mut Transaction, version: i64) { process::exit(1); } - q = "UPDATE `rss-watcher-feeds` SET `last_fetch`=2 WHERE `id`=0"; + q = "UPDATE `rss-watcher-feeds` SET `last_fetch`=2 WHERE (`id`=0 OR `id`=1) AND `url` LIKE 'version' "; if let Err(x) = tx.query_drop(q) { error!("Could not run database migration to v2...! ({:#?}", x); process::exit(1); @@ -194,7 +190,7 @@ pub fn get_feeds(conn: &mut Conn) -> Option> { `push_url`, \ `push_token` \ FROM `rss-watcher-feeds` \ - WHERE id > 0"; + WHERE `url` NOT LIKE 'version'"; let res = conn.query_map(q, |(id,url,last_fetch,title,message,push_url,push_token)| { FeedConf{id,url,last_fetch,title,message,push_url,push_token} -- cgit v1.2.3