aboutsummaryrefslogtreecommitdiffstats
path: root/rust
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-05-08 23:41:38 -0700
committerBryan Newbold <bnewbold@robocracy.org>2019-05-08 23:41:38 -0700
commitf7c1d9f49854f616e335c8a904e709624a51b0b3 (patch)
treecc7a753dc652d190364e62dd92096417f4c12037 /rust
parent18eff40d11a4c9deaf65bb5a43e7c3efb33aa1d0 (diff)
downloadfatcat-f7c1d9f49854f616e335c8a904e709624a51b0b3.tar.gz
fatcat-f7c1d9f49854f616e335c8a904e709624a51b0b3.zip
basic impl of new SQL schema in rust code (not wired to API)
Diffstat (limited to 'rust')
-rw-r--r--rust/src/database_models.rs36
-rw-r--r--rust/src/entity_crud.rs36
-rw-r--r--rust/src/identifiers.rs18
3 files changed, 71 insertions, 19 deletions
diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs
index adb38bda..e7918ec5 100644
--- a/rust/src/database_models.rs
+++ b/rust/src/database_models.rs
@@ -161,10 +161,10 @@ pub struct CreatorRevRow {
pub id: Uuid,
pub extra_json: Option<serde_json::Value>,
pub display_name: String,
- pub given_name: Option<String>,
- pub surname: Option<String>,
pub orcid: Option<String>,
pub wikidata_qid: Option<String>,
+ pub given_name: Option<String>,
+ pub surname: Option<String>,
}
#[derive(Debug, Associations, AsChangeset, Insertable)]
@@ -172,10 +172,10 @@ pub struct CreatorRevRow {
pub struct CreatorRevNewRow {
pub extra_json: Option<serde_json::Value>,
pub display_name: String,
- pub given_name: Option<String>,
- pub surname: Option<String>,
pub orcid: Option<String>,
pub wikidata_qid: Option<String>,
+ pub given_name: Option<String>,
+ pub surname: Option<String>,
}
entity_structs!(
@@ -311,6 +311,8 @@ pub struct WebcaptureRevCdxRow {
pub status_code: Option<i64>,
pub sha1: String,
pub sha256: Option<String>,
+ pub size_bytes: Option<i64>,
+ pub extra_json: Option<serde_json::Value>,
}
#[derive(Debug, Queryable, Associations, AsChangeset, Insertable)]
@@ -324,6 +326,8 @@ pub struct WebcaptureRevCdxNewRow {
pub status_code: Option<i64>,
pub sha1: String,
pub sha256: Option<String>,
+ pub size_bytes: Option<i64>,
+ pub extra_json: Option<serde_json::Value>,
}
#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)]
@@ -380,7 +384,7 @@ pub struct ReleaseRevRow {
pub title: String,
pub original_title: Option<String>,
pub release_type: Option<String>,
- pub release_status: Option<String>,
+ pub release_stage: Option<String>,
pub release_date: Option<chrono::NaiveDate>,
pub release_year: Option<i64>,
pub doi: Option<String>,
@@ -397,6 +401,14 @@ pub struct ReleaseRevRow {
pub publisher: Option<String>,
pub language: Option<String>,
pub license_slug: Option<String>,
+ pub number: Option<String>,
+ pub version: Option<String>,
+ pub subtitle: Option<String>,
+ pub withdrawn_state: Option<String>,
+ pub withdrawn_date: Option<chrono::NaiveDate>,
+ pub withdrawn_year: Option<i64>,
+ pub mag_id: Option<String>,
+ pub ark_id: Option<String>,
}
#[derive(Debug, Associations, AsChangeset, Insertable)]
@@ -409,7 +421,7 @@ pub struct ReleaseRevNewRow {
pub title: String,
pub original_title: Option<String>,
pub release_type: Option<String>,
- pub release_status: Option<String>,
+ pub release_stage: Option<String>,
pub release_date: Option<chrono::NaiveDate>,
pub release_year: Option<i64>,
pub doi: Option<String>,
@@ -426,6 +438,14 @@ pub struct ReleaseRevNewRow {
pub publisher: Option<String>,
pub language: Option<String>,
pub license_slug: Option<String>,
+ pub number: Option<String>,
+ pub version: Option<String>,
+ pub subtitle: Option<String>,
+ pub withdrawn_state: Option<String>,
+ pub withdrawn_date: Option<chrono::NaiveDate>,
+ pub withdrawn_year: Option<i64>,
+ pub mag_id: Option<String>,
+ pub ark_id: Option<String>,
}
entity_structs!(
@@ -489,6 +509,8 @@ pub struct ReleaseContribRow {
pub raw_affiliation: Option<String>,
pub index_val: Option<i32>,
pub extra_json: Option<serde_json::Value>,
+ pub given_name: Option<String>,
+ pub surname: Option<String>,
}
#[derive(Debug, Insertable)]
@@ -501,6 +523,8 @@ pub struct ReleaseContribNewRow {
pub raw_affiliation: Option<String>,
pub index_val: Option<i32>,
pub extra_json: Option<serde_json::Value>,
+ pub given_name: Option<String>,
+ pub surname: Option<String>,
}
#[derive(Debug, Queryable, Insertable, Associations, AsChangeset)]
diff --git a/rust/src/entity_crud.rs b/rust/src/entity_crud.rs
index faf4b496..cbee1fdd 100644
--- a/rust/src/entity_crud.rs
+++ b/rust/src/entity_crud.rs
@@ -1441,8 +1441,10 @@ impl EntityCrud for WebcaptureEntity {
url: c.url,
mimetype: c.mimetype,
status_code: c.status_code,
+ // XXX: size_bytes: c.size_bytes,
sha1: c.sha1,
sha256: c.sha256,
+ // XXX: extra_json: c.extra
})
.collect();
@@ -1529,8 +1531,10 @@ impl EntityCrud for WebcaptureEntity {
url: c.url.clone(),
mimetype: c.mimetype.clone(),
status_code: c.status_code,
+ size_bytes: None, // XXX: c.size_bytes,
sha1: c.sha1.clone(),
sha256: c.sha256.clone(),
+ extra_json: None, // XXX: c.extra
})
.collect();
webcapture_cdx_rows.extend(these_cdx_rows);
@@ -1616,11 +1620,15 @@ impl EntityCrud for ReleaseEntity {
Ok(ReleaseEntity {
title: None,
+ // XXX: subtitle: None,
original_title: None,
release_type: None,
release_status: None,
release_date: None,
release_year: None,
+ // XXX: withdrawn_state: None,
+ // XXX: withdrawn_date: None,
+ // XXX: withdrawn_year: None,
doi: None,
pmid: None,
pmcid: None,
@@ -1629,9 +1637,13 @@ impl EntityCrud for ReleaseEntity {
core_id: None,
arxiv_id: None,
jstor_id: None,
+ // XXX: ark_id: None,
+ // XXX: mag_id: None,
volume: None,
issue: None,
pages: None,
+ // XXX: number: None,
+ // XXX: version: None,
files: None,
filesets: None,
webcaptures: None,
@@ -1871,6 +1883,8 @@ impl EntityCrud for ReleaseEntity {
.map(|c: ReleaseContribRow| ReleaseContrib {
index: c.index_val.map(|v| v as i64),
raw_name: c.raw_name,
+ // XXX: given_name: c.given_name,
+ // XXX: surname: c.surname,
role: c.role,
raw_affiliation: c.raw_affiliation,
extra: c.extra_json,
@@ -1908,7 +1922,7 @@ impl EntityCrud for ReleaseEntity {
title: Some(rev_row.title),
original_title: rev_row.original_title,
release_type: rev_row.release_type,
- release_status: rev_row.release_status,
+ release_status: rev_row.release_stage,
release_date: rev_row.release_date,
release_year: rev_row.release_year,
doi: rev_row.doi,
@@ -1919,9 +1933,13 @@ impl EntityCrud for ReleaseEntity {
core_id: rev_row.core_id,
arxiv_id: rev_row.arxiv_id,
jstor_id: rev_row.jstor_id,
+ // XXX: ark_id: rev_row.ark_id,
+ // XXX: mag_id: rev_row.mag_id,
volume: rev_row.volume,
issue: rev_row.issue,
pages: rev_row.pages,
+ // XXX: number: rev_row.number,
+ // XXX: version: rev_row.version,
files: None,
filesets: None,
webcaptures: None,
@@ -1964,8 +1982,8 @@ impl EntityCrud for ReleaseEntity {
if let Some(ref release_type) = entity.release_type {
check_release_type(release_type)?;
}
- if let Some(ref release_status) = entity.release_status {
- check_release_status(release_status)?;
+ if let Some(ref release_stage) = entity.release_status {
+ check_release_stage(release_stage)?;
}
if let Some(ref abstracts) = entity.abstracts {
if abstracts.len() > 200 {
@@ -2063,11 +2081,15 @@ impl EntityCrud for ReleaseEntity {
Ok(ReleaseRevNewRow {
refs_blob_sha1: refs_sha1,
title: model.title.clone().unwrap(), // titles checked above
+ subtitle: None, // XXX: model.original_title.clone(),
original_title: model.original_title.clone(),
release_type: model.release_type.clone(),
- release_status: model.release_status.clone(),
+ release_stage: model.release_status.clone(),
release_date: model.release_date,
release_year: model.release_year,
+ withdrawn_state: None, // XXX: model.withdrawn_state.clone(),
+ withdrawn_date: None, // XXX: model.withdrawn_date,
+ withdrawn_year: None, // XXX: model.withdrawn_year,
doi: model.doi.clone(),
pmid: model.pmid.clone(),
pmcid: model.pmcid.clone(),
@@ -2076,9 +2098,13 @@ impl EntityCrud for ReleaseEntity {
core_id: model.core_id.clone(),
arxiv_id: model.arxiv_id.clone(),
jstor_id: model.jstor_id.clone(),
+ ark_id: None, // XXX: model.ark_id.clone(),
+ mag_id: None, // XXX: model.mag_id.clone(),
volume: model.volume.clone(),
issue: model.issue.clone(),
pages: model.pages.clone(),
+ number: None, // XXX: model.number.clone(),
+ version: None, // XXX: model.version.clone(),
work_ident_id: match model.work_id.clone() {
None => bail!("release_revs must have a work_id by the time they are inserted; this is an internal soundness error"),
Some(s) => FatcatId::from_str(&s)?.to_uuid(),
@@ -2141,6 +2167,8 @@ impl EntityCrud for ReleaseEntity {
Some(v) => Some(FatcatId::from_str(&v)?.to_uuid()),
},
raw_name: c.raw_name.clone(),
+ given_name: None, // XXX: c.given_name.clone(),
+ surname: None, // XXX: c.surname.clone(),
index_val: c.index.map(|v| v as i32),
role: c.role.clone(),
raw_affiliation: c.raw_affiliation.clone(),
diff --git a/rust/src/identifiers.rs b/rust/src/identifiers.rs
index ed88939d..18423643 100644
--- a/rust/src/identifiers.rs
+++ b/rust/src/identifiers.rs
@@ -342,7 +342,7 @@ fn test_check_release_type() {
assert!(check_release_type("book ").is_err());
}
-pub fn check_release_status(raw: &str) -> Result<()> {
+pub fn check_release_stage(raw: &str) -> Result<()> {
let valid_types = vec![
// DRIVER types (minus "version" suffix)
"draft",
@@ -359,19 +359,19 @@ pub fn check_release_status(raw: &str) -> Result<()> {
}
}
Err(FatcatError::NotInControlledVocabulary(
- "release_status".to_string(),
+ "release_stage".to_string(),
raw.to_string(),
))?
}
#[test]
-fn test_check_release_status() {
- assert!(check_release_status("draft").is_ok());
- assert!(check_release_status("retraction").is_ok());
- assert!(check_release_status("published").is_ok());
- assert!(check_release_status("pre-print").is_err());
- assert!(check_release_status("DRAFT").is_err());
- assert!(check_release_status("draft ").is_err());
+fn test_check_release_stage() {
+ assert!(check_release_stage("draft").is_ok());
+ assert!(check_release_stage("retraction").is_ok());
+ assert!(check_release_stage("published").is_ok());
+ assert!(check_release_stage("pre-print").is_err());
+ assert!(check_release_stage("DRAFT").is_err());
+ assert!(check_release_stage("draft ").is_err());
}
pub fn check_contrib_role(raw: &str) -> Result<()> {