]> uap-core.de Git - note.git/commitdiff
migrate db at startup main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 9 May 2026 11:18:07 +0000 (13:18 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 9 May 2026 11:18:07 +0000 (13:18 +0200)
Cargo.lock
application/Cargo.toml
application/src/backend.rs
application/src/main.rs
ui-rs/src/ui/button.rs

index 9c83a0c73be973674bd5e2562e3f2d1ba3036138..6db192c6fc3b47d183e3399c9f016bb56d530bfb 100644 (file)
@@ -1515,6 +1515,8 @@ dependencies = [
 name = "note"
 version = "0.1.0"
 dependencies = [
+ "entity",
+ "migration",
  "sea-orm",
  "tokio",
  "ui-rs",
index cc8099d4e2027f8d84cc69370452d32fabb800c8..ff1c6f5c61e46d7719c26f1dd587ef0e5b20bb51 100644 (file)
@@ -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"] }
index 0de52565523132adebd06857a6134da5a22d082f..acacc1f9f302409848159363247d854fb488347e 100644 (file)
@@ -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(())
+    }
 }
index 7eee73801f69993067acc1f0fd50d4b34c660895..a2d2e48683a6f86e1a3002475fcabb964ae8d247 100644 (file)
@@ -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::<MainWindow>(&mut app);
 }
index 055f7d88d664b317ef2170b339e9dde44c12a061..f13a9b2ccb70e9ca3d50c04688d2c5a400c8127b 100644 (file)
@@ -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();
             }