diff options
author | fx <[email protected]> | 2023-10-21 21:11:28 +0200 |
---|---|---|
committer | fx <[email protected]> | 2023-10-21 21:11:28 +0200 |
commit | bf1aeb7191bfaa75f1acf47c675bc68b9fac1cd8 (patch) | |
tree | 5cd77421900fd8ec02f05d15e6fb195f28dfceb4 /src/db.rs | |
parent | f5928b90748b0bb4c0c498ccc77ebde4eaec8841 (diff) | |
download | webol-bf1aeb7191bfaa75f1acf47c675bc68b9fac1cd8.tar webol-bf1aeb7191bfaa75f1acf47c675bc68b9fac1cd8.tar.gz webol-bf1aeb7191bfaa75f1acf47c675bc68b9fac1cd8.zip |
add migrate macro
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(); |