From bf1aeb7191bfaa75f1acf47c675bc68b9fac1cd8 Mon Sep 17 00:00:00 2001 From: fx Date: Sat, 21 Oct 2023 21:11:28 +0200 Subject: add migrate macro --- src/db.rs | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'src/db.rs') 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; use sqlx::{PgPool, postgres::PgPoolOptions}; use tracing::{debug, info}; -use crate::error::WebolError; - #[derive(Serialize)] pub struct Device { pub id: String, @@ -13,25 +11,6 @@ pub struct Device { pub broadcast_addr: String } -impl Device { - async fn init(db: &PgPool) -> Result<(), WebolError> { - sqlx::query!(r#" - CREATE TABLE IF NOT EXISTS "devices" - ( - "id" TEXT PRIMARY KEY NOT NULL, - "mac" TEXT NOT NULL, - "broadcast_addr" TEXT NOT NULL - );"# - ).execute(db).await.map_err(|err| WebolError::Server(Box::new(err)))?; - - Ok(()) - } -} - -pub async fn setup_db(db: &PgPool) -> Result<(), WebolError> { - Device::init(db).await -} - pub async fn init_db_pool() -> PgPool { #[cfg(not(debug_assertions))] let db_url = SETTINGS.get_string("database.url").unwrap(); -- cgit v1.2.3