From 378f0cce76ba9b5bab9505e43ccbb10061d0720d Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sat, 9 May 2026 13:18:07 +0200 Subject: [PATCH] migrate db at startup --- Cargo.lock | 2 ++ application/Cargo.toml | 2 ++ application/src/backend.rs | 11 ++++++++++- application/src/main.rs | 2 ++ ui-rs/src/ui/button.rs | 4 ++-- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9c83a0c..6db192c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1515,6 +1515,8 @@ dependencies = [ name = "note" version = "0.1.0" dependencies = [ + "entity", + "migration", "sea-orm", "tokio", "ui-rs", diff --git a/application/Cargo.toml b/application/Cargo.toml index cc8099d..ff1c6f5 100644 --- a/application/Cargo.toml +++ b/application/Cargo.toml @@ -5,5 +5,7 @@ edition = "2021" [dependencies] ui-rs = { path = "../ui-rs" } +entity = { path = "../entity" } +migration = { path = "../migration" } sea-orm = { version = "2.0.0-rc", features = [ "sqlx-sqlite", "sqlx-postgres", "runtime-tokio-native-tls", "macros" ] } tokio = { version = "1.52.1", features = ["rt-multi-thread"] } diff --git a/application/src/backend.rs b/application/src/backend.rs index 0de5256..acacc1f 100644 --- a/application/src/backend.rs +++ b/application/src/backend.rs @@ -1,6 +1,7 @@ -use sea_orm::{Database, DatabaseConnection}; +use sea_orm::{Database, DatabaseConnection, DbErr}; use tokio::runtime::Runtime; use std::sync::Arc; +use migration::{Migrator, MigratorTrait}; use ui_rs::ui; pub struct Backend { @@ -28,4 +29,12 @@ impl Backend { Self { rt, db } } + + pub fn migrate(&self) -> Result<(), DbErr> { + self.rt.block_on(async { + Migrator::up(&self.db, None).await + })?; + + Ok(()) + } } diff --git a/application/src/main.rs b/application/src/main.rs index 7eee738..a2d2e48 100644 --- a/application/src/main.rs +++ b/application/src/main.rs @@ -38,6 +38,8 @@ fn main() { ui::app_init("note"); let backend = Backend::new(); + backend.migrate().unwrap(); // todo: check error + let mut app = App { backend: backend }; ui::app_run::(&mut app); } diff --git a/ui-rs/src/ui/button.rs b/ui-rs/src/ui/button.rs index 055f7d8..f13a9b2 100644 --- a/ui-rs/src/ui/button.rs +++ b/ui-rs/src/ui/button.rs @@ -790,7 +790,7 @@ impl LinkButton { pub fn get_label(&self) -> String { unsafe { - let cstr_ptr = unsafe { ui_linkbutton_get_label(self.ptr) }; + let cstr_ptr = ui_linkbutton_get_label(self.ptr); if cstr_ptr.is_null() { return String::new(); } @@ -803,7 +803,7 @@ impl LinkButton { pub fn get_uri(&self) -> String { unsafe { - let cstr_ptr = unsafe { ui_linkbutton_get_uri(self.ptr) }; + let cstr_ptr = ui_linkbutton_get_uri(self.ptr); if cstr_ptr.is_null() { return String::new(); } -- 2.47.3