From 55f8a495354d233f7a68128b2f3c21dbe7395427 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sat, 26 May 2018 17:08:21 -0700 Subject: tweak schema (api and sql) --- rust/src/api_server.rs | 59 ++++++++++++++++++++++++++++----------------- rust/src/database_models.rs | 17 ++++++++----- rust/src/database_schema.rs | 11 ++++++--- 3 files changed, 56 insertions(+), 31 deletions(-) (limited to 'rust/src') diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index 8311896f..42c69c00 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -94,9 +94,11 @@ impl Server { }; let entity = ContainerEntity { - issn: rev.issn, + issnl: rev.issnl, publisher: rev.publisher, name: rev.name, + abbrev: rev.abbrev, + coden: rev.coden, state: Some(ident.state().unwrap().shortname()), ident: Some(ident.id.to_string()), revision: ident.rev_id, @@ -107,13 +109,13 @@ impl Server { Ok(Some(entity)) } - fn container_lookup_get_handler(&self, issn: String) -> Result> { + fn container_lookup_get_handler(&self, issnl: String) -> Result> { let conn = self.db_pool.get().expect("db_pool error"); let res: ::std::result::Result<(ContainerIdentRow, ContainerRevRow), _> = container_ident::table .inner_join(container_rev::table) - .filter(container_rev::issn.eq(&issn)) + .filter(container_rev::issnl.eq(&issnl)) .filter(container_ident::is_live.eq(true)) .filter(container_ident::redirect_id.is_null()) .first(&conn); @@ -125,9 +127,11 @@ impl Server { }; let entity = ContainerEntity { - issn: rev.issn, + issnl: rev.issnl, publisher: rev.publisher, name: rev.name, + abbrev: rev.abbrev, + coden: rev.coden, state: Some(ident.state().unwrap().shortname()), ident: Some(ident.id.to_string()), revision: ident.rev_id, @@ -154,7 +158,7 @@ impl Server { }; let entity = CreatorEntity { - name: rev.name, + full_name: rev.full_name, orcid: rev.orcid, state: Some(ident.state().unwrap().shortname()), ident: Some(ident.id.to_string()), @@ -183,7 +187,7 @@ impl Server { }; let entity = CreatorEntity { - name: rev.name, + full_name: rev.full_name, orcid: rev.orcid, state: Some(ident.state().unwrap().shortname()), ident: Some(ident.id.to_string()), @@ -220,6 +224,7 @@ impl Server { let entity = FileEntity { sha1: rev.sha1, + md5: rev.md5, size: rev.size.map(|v| v as i64), url: rev.url, releases: Some(releases), @@ -260,6 +265,7 @@ impl Server { let entity = FileEntity { sha1: rev.sha1, + md5: rev.md5, size: rev.size.map(|v| v as i64), url: rev.url, releases: Some(releases), @@ -334,7 +340,7 @@ impl Server { .iter() .map(|c: &ReleaseContribRow| ReleaseContrib { index: c.index, - contrib_type: c.contrib_type.clone(), + role: c.role.clone(), creator_stub: c.stub.clone(), creator_id: c.creator_ident_id.map(|v| v.to_string()), }) @@ -346,10 +352,12 @@ impl Server { date: rev.date .map(|v| chrono::DateTime::from_utc(v.and_hms(0, 0, 0), chrono::Utc)), doi: rev.doi, + isbn13: rev.isbn13, volume: rev.volume, pages: rev.pages, issue: rev.issue, container_id: rev.container_ident_id.map(|u| u.to_string()), + publisher: rev.publisher, work_id: rev.work_ident_id.to_string(), refs: Some(refs), contribs: Some(contribs), @@ -398,7 +406,7 @@ impl Server { .iter() .map(|c: &ReleaseContribRow| ReleaseContrib { index: c.index, - contrib_type: c.contrib_type.clone(), + role: c.role.clone(), creator_stub: c.stub.clone(), creator_id: c.creator_ident_id.map(|v| v.to_string()), }) @@ -410,10 +418,12 @@ impl Server { date: rev.date .map(|v| chrono::DateTime::from_utc(v.and_hms(0, 0, 0), chrono::Utc)), doi: rev.doi, + isbn13: rev.isbn13, volume: rev.volume, pages: rev.pages, issue: rev.issue, container_id: rev.container_ident_id.map(|u| u.to_string()), + publisher: rev.publisher, work_id: rev.work_ident_id.to_string(), refs: Some(refs), contribs: Some(contribs), @@ -594,7 +604,7 @@ impl Api for Server { container_lookup_get, container_lookup_get_handler, ContainerLookupGetResponse, - issn, + issnl, String ); wrap_lookup_handler!( @@ -632,18 +642,20 @@ impl Api for Server { }; let edit: ContainerEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO container_rev (name, publisher, issn, extra_json) - VALUES ($1, $2, $3, $4) + "WITH rev AS ( INSERT INTO container_rev (name, publisher, issnl, abbrev, coden, extra_json) + VALUES ($1, $2, $3, $4, $5, $6) RETURNING id ), ident AS ( INSERT INTO container_ident (rev_id) VALUES ((SELECT rev.id FROM rev)) RETURNING id ) INSERT INTO container_edit (editgroup_id, ident_id, rev_id) VALUES - ($5, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($7, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", ).bind::(body.name) .bind::, _>(body.publisher) - .bind::, _>(body.issn) + .bind::, _>(body.issnl) + .bind::, _>(body.abbrev) + .bind::, _>(body.coden) .bind::, _>(body.extra) .bind::(editgroup_id) .get_result(&conn) @@ -676,7 +688,7 @@ impl Api for Server { }; let edit: CreatorEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO creator_rev (name, orcid, extra_json) + "WITH rev AS ( INSERT INTO creator_rev (full_name, orcid, extra_json) VALUES ($1, $2, $3) RETURNING id ), ident AS ( INSERT INTO creator_ident (rev_id) @@ -685,7 +697,7 @@ impl Api for Server { INSERT INTO creator_edit (editgroup_id, ident_id, rev_id) VALUES ($4, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", - ).bind::(body.name) + ).bind::(body.full_name) .bind::, _>(body.orcid) .bind::, _>(body.extra) .bind::(editgroup_id) @@ -720,17 +732,18 @@ impl Api for Server { let edit: FileEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO file_rev (size, sha1, url, extra_json) - VALUES ($1, $2, $3, $4) + "WITH rev AS ( INSERT INTO file_rev (size, sha1, md5, url, extra_json) + VALUES ($1, $2, $3, $4, $5) RETURNING id ), ident AS ( INSERT INTO file_ident (rev_id) VALUES ((SELECT rev.id FROM rev)) RETURNING id ) INSERT INTO file_edit (editgroup_id, ident_id, rev_id) VALUES - ($5, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($6, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", ).bind::, _>(body.size) .bind::, _>(body.sha1) + .bind::, _>(body.md5) .bind::, _>(body.url) .bind::, _>(body.extra) .bind::(editgroup_id) @@ -835,24 +848,26 @@ impl Api for Server { }; let edit: ReleaseEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO release_rev (title, release_type, date, doi, volume, pages, issue, work_ident_id, container_ident_id, extra_json) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) + "WITH rev AS ( INSERT INTO release_rev (title, release_type, date, doi, isbn13, volume, pages, issue, work_ident_id, container_ident_id, publisher, extra_json) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING id ), ident AS ( INSERT INTO release_ident (rev_id) VALUES ((SELECT rev.id FROM rev)) RETURNING id ) INSERT INTO release_edit (editgroup_id, ident_id, rev_id) VALUES - ($11, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($13, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", ).bind::(body.title) .bind::, _>(body.release_type) .bind::, _>(body.date.map(|v| v.naive_utc().date())) .bind::, _>(body.doi) + .bind::, _>(body.isbn13) .bind::, _>(body.volume) .bind::, _>(body.pages) .bind::, _>(body.issue) .bind::(work_id) .bind::, _>(container_id) + .bind::, _>(body.publisher) .bind::, _>(body.extra) .bind::(editgroup_id) .get_result(&conn) @@ -899,7 +914,7 @@ impl Api for Server { .clone() .map(|v| uuid::Uuid::parse_str(&v).expect("valid UUID")), index: c.index, - contrib_type: c.contrib_type.clone(), + role: c.role.clone(), stub: c.creator_stub.clone(), }) .collect(); diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs index b27bca3f..9913b7e2 100644 --- a/rust/src/database_models.rs +++ b/rust/src/database_models.rs @@ -75,7 +75,9 @@ pub struct ContainerRevRow { pub extra_json: Option, pub name: String, pub publisher: Option, - pub issn: Option, + pub issnl: Option, + pub abbrev: Option, + pub coden: Option, } entity_structs!( @@ -90,7 +92,7 @@ entity_structs!( pub struct CreatorRevRow { pub id: i64, pub extra_json: Option, - pub name: String, + pub full_name: String, pub orcid: Option, } @@ -108,6 +110,7 @@ pub struct FileRevRow { pub extra_json: Option, pub size: Option, pub sha1: Option, + pub md5: Option, pub url: Option, } @@ -124,9 +127,11 @@ pub struct ReleaseRevRow { pub release_type: Option, pub date: Option, pub doi: Option, + pub isbn13: Option, pub volume: Option, pub pages: Option, pub issue: Option, + pub publisher: Option, } entity_structs!( @@ -153,9 +158,9 @@ pub struct ReleaseContribRow { pub id: i64, pub release_rev: i64, pub creator_ident_id: Option, - pub stub: Option, + pub role: Option, pub index: Option, - pub contrib_type: Option, + pub stub: Option, } #[derive(Debug, Insertable)] @@ -163,9 +168,9 @@ pub struct ReleaseContribRow { pub struct ReleaseContribNewRow { pub release_rev: i64, pub creator_ident_id: Option, - pub stub: Option, + pub role: Option, pub index: Option, - pub contrib_type: Option, + pub stub: Option, } #[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] diff --git a/rust/src/database_schema.rs b/rust/src/database_schema.rs index 7d8ff4e1..2541bcd8 100644 --- a/rust/src/database_schema.rs +++ b/rust/src/database_schema.rs @@ -32,7 +32,9 @@ table! { extra_json -> Nullable, name -> Text, publisher -> Nullable, - issn -> Nullable, + issnl -> Nullable, + abbrev -> Nullable, + coden -> Nullable, } } @@ -60,7 +62,7 @@ table! { creator_rev (id) { id -> Int8, extra_json -> Nullable, - name -> Text, + full_name -> Text, orcid -> Nullable, } } @@ -116,6 +118,7 @@ table! { extra_json -> Nullable, size -> Nullable, sha1 -> Nullable, + md5 -> Nullable, url -> Nullable, } } @@ -125,7 +128,7 @@ table! { id -> Int8, release_rev -> Int8, creator_ident_id -> Nullable, - contrib_type -> Nullable, + role -> Nullable, index -> Nullable, stub -> Nullable, } @@ -171,9 +174,11 @@ table! { release_type -> Nullable, date -> Nullable, doi -> Nullable, + isbn13 -> Nullable, volume -> Nullable, pages -> Nullable, issue -> Nullable, + publisher -> Nullable, } } -- cgit v1.2.3