summaryrefslogtreecommitdiff
path: root/src/db.rs
diff options
context:
space:
mode:
authorfx <[email protected]>2023-10-21 21:11:28 +0200
committerfx <[email protected]>2023-10-21 21:11:28 +0200
commitbf1aeb7191bfaa75f1acf47c675bc68b9fac1cd8 (patch)
tree5cd77421900fd8ec02f05d15e6fb195f28dfceb4 /src/db.rs
parentf5928b90748b0bb4c0c498ccc77ebde4eaec8841 (diff)
downloadwebol-bf1aeb7191bfaa75f1acf47c675bc68b9fac1cd8.tar
webol-bf1aeb7191bfaa75f1acf47c675bc68b9fac1cd8.tar.gz
webol-bf1aeb7191bfaa75f1acf47c675bc68b9fac1cd8.zip
add migrate macro
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs21
1 files changed, 0 insertions, 21 deletions
diff --git a/src/db.rs b/src/db.rs
index e9d001f..295780e 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -4,8 +4,6 @@ use serde::Serialize;
4use sqlx::{PgPool, postgres::PgPoolOptions}; 4use sqlx::{PgPool, postgres::PgPoolOptions};
5use tracing::{debug, info}; 5use tracing::{debug, info};
6 6
7use crate::error::WebolError;
8
9#[derive(Serialize)] 7#[derive(Serialize)]
10pub struct Device { 8pub struct Device {
11 pub id: String, 9 pub id: String,
@@ -13,25 +11,6 @@ pub struct Device {
13 pub broadcast_addr: String 11 pub broadcast_addr: String
14} 12}
15 13
16impl Device {
17 async fn init(db: &PgPool) -> Result<(), WebolError> {
18 sqlx::query!(r#"
19 CREATE TABLE IF NOT EXISTS "devices"
20 (
21 "id" TEXT PRIMARY KEY NOT NULL,
22 "mac" TEXT NOT NULL,
23 "broadcast_addr" TEXT NOT NULL
24 );"#
25 ).execute(db).await.map_err(|err| WebolError::Server(Box::new(err)))?;
26
27 Ok(())
28 }
29}
30
31pub async fn setup_db(db: &PgPool) -> Result<(), WebolError> {
32 Device::init(db).await
33}
34
35pub async fn init_db_pool() -> PgPool { 14pub async fn init_db_pool() -> PgPool {
36 #[cfg(not(debug_assertions))] 15 #[cfg(not(debug_assertions))]
37 let db_url = SETTINGS.get_string("database.url").unwrap(); 16 let db_url = SETTINGS.get_string("database.url").unwrap();