From 703f4e45e37830046ab9f21bcabe14fb6ae9465e Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sun, 21 Jun 2026 20:50:01 +0200 Subject: [PATCH] add repository to data model --- application/src/backend.rs | 11 ++++++++- dav-rs/src/dav/resource.rs | 4 ++-- entity/src/collection.rs | 1 + entity/src/lib.rs | 3 ++- entity/src/repository.rs | 16 +++++++++++++ .../src/m20260502_184134_create_settings.rs | 23 +++++++++++++++++++ 6 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 entity/src/repository.rs diff --git a/application/src/backend.rs b/application/src/backend.rs index da08f47..66c88da 100644 --- a/application/src/backend.rs +++ b/application/src/backend.rs @@ -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()), diff --git a/dav-rs/src/dav/resource.rs b/dav-rs/src/dav/resource.rs index 07cdcf9..25b8510 100644 --- a/dav-rs/src/dav/resource.rs +++ b/dav-rs/src/dav/resource.rs @@ -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>>, } diff --git a/entity/src/collection.rs b/entity/src/collection.rs index a596011..c30106c 100644 --- a/entity/src/collection.rs +++ b/entity/src/collection.rs @@ -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, diff --git a/entity/src/lib.rs b/entity/src/lib.rs index 1b1ae7c..1b9a694 100644 --- a/entity/src/lib.rs +++ b/entity/src/lib.rs @@ -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 index 0000000..7fa18c6 --- /dev/null +++ b/entity/src/repository.rs @@ -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, + pub base_url: Option, +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/migration/src/m20260502_184134_create_settings.rs b/migration/src/m20260502_184134_create_settings.rs index 3bdc1cb..8f27a64 100644 --- a/migration/src/m20260502_184134_create_settings.rs +++ b/migration/src/m20260502_184134_create_settings.rs @@ -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 -- 2.52.0