diff options
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 21 |
1 files changed, 0 insertions, 21 deletions
@@ -4,8 +4,6 @@ use serde::Serialize; | |||
4 | use sqlx::{PgPool, postgres::PgPoolOptions}; | 4 | use sqlx::{PgPool, postgres::PgPoolOptions}; |
5 | use tracing::{debug, info}; | 5 | use tracing::{debug, info}; |
6 | 6 | ||
7 | use crate::error::WebolError; | ||
8 | |||
9 | #[derive(Serialize)] | 7 | #[derive(Serialize)] |
10 | pub struct Device { | 8 | pub 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 | ||
16 | impl 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 | |||
31 | pub async fn setup_db(db: &PgPool) -> Result<(), WebolError> { | ||
32 | Device::init(db).await | ||
33 | } | ||
34 | |||
35 | pub async fn init_db_pool() -> PgPool { | 14 | pub 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(); |