From 7fccb7ce8d7513feb8bf1aa5476e0683b9e0c32c Mon Sep 17 00:00:00 2001 From: Ronan Date: Mon, 16 Sep 2024 20:40:39 +0200 Subject: [PATCH] do not add testuser permanently --- Cargo.toml | 4 +++- build.rs | 24 +++++++++++++++++++++++- db_v2.sqlite3 | Bin 348160 -> 352256 bytes db_v2/create/db.sql | 3 --- libs/state/src/database.rs | 5 ++++- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b2caa34..716c170 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,4 +33,6 @@ clap = { version = "4.5", features = ["derive"] } [build-dependencies] serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" \ No newline at end of file +serde_json = "1.0" +tokio = { version = "1", features = ["full"] } +sqlx = { version = "0.8", features = ["sqlite", "runtime-tokio-rustls", "macros", "chrono", "json"] } \ No newline at end of file diff --git a/build.rs b/build.rs index e68aa32..a06fb6d 100644 --- a/build.rs +++ b/build.rs @@ -13,6 +13,7 @@ // // You should have received a copy of the Affero General Public License // along with SCTGDesk. If not, see . +use sqlx::{Connection, Executor, SqliteConnection}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::env; @@ -50,7 +51,21 @@ impl PackageJson { self.version = version.to_string(); } } -fn main() { +#[tokio::main] +async fn main() { + let db_path = env::var("DATABASE_URL").unwrap_or("sqlite://db_v2.sqlite3".to_string()); + let mut conn = SqliteConnection::connect(&format!("sqlite://{}", db_path)) + .await + .expect("Failed to open database"); + conn.execute( + r#" + INSERT OR IGNORE INTO peer (guid, id, uuid, pk, created_at, "user", status, note, region, strategy, info, last_online) VALUES + (x'95CC7775BA37481DAD7214A4F6CE5A94', 'TESTUSER', randomblob(16), randomblob(16), '1901-01-01 12:00:00', randomblob(16), 0, '', NULL, randomblob(16), '{}', '1901-01-01 12:00:00'); + "# + ) + .await + .expect("Failed to insert test data"); + println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=webconsole"); let data = fs::read_to_string("./webconsole/package.json").unwrap(); @@ -103,4 +118,11 @@ fn main() { str::from_utf8(&output.stdout).unwrap_or(""), str::from_utf8(&output.stderr).unwrap_or("") ); + conn.execute( + r#" + DELETE FROM peer WHERE guid = x'95CC7775BA37481DAD7214A4F6CE5A94'; + "# + ) + .await + .expect("Failed to delete test data"); } diff --git a/db_v2.sqlite3 b/db_v2.sqlite3 index 0b1fb563bb368b56aec9fb99a2a0a17d3b897583..076cd026578ce1537c7579bdd9da08e331ec3ea8 100644 GIT binary patch delta 2677 zcmb_edrT8|9KYXPuh;h#p#cho<5gr9Y$?cavWXL-ykCOCCatt!3AET=0hz3*6HUu9 zT-|OH=NN82mMv3J$z)Mt-2RvgKB6&9R}J%zWttebjD$JEe#eat8Zpz^-nac+`}@8= z-$&ckujm?4Xv#|qEVP-bx7nMGG^I!62#O-hDGEUlF_cOuIZyzUlHD3TE=E#1T8^3e z$w-NK7$FalMY0DnMwTVLBkhrDBv&PNNrZTKFi74fcCD8Xc${9?ge}^Xd zo3+VeHK%G*(~`BB$+{(!?!~40jHRjRX~bk@qa@LAV1QBMUo>8E=MC$BIbWmbX#7f6 zjtlz^B)wBjJaiw@7p64oK5Fge9bUIaOyEJB{ocO4yNw&>nsq&sT`a+B5D|DHXV-Hi z8>@3VXj?N?*JLqU>A5bR=)pB#=$K}*Qb^#zoC|k;=N`J=_!NfcwY%>4dV!zv9j^16 zMxbHJZmzSnn(fcSf%dmb!XNls-jKK_1@8Lq#l*6%R`Cg3G0jN5L!4`MI{tUWF1AfD z@Az7rz(YC9_A_Y*8|*e`%kv;(TiIHk-?HImZ<5hzvdn4_*E9DvwxhQOBXAWL^tx-k z2@cwBq|FVRpC)eCe3Nqlt3v%`SBy`nTg;CoyZz<6Z9}(T(Ve6}K5TioOdO-{_+7T; zqBL)Hu(J8hbluQrt@QYr)gLM*viIc~CStToLly8FPH%p2KgD95&B!woLOimG;0BVA zod`KW-X(97*U0b5v*Zc#2)Up1lDo)GxN=@6T_Owz+_sT$kX;O74zjZ>;vhS7LJsbL zQzGCX+t9=`oNhrr2icy%Imi~7$3eCz7zbGfQ6Yv47u568Va@|`>Uar{;=^5vkau8Q zKa!CVm`YQTQ(m#AJg4lvAKIL!Gghg-w1<2;FyC;ELM}befp(#nh6JO zq@9i#QWBX>9uUUda05}KpQ%`CA$KZCR)}uNP=T!k^QRj`;VjE)PQ&LzWiQRvsI!~l zOqyzqG^-W7NCg~$uGuX%S`m13dWGA)hJrp+yiOlgxx0RI{j$0k_aR z78UL+zJ(4I-@=X=BH``KBM|~Mlmsa8Pz120M#u!VU8bZmuW46n_g2qT&fU^`X@Tt` z8U*sG=mAO&uT#A|a8yeCfrMe(5x6MSvQb999FLOlJOYudi3X*Wi%QVAmicA)gc0)nP?fovh9?O85LfWpF|MivEeI3hH0a7G;O> z8Cn_`>VlDip^=q=0TB6zHM^{iR`;$fv}wMgUvm4*{Cfv)@j6cBQ@r@C(|-BI>RO;C z0d!rP8W;_v`F}8QGD&613l`9$J#Gt-L_ zOEUBGia~zo0C~LWz_tU7ECoOxK4IX00`%c6ei>_-F8Y^Zn(U&*wXx>jIO}c9#oGDx6FV z4AZl2G9^ye_hRLk9_PtAX?v;{s~r%|w-(~V*+`gcTaWiAv z1EysUm=nM*Rzwd=bnCe`Ga4`}EM_rK*v>M6 Vec { let mut conn = self.pool.acquire().await.unwrap(); + // for avoiding compiltion error you can use the following query + // INSERT OR IGNORE INTO peer (guid, id, uuid, pk, created_at, "user", status, note, region, strategy, info, last_online) VALUES + // (x'95CC7775BA37481DAD7214A4F6CE5A94', 'TESTUSER', randomblob(16), randomblob(16), '1901-01-01 12:00:00', randomblob(16), 0, '', NULL, randomblob(16), '{}', '1901-01-01 12:00:00'); let res = sqlx::query!( r#" SELECT COALESCE(trim(json_extract(info,'$.cpu')),"unknown") as cpu, - COUNT(*) AS machine_count + COUNT(*) AS machine_count FROM peer GROUP BY