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};
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()),
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()),
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>>,
}
#[sea_orm(primary_key)]
pub collection_id: i32,
pub profile_id: i32,
+ pub repository_id: i32,
pub name: String,
pub parent: String,
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
--- /dev/null
+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 {}
)
.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()
.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"))
.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?;
.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