Skip to content

Commit

Permalink
do not add testuser permanently
Browse files Browse the repository at this point in the history
  • Loading branch information
eltorio committed Sep 16, 2024
1 parent e54094c commit 7fccb7c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ clap = { version = "4.5", features = ["derive"] }

[build-dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_json = "1.0"
tokio = { version = "1", features = ["full"] }
sqlx = { version = "0.8", features = ["sqlite", "runtime-tokio-rustls", "macros", "chrono", "json"] }
24 changes: 23 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the Affero General Public License
// along with SCTGDesk. If not, see <https://www.gnu.org/licenses/agpl-3.0.html>.
use sqlx::{Connection, Executor, SqliteConnection};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::env;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
}
Binary file modified db_v2.sqlite3
Binary file not shown.
3 changes: 0 additions & 3 deletions db_v2/create/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ CREATE TABLE IF NOT EXISTS peer (
region text null,
strategy blob,
info JSON not null DEFAULT '{}', "last_online" datetime not null default('2011-11-16 11:55:19')) without rowid;
-- Needed for compile time (sqlx)
INSERT OR IGNORE INTO peer (guid, id, uuid, pk, created_at, "user", status, note, region, strategy, info, last_online) VALUES
(x'018f255622f77778a006702ca5c23715', 'TESTUSER', randomblob(16), randomblob(16), '1901-01-01 12:00:00', randomblob(16), 0, '', NULL, randomblob(16), '{}', '1901-01-01 12:00:00');
CREATE TABLE IF NOT EXISTS "user" (
guid blob primary key not null,
name varchar(100) not null,
Expand Down
5 changes: 4 additions & 1 deletion libs/state/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1560,11 +1560,14 @@ impl Database {

pub async fn get_cpus_count(&self) -> Vec<CpuCount> {
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
Expand Down

0 comments on commit 7fccb7c

Please sign in to comment.