diff options
Diffstat (limited to 'rust/src/database_models.rs')
-rw-r--r-- | rust/src/database_models.rs | 131 |
1 files changed, 105 insertions, 26 deletions
diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs index 63fbcb29..adb38bda 100644 --- a/rust/src/database_models.rs +++ b/rust/src/database_models.rs @@ -3,8 +3,10 @@ use crate::database_schema::*; use crate::errors::*; use crate::identifiers::uuid2fcid; -use chrono; -use fatcat_api_spec::models::{ChangelogEntry, Editgroup, EditgroupAnnotation, Editor, EntityEdit}; +use chrono::Utc; +use fatcat_api_spec::models::{ + ChangelogEntry, Editgroup, EditgroupAnnotation, Editor, EntityEdit, ReleaseRef, +}; use serde_json; use uuid::Uuid; @@ -127,11 +129,10 @@ pub struct ContainerRevRow { pub id: Uuid, pub extra_json: Option<serde_json::Value>, pub name: String, + pub container_type: Option<String>, pub publisher: Option<String>, pub issnl: Option<String>, pub wikidata_qid: Option<String>, - pub abbrev: Option<String>, - pub coden: Option<String>, } #[derive(Debug, Associations, AsChangeset, Insertable)] @@ -139,11 +140,10 @@ pub struct ContainerRevRow { pub struct ContainerRevNewRow { pub extra_json: Option<serde_json::Value>, pub name: String, + pub container_type: Option<String>, pub publisher: Option<String>, pub issnl: Option<String>, pub wikidata_qid: Option<String>, - pub abbrev: Option<String>, - pub coden: Option<String>, } entity_structs!( @@ -305,7 +305,7 @@ pub struct WebcaptureRevCdxRow { pub id: i64, pub webcapture_rev: Uuid, pub surt: String, - pub timestamp: String, + pub timestamp: chrono::DateTime<Utc>, pub url: String, pub mimetype: Option<String>, pub status_code: Option<i64>, @@ -318,7 +318,7 @@ pub struct WebcaptureRevCdxRow { pub struct WebcaptureRevCdxNewRow { pub webcapture_rev: Uuid, pub surt: String, - pub timestamp: String, + pub timestamp: chrono::DateTime<Utc>, pub url: String, pub mimetype: Option<String>, pub status_code: Option<i64>, @@ -376,7 +376,9 @@ pub struct ReleaseRevRow { pub extra_json: Option<serde_json::Value>, pub work_ident_id: Uuid, pub container_ident_id: Option<Uuid>, + pub refs_blob_sha1: Option<String>, pub title: String, + pub original_title: Option<String>, pub release_type: Option<String>, pub release_status: Option<String>, pub release_date: Option<chrono::NaiveDate>, @@ -387,11 +389,14 @@ pub struct ReleaseRevRow { pub wikidata_qid: Option<String>, pub isbn13: Option<String>, pub core_id: Option<String>, + pub arxiv_id: Option<String>, + pub jstor_id: Option<String>, pub volume: Option<String>, pub issue: Option<String>, pub pages: Option<String>, pub publisher: Option<String>, pub language: Option<String>, + pub license_slug: Option<String>, } #[derive(Debug, Associations, AsChangeset, Insertable)] @@ -400,7 +405,9 @@ pub struct ReleaseRevNewRow { pub extra_json: Option<serde_json::Value>, pub work_ident_id: Uuid, pub container_ident_id: Option<Uuid>, + pub refs_blob_sha1: Option<String>, pub title: String, + pub original_title: Option<String>, pub release_type: Option<String>, pub release_status: Option<String>, pub release_date: Option<chrono::NaiveDate>, @@ -411,11 +418,14 @@ pub struct ReleaseRevNewRow { pub wikidata_qid: Option<String>, pub isbn13: Option<String>, pub core_id: Option<String>, + pub arxiv_id: Option<String>, + pub jstor_id: Option<String>, pub volume: Option<String>, pub issue: Option<String>, pub pages: Option<String>, pub publisher: Option<String>, pub language: Option<String>, + pub license_slug: Option<String>, } entity_structs!( @@ -476,6 +486,7 @@ pub struct ReleaseContribRow { pub creator_ident_id: Option<Uuid>, pub raw_name: Option<String>, pub role: Option<String>, + pub raw_affiliation: Option<String>, pub index_val: Option<i32>, pub extra_json: Option<serde_json::Value>, } @@ -487,39 +498,107 @@ pub struct ReleaseContribNewRow { pub creator_ident_id: Option<Uuid>, pub raw_name: Option<String>, pub role: Option<String>, + pub raw_affiliation: Option<String>, pub index_val: Option<i32>, pub extra_json: Option<serde_json::Value>, } -#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] +#[derive(Debug, Queryable, Insertable, Associations, AsChangeset)] #[table_name = "release_ref"] pub struct ReleaseRefRow { - pub id: i64, pub release_rev: Uuid, - pub target_release_ident_id: Option<Uuid>, - pub index_val: Option<i32>, - pub key: Option<String>, - pub extra_json: Option<serde_json::Value>, - pub container_name: Option<String>, - pub year: Option<i32>, - pub title: Option<String>, - pub locator: Option<String>, + pub index_val: i32, + pub target_release_ident_id: Uuid, } -#[derive(Debug, Insertable, AsChangeset)] -#[table_name = "release_ref"] -pub struct ReleaseRefNewRow { - pub release_rev: Uuid, - pub target_release_ident_id: Option<Uuid>, - pub index_val: Option<i32>, +#[derive(Debug, Queryable, Insertable, Associations, AsChangeset)] +#[table_name = "refs_blob"] +pub struct RefsBlobRow { + pub sha1: String, + pub refs_json: serde_json::Value, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +/// This model is a stable representation of what goes in a RefsBlobRow `refs_json` field (an array +/// of this model). We could rely on the `ReleaseRef` API spec model directly, but that would lock +/// the database contents to the API spec rigidly; by defining this struct independently, we can +/// migrate the schemas. To start, this is a direct copy of the `ReleaseRef` model. +pub struct RefsBlobJson { + #[serde(rename = "index")] + #[serde(skip_serializing_if = "Option::is_none")] + pub index: Option<i64>, + + /// base32-encoded unique identifier + #[serde(rename = "target_release_id")] + #[serde(skip_serializing_if = "Option::is_none")] + pub target_release_id: Option<String>, + + #[serde(rename = "extra")] + #[serde(skip_serializing_if = "Option::is_none")] + pub extra: Option<serde_json::Value>, + + #[serde(rename = "key")] + #[serde(skip_serializing_if = "Option::is_none")] pub key: Option<String>, - pub extra_json: Option<serde_json::Value>, + + #[serde(rename = "year")] + #[serde(skip_serializing_if = "Option::is_none")] + pub year: Option<i64>, + + #[serde(rename = "container_name")] + #[serde(skip_serializing_if = "Option::is_none")] pub container_name: Option<String>, - pub year: Option<i32>, + + #[serde(rename = "title")] + #[serde(skip_serializing_if = "Option::is_none")] pub title: Option<String>, + + #[serde(rename = "locator")] + #[serde(skip_serializing_if = "Option::is_none")] pub locator: Option<String>, } +impl RefsBlobJson { + pub fn into_model(self) -> ReleaseRef { + ReleaseRef { + index: self.index, + target_release_id: self.target_release_id, + extra: self.extra, + key: self.key, + year: self.year, + container_name: self.container_name, + title: self.title, + locator: self.locator, + } + } + + pub fn to_model(&self) -> ReleaseRef { + ReleaseRef { + index: self.index, + target_release_id: self.target_release_id.clone(), + extra: self.extra.clone(), + key: self.key.clone(), + year: self.year, + container_name: self.container_name.clone(), + title: self.title.clone(), + locator: self.locator.clone(), + } + } + + pub fn from_model(model: &ReleaseRef) -> RefsBlobJson { + RefsBlobJson { + index: model.index, + target_release_id: model.target_release_id.clone(), + extra: model.extra.clone(), + key: model.key.clone(), + year: model.year, + container_name: model.container_name.clone(), + title: model.title.clone(), + locator: model.locator.clone(), + } + } +} + #[derive(Debug, Queryable, Insertable, Associations, AsChangeset)] #[table_name = "file_rev_release"] pub struct FileRevReleaseRow { |