]> uap-core.de Git - note.git/commitdiff
add repository to data model main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 21 Jun 2026 18:50:01 +0000 (20:50 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 21 Jun 2026 18:50:01 +0000 (20:50 +0200)
application/src/backend.rs
dav-rs/src/dav/resource.rs
entity/src/collection.rs
entity/src/lib.rs
entity/src/repository.rs [new file with mode: 0644]
migration/src/m20260502_184134_create_settings.rs

index da08f473ee98b2602b322ab94b3c37982f754b40..66c88daef77a8255cba4da38bd9af2d3c64df95e 100644 (file)
@@ -38,7 +38,7 @@ use tokio::sync::broadcast::error::SendError;
 use migration::{Expr, Migrator, MigratorTrait};
 use ui_rs::ui;
 
-use entity::{collection, note, notecontent, profile};
+use entity::{collection, note, notecontent, profile, repository};
 use entity::profile::Entity as Profile;
 use entity::collection::{create_notebook_hierarchy, CollectionType, Entity as Collection, Node};
 use entity::note::{Column, Entity as Note};
@@ -198,9 +198,17 @@ impl Backend {
 
             let inserted = active.insert(db).await?;
 
+            // create a repository
+            let insert_repository = repository::ActiveModel {
+                name: Set("local".to_string()),
+                ..Default::default()
+            };
+            let repo = insert_repository.insert(db).await?;
+
             // create some initial notebooks
             let insert_notebooks = collection::ActiveModel {
                 profile_id: Set(inserted.id),
+                repository_id: Set(repo.repository_id),
                 name: Set("Notebooks".to_string()),
                 parent: Set("".to_string()),
                 icon: Set("".to_string()),
@@ -212,6 +220,7 @@ impl Backend {
 
             let insert_notes = collection::ActiveModel {
                 profile_id: Set(inserted.id),
+                repository_id: Set(repo.repository_id),
                 name: Set("Notes".to_string()),
                 parent: Set("/Notebooks".to_string()),
                 icon: Set("".to_string()),
index 07cdcf96e6589c764963413406de60cc6a0d3ad1..25b85105fe687611e5a0a87d3435794393f7653e 100644 (file)
@@ -35,11 +35,11 @@ use crate::dav::ffi;
 use crate::dav::session::Session;
 
 pub struct Resource<'a> {
-    base: ResourceRef<'a>
+    pub base: ResourceRef<'a>
 }
 
 pub struct ResourceRef<'a> {
-    ptr: *mut ffi::DavResource,
+    pub ptr: *mut ffi::DavResource,
     _marker: PhantomData<&'a Resource<'a>>,
 }
 
index a5960115a4289c1eb07b6d4964f05901596bde2a..c30106c155571067aceab3fd2687856f23b76f6b 100644 (file)
@@ -7,6 +7,7 @@ pub struct Model {
     #[sea_orm(primary_key)]
     pub collection_id: i32,
     pub profile_id: i32,
+    pub repository_id: i32,
 
     pub name: String,
     pub parent: String,
index 1b1ae7c098a2de6efa6c64176124c7e365d857eb..1b9a69462b98eb9cfd5fd34acea02776702e7b26 100644 (file)
@@ -2,4 +2,5 @@ mod prelude;
 pub mod profile;
 pub mod collection;
 pub mod note;
-pub mod notecontent;
\ No newline at end of file
+pub mod notecontent;
+pub mod repository;
\ No newline at end of file
diff --git a/entity/src/repository.rs b/entity/src/repository.rs
new file mode 100644 (file)
index 0000000..7fa18c6
--- /dev/null
@@ -0,0 +1,16 @@
+use sea_orm::entity::prelude::*;
+
+
+#[sea_orm::model]
+#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
+#[sea_orm(table_name = "repository")]
+pub struct Model {
+    #[sea_orm(primary_key)]
+    pub repository_id: i32,
+
+    pub name: String,
+    pub local_path: Option<String>,
+    pub base_url: Option<String>,
+}
+
+impl ActiveModelBehavior for ActiveModel {}
index 3bdc1cbc932a437577616b974fec2c30ce223a6b..8f27a64bba28e4fcfc18fc0e204aa8958baa3be6 100644 (file)
@@ -19,6 +19,19 @@ impl MigrationTrait for Migration {
             )
             .await?;
 
+        manager
+            .create_table(
+                Table::create()
+                    .table("repository")
+                    .if_not_exists()
+                    .col(pk_auto("repository_id"))
+                    .col(string("name"))
+                    .col(string_null("local_path"))
+                    .col(string_null("base_url"))
+                    .to_owned(),
+            )
+            .await?;
+
         manager
             .create_table(
                 Table::create()
@@ -26,6 +39,7 @@ impl MigrationTrait for Migration {
                     .if_not_exists()
                     .col(pk_auto("collection_id"))
                     .col(integer("profile_id"))
+                    .col(integer("repository_id"))
                     .col(string("name"))
                     .col(string("parent"))
                     .col(string("icon"))
@@ -37,6 +51,13 @@ impl MigrationTrait for Migration {
                              .to("Profile", "id")
                              .on_delete(ForeignKeyAction::Cascade)
                              .on_update(ForeignKeyAction::Cascade))
+                    .foreign_key(
+                        ForeignKey::create()
+                            .name("fk-collection-repository")
+                            .from("collection", "repository_id")
+                            .to("repository", "repository_id")
+                            .on_delete(ForeignKeyAction::Cascade)
+                            .on_update(ForeignKeyAction::Cascade))
                     .to_owned(),
             )
             .await?;
@@ -83,6 +104,8 @@ impl MigrationTrait for Migration {
             .drop_table(Table::drop().table("note").to_owned()).await?;
         manager
             .drop_table(Table::drop().table("collection").to_owned()).await?;
+        manager
+            .drop_table(Table::drop().table("repository").to_owned()).await?;
         manager
             .drop_table(Table::drop().table("profile").to_owned())
             .await