Add remaining entities with relations

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 551d556b75
commit 72c5796311

@ -541,6 +541,7 @@ dependencies = [
name = "mediarepo-database" name = "mediarepo-database"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"chrono",
"mediarepo-core", "mediarepo-core",
"sea-orm", "sea-orm",
"sqlx", "sqlx",

@ -6,6 +6,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
chrono = "0.4.19"
[dependencies.mediarepo-core] [dependencies.mediarepo-core]
path = "../mediarepo-core" path = "../mediarepo-core"

@ -0,0 +1,40 @@
use sea_orm::prelude::*;
use chrono::NaiveDateTime;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "files")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: u64,
pub file_type: u32,
pub name: Option<String>,
pub comment: Option<String>,
pub storage_id: u64,
pub hash_id: u64,
pub import_time: NaiveDateTime,
pub creation_time: NaiveDateTime,
pub change_time: NaiveDateTime,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(belongs_to = "super::hash::Entity", from = "Column::HashId", to = "super::hash::Column::Id")]
Hash,
#[sea_orm(belongs_to = "super::storage::Entity", from = "Column::StorageId", to = "super::storage::Column::Id")]
Storage,
}
impl Related<super::hash::Entity> for Entity {
fn to() -> RelationDef {
Relation::Hash.def()
}
}
impl Related<super::storage::Entity> for Entity {
fn to() -> RelationDef {
Relation::Storage.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

@ -0,0 +1,35 @@
use sea_orm::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "hashes")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: u64,
pub value: String
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
}
impl Related<super::tag::Entity> for Entity {
fn to() -> RelationDef {
super::hash_tag::Relation::Tag.def()
}
fn via() -> Option<RelationDef> {
Some(super::hash_tag::Relation::Hash.def().rev())
}
}
impl Related<super::source::Entity> for Entity {
fn to() -> RelationDef {
super::hash_source::Relation::Source.def()
}
fn via() -> Option<RelationDef> {
Some(super::hash_source::Relation::Hash.def().rev())
}
}
impl ActiveModelBehavior for ActiveModel {}

@ -0,0 +1,32 @@
use sea_orm::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "hash_source_mappings")]
pub struct Model {
#[sea_orm(primary_key)]
pub hash_id: u64,
#[sea_orm(primary_key)]
pub source_id: u64,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(belongs_to = "super::hash::Entity", from = "Column::HashId", to = "super::hash::Column::Id")]
Hash,
#[sea_orm(belongs_to = "super::source::Entity", from = "Column::SourceId", to = "super::source::Column::Id")]
Source,
}
impl Related<super::hash::Entity> for Entity {
fn to() -> RelationDef {
Relation::Hash.def()
}
}
impl Related<super::source::Entity> for Entity {
fn to() -> RelationDef {
Relation::Source.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

@ -0,0 +1,32 @@
use sea_orm::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "hash_tag_mappings")]
pub struct Model {
#[sea_orm(primary_key)]
pub hash_id: u64,
#[sea_orm(primary_key)]
pub tag_id: u64,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(belongs_to = "super::hash::Entity", from = "Column::HashId", to = "super::hash::Column::Id")]
Hash,
#[sea_orm(belongs_to = "super::tag::Entity", from = "Column::TagId", to = "super::tag::Column::Id")]
Tag,
}
impl Related<super::hash::Entity> for Entity {
fn to() -> RelationDef {
Relation::Hash.def()
}
}
impl Related<super::tag::Entity> for Entity {
fn to() -> RelationDef {
Relation::Tag.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

@ -1,5 +1,8 @@
mod tag; pub mod tag;
mod namespace; pub mod namespace;
pub mod hash;
pub use tag::*; pub mod source;
pub use namespace::*; pub mod file;
pub mod hash_tag;
pub mod storage;
pub mod hash_source;

@ -0,0 +1,25 @@
use sea_orm::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "sources")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: u64,
pub url: String
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
}
impl Related<super::hash::Entity> for Entity {
fn to() -> RelationDef {
super::hash_source::Relation::Hash.def()
}
fn via() -> Option<RelationDef> {
Some(super::hash_source::Relation::Source.def().rev())
}
}
impl ActiveModelBehavior for ActiveModel {}

@ -0,0 +1,24 @@
use sea_orm::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "storages")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: u64,
pub name: String,
pub path: String
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::file::Entity")]
File,
}
impl Related<super::file::Entity> for Entity {
fn to() -> RelationDef {
Relation::File.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

@ -17,7 +17,11 @@ pub enum Relation {
impl Related<super::namespace::Entity> for Entity { impl Related<super::namespace::Entity> for Entity {
fn to() -> RelationDef { fn to() -> RelationDef {
Relation::Namespace.def() super::hash_tag::Relation::Hash.def()
}
fn via() -> Option<RelationDef> {
Some(super::hash_tag::Relation::Tag.def().rev())
} }
} }

Loading…
Cancel
Save