aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakobst1n <jakob@jakobstendahl.no>2023-09-08 19:40:42 +0200
committerjakobst1n <jakob.stendahl@outlook.com>2023-09-08 19:40:49 +0200
commit4d9bc3406cb001bd239fdd2e9c66d255b0a56bdf (patch)
treed6a2ef08b9ed774f011e427be9e9daf0d82d9e54
parent617bb0662f85f4c6c0f78fe39d5a33a2bd9a8b61 (diff)
downloadRSS-watcher-4d9bc3406cb001bd239fdd2e9c66d255b0a56bdf.tar.gz
RSS-watcher-4d9bc3406cb001bd239fdd2e9c66d255b0a56bdf.zip
Change to allow the `version` column to have id 0 or 1, remove sql_mode setting (#2)
-rw-r--r--src/database.rs12
1 files 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<Option<i64>> = 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<Vec<FeedConf>> {
`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}