settings: add base url, WIP flash system

This commit is contained in:
Philippe Loctaux 2023-03-07 08:42:23 +01:00
parent f2bea92272
commit c670201b86
18 changed files with 190 additions and 68 deletions

View file

@ -0,0 +1,2 @@
alter table settings
drop column url;

View file

@ -0,0 +1,2 @@
alter table settings
add column url TEXT;

View file

@ -2,7 +2,8 @@ select id,
created_at as "created_at: DateTime<Utc>",
updated_at as "updated_at: DateTime<Utc>",
business_name,
business_logo
business_logo,
url
from settings

View file

@ -0,0 +1,5 @@
update settings
set url = ?
where id is 0

View file

@ -40,6 +40,64 @@
},
"query": "insert or ignore into settings(id)\nvalues (0);"
},
"64cf880633d3ee5c18f6e7c2a865470442f1ba4b1019806a580ec384329dc32e": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Int64"
},
{
"name": "created_at: DateTime<Utc>",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "updated_at: DateTime<Utc>",
"ordinal": 2,
"type_info": "Text"
},
{
"name": "business_name",
"ordinal": 3,
"type_info": "Text"
},
{
"name": "business_logo",
"ordinal": 4,
"type_info": "Blob"
},
{
"name": "url",
"ordinal": 5,
"type_info": "Text"
}
],
"nullable": [
false,
false,
false,
true,
true,
true
],
"parameters": {
"Right": 0
}
},
"query": "select id,\n created_at as \"created_at: DateTime<Utc>\",\n updated_at as \"updated_at: DateTime<Utc>\",\n business_name,\n business_logo,\n url\n\nfrom settings\n\nwhere id is 0\n"
},
"87906834faa6f185aee0e4d893b9754908b1c173e9dce383663d723891a89cd1": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Right": 1
}
},
"query": "update settings\n\nset url = ?\n\nwhere id is 0\n"
},
"aae93a39c5a9f46235b5ef871b45ba76d7efa1677bfe8291a62b8cbf9cd9e0d5": {
"describe": {
"columns": [],
@ -127,47 +185,5 @@
}
},
"query": "select u.id,\n u.created_at as \"created_at: DateTime<Utc>\",\n u.updated_at as \"updated_at: DateTime<Utc>\",\n u.is_admin as \"is_admin: bool\",\n u.username,\n u.name,\n u.email,\n u.password,\n u.password_recover,\n u.paper_key,\n u.is_archived as \"is_archived: bool\"\nfrom users u\n\n inner join settings s on u.id = s.first_admin\n\nwhere u.is_admin is 1\n and u.is_archived is 0\n and u.id is s.first_admin\n\nlimit 1"
},
"cc69514c4d9457462e634eb58cbfc82b454197c5cb7f4a451954eb5a421afc3b": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Int64"
},
{
"name": "created_at: DateTime<Utc>",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "updated_at: DateTime<Utc>",
"ordinal": 2,
"type_info": "Text"
},
{
"name": "business_name",
"ordinal": 3,
"type_info": "Text"
},
{
"name": "business_logo",
"ordinal": 4,
"type_info": "Blob"
}
],
"nullable": [
false,
false,
false,
true,
true
],
"parameters": {
"Right": 0
}
},
"query": "select id,\n created_at as \"created_at: DateTime<Utc>\",\n updated_at as \"updated_at: DateTime<Utc>\",\n business_name,\n business_logo\n\nfrom settings\n\nwhere id is 0\n"
}
}

View file

@ -10,6 +10,7 @@ pub struct Settings {
pub updated_at: DateTime<Utc>,
pub business_name: Option<String>,
pub business_logo: Option<Vec<u8>>,
pub url: Option<String>,
}
impl Settings {
@ -67,4 +68,13 @@ impl Settings {
Ok((query.rows_affected() == 1).then_some(()))
}
pub async fn set_url(conn: impl SqliteExecutor<'_>, url: &str) -> Result<Option<()>, Error> {
let query: SqliteQueryResult = sqlx::query_file!("queries/settings/set_url.sql", url)
.execute(conn)
.await
.map_err(handle_error)?;
Ok((query.rows_affected() == 1).then_some(()))
}
}