settings: store id of first admin user
This commit is contained in:
parent
3e168c19bc
commit
a3866b0af2
5 changed files with 25 additions and 0 deletions
|
|
@ -0,0 +1,2 @@
|
||||||
|
alter table settings
|
||||||
|
drop column first_admin;
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
alter table settings
|
||||||
|
add column first_admin TEXT references users (id);
|
||||||
|
|
@ -54,4 +54,17 @@ impl Settings {
|
||||||
|
|
||||||
Ok((query.rows_affected() == 1).then_some(()))
|
Ok((query.rows_affected() == 1).then_some(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn set_first_admin(
|
||||||
|
conn: impl SqliteExecutor<'_>,
|
||||||
|
id: &str,
|
||||||
|
) -> Result<Option<()>, Error> {
|
||||||
|
let query: SqliteQueryResult =
|
||||||
|
sqlx::query_file!("queries/settings/set_first_admin.sql", id)
|
||||||
|
.execute(conn)
|
||||||
|
.await
|
||||||
|
.map_err(handle_error)?;
|
||||||
|
|
||||||
|
Ok((query.rows_affected() == 1).then_some(()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,6 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
database = { path = "../database" }
|
database = { path = "../database" }
|
||||||
|
id = { path = "../id" }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
|
|
@ -2,6 +2,7 @@ use crate::error::Error;
|
||||||
use crate::Settings;
|
use crate::Settings;
|
||||||
use database::sqlx::SqliteExecutor;
|
use database::sqlx::SqliteExecutor;
|
||||||
use database::Settings as DatabaseSettings;
|
use database::Settings as DatabaseSettings;
|
||||||
|
use id::UserID;
|
||||||
|
|
||||||
const DEFAULT_BUSINESS_NAME: &str = "ezidam";
|
const DEFAULT_BUSINESS_NAME: &str = "ezidam";
|
||||||
pub const DEFAULT_BUSINESS_LOGO: &[u8] = include_bytes!("../../../logo/ezidam.png");
|
pub const DEFAULT_BUSINESS_LOGO: &[u8] = include_bytes!("../../../logo/ezidam.png");
|
||||||
|
|
@ -48,4 +49,10 @@ impl Settings {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn set_first_admin(conn: impl SqliteExecutor<'_>, id: &UserID) -> Result<(), Error> {
|
||||||
|
DatabaseSettings::set_first_admin(conn, &id.0).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue