better relations

This commit is contained in:
Jamie
2021-12-24 22:51:13 -08:00
parent 5ed02125c7
commit 836178ca45
4 changed files with 117 additions and 101 deletions

View File

@@ -9,85 +9,64 @@ use serde::{Deserialize, Serialize};
#[sea_orm(table_name = "files")]
// -------------------------------------
pub struct Model {
// identity
#[sea_orm(primary_key)]
pub id: u32,
// pub buffer_checksum: String,
#[sea_orm(unique)]
pub meta_checksum: String,
pub uri: String,
pub is_dir: bool,
// date
pub date_created: Option<NaiveDateTime>,
pub date_modified: Option<NaiveDateTime>,
pub date_indexed: Option<NaiveDateTime>,
// metadata
pub name: String,
pub extension: String,
pub size_in_bytes: String,
pub library_id: u32,
// #[sea_orm(column_type = "Int")]
// pub encryption: crypto::Encryption,
// ownership
#[sea_orm(nullable)]
pub ipfs_id: Option<String>,
#[sea_orm(nullable)]
pub storage_device_id: Option<u32>,
#[sea_orm(nullable)]
pub capture_device_id: Option<u32>,
#[sea_orm(nullable)]
pub parent_id: Option<u32>,
// identity
#[sea_orm(primary_key)]
pub id: u32,
// pub buffer_checksum: String,
#[sea_orm(unique)]
pub meta_checksum: String,
pub uri: String,
pub is_dir: bool,
// date
pub date_created: Option<NaiveDateTime>,
pub date_modified: Option<NaiveDateTime>,
pub date_indexed: Option<NaiveDateTime>,
// metadata
pub name: String,
pub extension: String,
pub size_in_bytes: String,
pub library_id: u32,
// #[sea_orm(column_type = "Int")]
// pub encryption: crypto::Encryption,
// ownership
#[sea_orm(nullable)]
pub ipfs_id: Option<String>,
#[sea_orm(nullable)]
pub storage_device_id: Option<u32>,
#[sea_orm(nullable)]
pub capture_device_id: Option<u32>,
#[sea_orm(nullable)]
pub parent_id: Option<u32>,
}
#[derive(Copy, Clone, Debug, EnumIter)]
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
Library,
StorageDevice,
CaptureDevice,
ParentFile,
}
#[sea_orm(
belongs_to = "super::library::Entity",
from = "Column::LibraryId",
to = "super::library::Column::Id"
)]
Library,
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::Library => Entity::belongs_to(super::library::Entity)
.from(Column::LibraryId)
.to(super::library::Column::Id)
.into(),
Self::StorageDevice => Entity::belongs_to(super::storage_device::Entity)
.from(Column::StorageDeviceId)
.to(super::storage_device::Column::Id)
.into(),
Self::CaptureDevice => Entity::belongs_to(super::capture_device::Entity)
.from(Column::CaptureDeviceId)
.to(super::capture_device::Column::Id)
.into(),
Self::ParentFile => Entity::belongs_to(Entity)
.from(Column::ParentId)
.to(Column::Id)
.into(),
}
}
}
impl Related<super::library::Entity> for Entity {
fn to() -> RelationDef {
Relation::Library.def()
}
}
impl Related<super::storage_device::Entity> for Entity {
fn to() -> RelationDef {
Relation::StorageDevice.def()
}
}
impl Related<super::capture_device::Entity> for Entity {
fn to() -> RelationDef {
Relation::CaptureDevice.def()
}
}
impl Related<Entity> for Entity {
fn to() -> RelationDef {
Relation::ParentFile.def()
}
#[sea_orm(
belongs_to = "super::storage_device::Entity",
from = "Column::StorageDeviceId",
to = "super::storage_device::Column::Id"
)]
StorageDevice,
#[sea_orm(
belongs_to = "super::capture_device::Entity",
from = "Column::CaptureDeviceId",
to = "super::capture_device::Column::Id"
)]
CaptureDevice,
#[sea_orm(belongs_to = "Entity", from = "Column::ParentId", to = "Column::Id")]
ParentFile,
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -8,17 +8,24 @@ use serde::{Deserialize, Serialize};
#[sea_orm(table_name = "spaces")]
// -------------------------------------
pub struct Model {
#[sea_orm(primary_key)]
pub id: u32,
pub name: String,
pub calculated_size_in_bytes: Option<String>,
pub calculated_file_count: Option<u32>,
pub library_id: String,
pub date_created: Option<NaiveDateTime>,
pub date_modified: Option<NaiveDateTime>,
#[sea_orm(primary_key)]
pub id: u32,
pub name: String,
pub calculated_size_in_bytes: Option<String>,
pub calculated_file_count: Option<u32>,
pub library_id: String,
pub date_created: Option<NaiveDateTime>,
pub date_modified: Option<NaiveDateTime>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
pub enum Relation {
#[sea_orm(
belongs_to = "super::library::Entity",
from = "Column::LibraryId",
to = "super::library::Column::Id"
)]
Library,
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -8,17 +8,24 @@ use serde::{Deserialize, Serialize};
#[sea_orm(table_name = "tags")]
// -------------------------------------
pub struct Model {
#[sea_orm(primary_key)]
pub id: u32,
pub name: String,
pub total_files: Option<String>,
pub redundancy_goal: Option<u32>,
pub library_id: String,
pub date_created: Option<NaiveDateTime>,
pub date_modified: Option<NaiveDateTime>,
#[sea_orm(primary_key)]
pub id: u32,
pub name: String,
pub total_files: Option<String>,
pub redundancy_goal: Option<u32>,
pub library_id: String,
pub date_created: Option<NaiveDateTime>,
pub date_modified: Option<NaiveDateTime>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
pub enum Relation {
#[sea_orm(
belongs_to = "super::library::Entity",
from = "Column::LibraryId",
to = "super::library::Column::Id"
)]
Library,
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -1,13 +1,36 @@
pub enum TransactionType {
//
// Transactions are used to describe changes to be made to the database
// - a transaction must be run as a single read, write, or delete operation to the SQLite database
// - they are emitted by a given client and accepted or rejected by sister clients
// - if a client rejects a transaction the entire database will be marked for re-sync
pub struct Transaction {
pub id: i32,
pub timestamp: i32, // unix timestamp
pub client_id: i32, // the client that created the transaction
pub model: String, // the model that the transaction is for
pub method TransactionMethod,
// vector of transaction entries
pub mutations: Option<Vec<ObjectMutation>>
}
//
pub struct ObjectMutation {
pub primary_key: Vec<i32>,
pub columns: Vec<String>,
pub new_values: Vec<String>,
}
pub enum TransactionMethod {
CREATE,
UPDATE,
DELETE,
}
pub struct Transaction {
pub id: i32,
pub timestamp: i32,
pub client_id: i32,
pub target_client_id: i32,
// type TransactionType
}
// create tag
// update tag
// assign tag to file
// create files
// create action records
//