From ceefad3b3f3decd4087aaad8e843df3ce42f0db6 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 15 May 2018 19:01:44 -0700 Subject: flush out more database models --- rust/src/api_server.rs | 3 +- rust/src/database_models.rs | 300 +++++++++++++++++--------------------------- 2 files changed, 120 insertions(+), 183 deletions(-) (limited to 'rust/src') diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index aa13023d..9fbcbc57 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -7,6 +7,7 @@ use database_schema::{container_rev, container_ident, container_edit, file_rev, file_ident, file_edit, release_rev, release_ident, release_edit, work_rev, work_ident, work_edit, + editor, editgroup, changelog }; use uuid; use diesel::prelude::*; @@ -88,7 +89,7 @@ impl Api for Server { fn creator_id_get( &self, id: String, - context: &Context, + _context: &Context, ) -> Box + Send> { let conn = self.db_pool.get().expect("db_pool error"); /* diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs index c0118dda..7153d18f 100644 --- a/rust/src/database_models.rs +++ b/rust/src/database_models.rs @@ -1,4 +1,5 @@ +use chrono; use uuid::Uuid; //use diesel::prelude::*; @@ -7,216 +8,151 @@ use database_schema::*; // Ugh. I thought the whole point was to *not* do this, but: // https://github.com/diesel-rs/diesel/issues/1589 -/* -table! { - changelog (id) { - id -> Int8, - editgroup_id -> Int8, - timestamp -> Nullable, - } -} -*/ - -#[derive(Debug, Queryable, Identifiable, Associations)] // AsChangeset -#[table_name = "container_edit"] -pub struct ContainerEditRow { - pub id: i64, - pub ident_id: Uuid, - pub rev_id: Option, - pub redirect_id: Option, - pub editgroup_id: i64, - //pub extra_json: Option, -} - -#[derive(Debug, Queryable, Identifiable, Associations)] // AsChangeset -#[table_name = "container_ident"] -pub struct ContainerIdentRow { - pub id: Uuid, - pub is_live: bool, - pub rev_id: Option, - pub redirect_id: Option, -} - -#[derive(Debug, Queryable, Identifiable, Associations)] // AsChangeset +// Helper for constructing tables +macro_rules! entity_structs { + ($edit_table:expr, $edit_struct:ident, $ident_table:expr, $ident_struct:ident) => ( + + #[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] + #[table_name = $edit_table] + pub struct $edit_struct { + pub id: i64, + pub ident_id: Uuid, + pub rev_id: Option, + pub redirect_id: Option, + pub editgroup_id: i64, + //pub extra_json: Option, + } + + #[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] + #[table_name = $ident_table] + pub struct $ident_struct { + pub id: Uuid, + pub is_live: bool, + pub rev_id: Option, + pub redirect_id: Option, + } + ) +} + +#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] #[table_name = "container_rev"] pub struct ContainerRevRow { pub id: i64, //extra_json: Option, - pub name: Option, + pub name: String, pub parent_ident_id: Option, pub publisher: Option, pub issn: Option, } -/* -table! { - creator_edit (id) { - id -> Int8, - extra_json -> Nullable, - ident_id -> Uuid, - rev_id -> Nullable, - redirect_id -> Nullable, - editgroup_id -> Int8, - } -} - -table! { - creator_ident (id) { - id -> Uuid, - is_live -> Bool, - rev_id -> Nullable, - redirect_id -> Nullable, - } -} - -table! { - creator_rev (id) { - id -> Int8, - extra_json -> Nullable, - name -> Nullable, - orcid -> Nullable, - } -} - -table! { - editgroup (id) { - id -> Int8, - extra_json -> Nullable, - editor_id -> Int8, - description -> Nullable, - } -} +entity_structs!("container_edit", ContainerEditRow, "container_ident", ContainerIdentRow); -table! { - editor (id) { - id -> Int8, - username -> Text, - is_admin -> Bool, - active_editgroup_id -> Nullable, - } +#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] +#[table_name = "creator_rev"] +pub struct CreatorRevRow { + pub id: i64, + //extra_json: Option, + pub name: String, + pub orcid: Option, } -table! { - file_edit (id) { - id -> Int8, - extra_json -> Nullable, - ident_id -> Uuid, - rev_id -> Nullable, - redirect_id -> Nullable, - editgroup_id -> Int8, - } -} +entity_structs!("creator_edit", CreatorEditRow, "creator_ident", CreatorIdentRow); -table! { - file_ident (id) { - id -> Uuid, - is_live -> Bool, - rev_id -> Nullable, - redirect_id -> Nullable, - } +#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] +#[table_name = "file_rev"] +pub struct FileRevRow { + pub id: i64, + //extra_json: Option, + pub size: Option, + pub sha1: Option, + pub url: Option, } -table! { - file_release (id) { - id -> Int8, - file_rev -> Int8, - target_release_ident_id -> Uuid, - } -} +entity_structs!("file_edit", FileEditRow, "file_ident", FileIdentRow); -table! { - file_rev (id) { - id -> Int8, - extra_json -> Nullable, - size -> Nullable, - sha1 -> Nullable, - url -> Nullable, - } +#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] +#[table_name = "release_rev"] +pub struct ReleaseRevRow { + pub id: i64, + //extra_json: Option, + pub work_ident_id: Option, + pub container_ident_id: Option, + pub title: Option, + pub license: Option, + pub release_type: Option, + pub date: Option, + pub doi: Option, + pub volume: Option, + pub pages: Option, + pub issue: Option, +} + +entity_structs!("release_edit", ReleaseEditRow, "release_ident", ReleaseIdentRow); + +#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] +#[table_name = "work_rev"] +pub struct WorkRevRow { + pub id: i64, + //extra_json: Option, + pub work_type: Option, + pub primary_release_id: Option, } -table! { - release_contrib (id) { - id -> Int8, - release_rev -> Int8, - creator_ident_id -> Nullable, - stub -> Nullable, - contrib_type -> Nullable, - } -} +entity_structs!("work_edit", WorkEditRow, "work_ident", WorkIdentRow); -table! { - release_edit (id) { - id -> Int8, - extra_json -> Nullable, - ident_id -> Uuid, - rev_id -> Nullable, - redirect_id -> Nullable, - editgroup_id -> Int8, - } +#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] +#[table_name = "release_contrib"] +pub struct ReleaseContribRow { + id: i64, + release_rev: i64, + creator_ident_id: Option, + stub: Option, + contrib_type: Option, } -table! { - release_ident (id) { - id -> Uuid, - is_live -> Bool, - rev_id -> Nullable, - redirect_id -> Nullable, - } -} -table! { - release_ref (id) { - id -> Int8, - release_rev -> Int8, - target_release_ident_id -> Nullable, - index -> Nullable, - stub -> Nullable, - } +#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] +#[table_name = "release_ref"] +pub struct ReleaseRefRow { + id: i64, + release_rev: i64, + target_release_ident_id: Option, + index: Option, + stub: Option, } -table! { - release_rev (id) { - id -> Int8, - extra_json -> Nullable, - work_ident_id -> Nullable, - container_ident_id -> Nullable, - title -> Nullable, - license -> Nullable, - release_type -> Nullable, - date -> Nullable, - doi -> Nullable, - volume -> Nullable, - pages -> Nullable, - issue -> Nullable, - } +/* +#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] +#[table_name = "file_release"] +pub struct FileReleaseRow { + id: i64, + file_rev: i64, + target_release_ident_id: Uuid, } +*/ -table! { - work_edit (id) { - id -> Int8, - extra_json -> Nullable, - ident_id -> Uuid, - rev_id -> Nullable, - redirect_id -> Nullable, - editgroup_id -> Int8, - } +#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] +#[table_name = "editgroup"] +pub struct EditgroupRow { + id: i64, + //extra_json: Option, + editor_id: i64, + description: Option, } -table! { - work_ident (id) { - id -> Uuid, - is_live -> Bool, - rev_id -> Nullable, - redirect_id -> Nullable, - } +#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] +#[table_name = "editor"] +pub struct EditorRow { + id: i64, + username: String, + is_admin: bool, + active_editgroup_id: Option, } -table! { - work_rev (id) { - id -> Int8, - extra_json -> Nullable, - work_type -> Nullable, - primary_release_id -> Nullable, - } +#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] +#[table_name = "changelog"] +pub struct ChangelogRow { + id: i64, + editgroup_id: i64, + timestamp: chrono::NaiveDateTime, } -*/ -- cgit v1.2.3