From 2991a4349f86cca8d1dcc978e3506f3032d5ebdd Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 24 May 2018 22:35:37 -0700 Subject: extra_json in SQL schema and implementation --- rust/migrations/2018-05-12-001226_init/up.sql | 20 ++++++++++---------- rust/src/api_server.rs | 14 ++++++++++++++ rust/src/database_models.rs | 12 ++++++------ rust/src/database_schema.rs | 10 ++++++++++ 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/rust/migrations/2018-05-12-001226_init/up.sql b/rust/migrations/2018-05-12-001226_init/up.sql index d8b93dc2..5d11191e 100644 --- a/rust/migrations/2018-05-12-001226_init/up.sql +++ b/rust/migrations/2018-05-12-001226_init/up.sql @@ -35,7 +35,7 @@ CREATE TABLE changelog ( -------------------- Creators ----------------------------------------------- CREATE TABLE creator_rev ( id BIGSERIAL PRIMARY KEY, - -- extra_json JSON, + extra_json JSON, name TEXT NOT NULL, orcid TEXT @@ -54,7 +54,7 @@ CREATE TABLE creator_ident ( CREATE TABLE creator_edit ( id BIGSERIAL PRIMARY KEY, - -- extra_json JSON, + extra_json JSON, ident_id UUID REFERENCES creator_ident(id) NOT NULL, rev_id BIGINT REFERENCES creator_rev(id), redirect_id UUID REFERENCES creator_ident(id), @@ -64,7 +64,7 @@ CREATE TABLE creator_edit ( -------------------- Containers -------------------------------------------- CREATE TABLE container_rev ( id BIGSERIAL PRIMARY KEY, - -- extra_json JSON, + extra_json JSON, name TEXT NOT NULL, publisher TEXT, @@ -82,7 +82,7 @@ CREATE TABLE container_ident ( CREATE TABLE container_edit ( id BIGSERIAL PRIMARY KEY, - -- extra_json JSON, + extra_json JSON, ident_id UUID REFERENCES container_ident(id) NOT NULL, rev_id BIGINT REFERENCES container_rev(id), redirect_id UUID REFERENCES container_ident(id), @@ -92,7 +92,7 @@ CREATE TABLE container_edit ( -------------------- Files ------------------------------------------------- CREATE TABLE file_rev ( id BIGSERIAL PRIMARY KEY, - -- extra_json JSON, + extra_json JSON, size BIGINT, sha1 TEXT, -- TODO: varchar or bytes @@ -108,7 +108,7 @@ CREATE TABLE file_ident ( CREATE TABLE file_edit ( id BIGSERIAL PRIMARY KEY, - -- extra_json JSON, + extra_json JSON, ident_id UUID REFERENCES file_ident(id) NOT NULL, rev_id BIGINT REFERENCES file_rev(id), redirect_id UUID REFERENCES file_ident(id), @@ -118,7 +118,7 @@ CREATE TABLE file_edit ( -------------------- Release ----------------------------------------------- CREATE TABLE release_rev ( id BIGSERIAL PRIMARY KEY, - -- extra_json JSON, + extra_json JSON, work_ident_id UUID NOT NULL, -- FOREIGN KEY; see ALRTER below container_ident_id UUID REFERENCES container_ident(id), @@ -142,7 +142,7 @@ CREATE TABLE release_ident ( CREATE TABLE release_edit ( id BIGSERIAL PRIMARY KEY, - -- extra_json JSON, + extra_json JSON, ident_id UUID REFERENCES release_ident(id) NOT NULL, rev_id BIGINT REFERENCES release_rev(id), redirect_id UUID REFERENCES release_ident(id), @@ -152,7 +152,7 @@ CREATE TABLE release_edit ( -------------------- Works -------------------------------------------------- CREATE TABLE work_rev ( id BIGSERIAL PRIMARY KEY, - -- extra_json JSON, + extra_json JSON, -- not even a work, for now work_type TEXT, -- TODO: enum? @@ -168,7 +168,7 @@ CREATE TABLE work_ident ( CREATE TABLE work_edit ( id BIGSERIAL PRIMARY KEY, - -- extra_json JSON, + extra_json JSON, ident_id UUID REFERENCES work_ident(id) NOT NULL, rev_id BIGINT REFERENCES work_rev(id), redirect_id UUID REFERENCES work_ident(id), diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index 7adf1a1d..9a2f3b56 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -101,6 +101,7 @@ impl Server { revision: ident.rev_id, redirect: ident.redirect_id.map(|u| u.to_string()), editgroup_id: None, + extra: rev.extra_json, }; Ok(Some(entity)) } @@ -131,6 +132,7 @@ impl Server { revision: ident.rev_id, redirect: ident.redirect_id.map(|u| u.to_string()), editgroup_id: None, + extra: rev.extra_json, }; Ok(Some(entity)) } @@ -158,6 +160,7 @@ impl Server { revision: ident.rev_id, redirect: ident.redirect_id.map(|u| u.to_string()), editgroup_id: None, + extra: rev.extra_json, }; Ok(Some(entity)) } @@ -186,6 +189,7 @@ impl Server { revision: ident.rev_id, redirect: ident.redirect_id.map(|u| u.to_string()), editgroup_id: None, + extra: rev.extra_json, }; Ok(Some(entity)) } @@ -214,6 +218,7 @@ impl Server { revision: ident.rev_id.map(|v| v), redirect: ident.redirect_id.map(|u| u.to_string()), editgroup_id: None, + extra: rev.extra_json, }; Ok(Some(entity)) } @@ -243,6 +248,7 @@ impl Server { revision: ident.rev_id.map(|v| v), redirect: ident.redirect_id.map(|u| u.to_string()), editgroup_id: None, + extra: rev.extra_json, }; Ok(Some(entity)) } @@ -269,6 +275,7 @@ impl Server { revision: ident.rev_id, redirect: ident.redirect_id.map(|u| u.to_string()), editgroup_id: None, + extra: rev.extra_json, }; Ok(Some(entity)) } @@ -303,6 +310,7 @@ impl Server { revision: ident.rev_id, redirect: ident.redirect_id.map(|u| u.to_string()), editgroup_id: None, + extra: rev.extra_json, }; Ok(Some(entity)) } @@ -338,6 +346,7 @@ impl Server { revision: ident.rev_id, redirect: ident.redirect_id.map(|u| u.to_string()), editgroup_id: None, + extra: rev.extra_json, }; Ok(Some(entity)) } @@ -485,6 +494,7 @@ impl Api for Server { revision: Some(edit.rev_id.unwrap()), ident: Some(edit.ident_id.to_string()), edit_id: Some(edit.id), + extra: edit.extra_json.clone(), }; Box::new(futures::done(Ok(ContainerPostResponse::CreatedEntity( entity_edit, @@ -525,6 +535,7 @@ impl Api for Server { revision: Some(edit.rev_id.unwrap()), ident: Some(edit.ident_id.to_string()), edit_id: Some(edit.id), + extra: edit.extra_json.clone(), }; Box::new(futures::done(Ok(CreatorPostResponse::CreatedEntity( entity_edit, @@ -567,6 +578,7 @@ impl Api for Server { revision: Some(edit.rev_id.unwrap()), ident: Some(edit.ident_id.to_string()), edit_id: Some(edit.id), + extra: edit.extra_json.clone(), }; Box::new(futures::done(Ok(FilePostResponse::CreatedEntity( entity_edit, @@ -607,6 +619,7 @@ impl Api for Server { revision: Some(edit.rev_id.unwrap()), ident: Some(edit.ident_id.to_string()), edit_id: Some(edit.id), + extra: edit.extra_json.clone(), }; Box::new(futures::done(Ok(WorkPostResponse::CreatedEntity( entity_edit, @@ -660,6 +673,7 @@ impl Api for Server { revision: Some(edit.rev_id.unwrap()), ident: Some(edit.ident_id.to_string()), edit_id: Some(edit.id), + extra: edit.extra_json.clone(), }; Box::new(futures::done(Ok(ReleasePostResponse::CreatedEntity( entity_edit, diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs index d871d55d..732ceeeb 100644 --- a/rust/src/database_models.rs +++ b/rust/src/database_models.rs @@ -40,7 +40,7 @@ macro_rules! entity_structs { pub rev_id: Option, pub redirect_id: Option, pub editgroup_id: i64, - //pub extra_json: Option, + pub extra_json: Option, } #[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] @@ -72,7 +72,7 @@ macro_rules! entity_structs { #[table_name = "container_rev"] pub struct ContainerRevRow { pub id: i64, - //pub extra_json: Option, + pub extra_json: Option, pub name: String, pub publisher: Option, pub issn: Option, @@ -89,7 +89,7 @@ entity_structs!( #[table_name = "creator_rev"] pub struct CreatorRevRow { pub id: i64, - //extra_json: Option, + pub extra_json: Option, pub name: String, pub orcid: Option, } @@ -105,7 +105,7 @@ entity_structs!( #[table_name = "file_rev"] pub struct FileRevRow { pub id: i64, - //extra_json: Option, + pub extra_json: Option, pub size: Option, pub sha1: Option, pub url: Option, @@ -117,7 +117,7 @@ entity_structs!("file_edit", FileEditRow, "file_ident", FileIdentRow); #[table_name = "release_rev"] pub struct ReleaseRevRow { pub id: i64, - //extra_json: Option, + pub extra_json: Option, pub work_ident_id: Uuid, pub container_ident_id: Option, pub title: String, @@ -140,7 +140,7 @@ entity_structs!( #[table_name = "work_rev"] pub struct WorkRevRow { pub id: i64, - //extra_json: Option, + pub extra_json: Option, pub work_type: Option, pub primary_release_id: Option, } diff --git a/rust/src/database_schema.rs b/rust/src/database_schema.rs index 6856b19c..5ce407b6 100644 --- a/rust/src/database_schema.rs +++ b/rust/src/database_schema.rs @@ -9,6 +9,7 @@ table! { table! { container_edit (id) { id -> Int8, + extra_json -> Nullable, ident_id -> Uuid, rev_id -> Nullable, redirect_id -> Nullable, @@ -28,6 +29,7 @@ table! { table! { container_rev (id) { id -> Int8, + extra_json -> Nullable, name -> Text, publisher -> Nullable, issn -> Nullable, @@ -37,6 +39,7 @@ table! { table! { creator_edit (id) { id -> Int8, + extra_json -> Nullable, ident_id -> Uuid, rev_id -> Nullable, redirect_id -> Nullable, @@ -56,6 +59,7 @@ table! { table! { creator_rev (id) { id -> Int8, + extra_json -> Nullable, name -> Text, orcid -> Nullable, } @@ -82,6 +86,7 @@ table! { table! { file_edit (id) { id -> Int8, + extra_json -> Nullable, ident_id -> Uuid, rev_id -> Nullable, redirect_id -> Nullable, @@ -108,6 +113,7 @@ table! { table! { file_rev (id) { id -> Int8, + extra_json -> Nullable, size -> Nullable, sha1 -> Nullable, url -> Nullable, @@ -127,6 +133,7 @@ table! { table! { release_edit (id) { id -> Int8, + extra_json -> Nullable, ident_id -> Uuid, rev_id -> Nullable, redirect_id -> Nullable, @@ -156,6 +163,7 @@ table! { table! { release_rev (id) { id -> Int8, + extra_json -> Nullable, work_ident_id -> Uuid, container_ident_id -> Nullable, title -> Text, @@ -171,6 +179,7 @@ table! { table! { work_edit (id) { id -> Int8, + extra_json -> Nullable, ident_id -> Uuid, rev_id -> Nullable, redirect_id -> Nullable, @@ -190,6 +199,7 @@ table! { table! { work_rev (id) { id -> Int8, + extra_json -> Nullable, work_type -> Nullable, primary_release_id -> Nullable, } -- cgit v1.2.3