From 3b497d0be9f5b6588f871f37ee3b595878003f46 Mon Sep 17 00:00:00 2001 From: Brendan OConnell Date: Thu, 15 Feb 2024 16:45:10 +0100 Subject: [PATCH] Added publisher website to locationPlatform --- CHANGELOG.md | 1 + thoth-api/migrations/v0.11.16/down.sql | 34 ++++++++++++++++++++++++++ thoth-api/migrations/v0.11.16/up.sql | 1 + thoth-api/src/model/location/mod.rs | 8 ++++++ 4 files changed, 44 insertions(+) create mode 100644 thoth-api/migrations/v0.11.16/down.sql create mode 100644 thoth-api/migrations/v0.11.16/up.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 753db81f..b34c5140 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Changed + - [561](https://github.com/thoth-pub/thoth/issues/561) - Add PUBLISHER_WEBSITE as a location platform - [553](https://github.com/thoth-pub/thoth/pull/553) - Upgrade rust to `1.76.0` in production and development `Dockerfile` - [305](https://github.com/thoth-pub/thoth/issues/305) - Update rust edition to 2021 - [555](https://github.com/thoth-pub/thoth/pull/555) - Remove thoth-client's schema.json with auto-generated GraphQL schema language file on compilation diff --git a/thoth-api/migrations/v0.11.16/down.sql b/thoth-api/migrations/v0.11.16/down.sql new file mode 100644 index 00000000..5a1c9039 --- /dev/null +++ b/thoth-api/migrations/v0.11.16/down.sql @@ -0,0 +1,34 @@ +UPDATE location SET location_platform = 'Other' WHERE location_platform IN ( + 'Publisher Website', +); + +-- Drop the default and unique constraint, otherwise it won't be able to cast to text +ALTER TABLE location ALTER COLUMN location_platform DROP DEFAULT; +DROP INDEX location_uniq_platform_idx; + +ALTER TABLE location ALTER COLUMN location_platform TYPE text; +DROP TYPE location_platform; +CREATE TYPE location_platform AS ENUM ( + 'Project MUSE', + 'OAPEN', + 'DOAB', + 'JSTOR', + 'EBSCO Host', + 'OCLC KB', + 'ProQuest KB', + 'ProQuest ExLibris', + 'EBSCO KB', + 'JISC KB', + 'Google Books', + 'Internet Archive', + 'ScienceOpen', + 'SciELO Books' + 'Other' + ); +ALTER TABLE location ALTER location_platform TYPE location_platform USING location_platform::location_platform; +ALTER TABLE location + ALTER COLUMN location_platform SET DEFAULT 'Other'::location_platform; + +CREATE UNIQUE INDEX location_uniq_platform_idx + ON location (publication_id, location_platform) + WHERE NOT location_platform = 'Other'::location_platform; diff --git a/thoth-api/migrations/v0.11.16/up.sql b/thoth-api/migrations/v0.11.16/up.sql new file mode 100644 index 00000000..addc5d68 --- /dev/null +++ b/thoth-api/migrations/v0.11.16/up.sql @@ -0,0 +1 @@ +ALTER TYPE location_platform ADD VALUE 'Publisher Website'; diff --git a/thoth-api/src/model/location/mod.rs b/thoth-api/src/model/location/mod.rs index 1276b14e..2ba4e893 100644 --- a/thoth-api/src/model/location/mod.rs +++ b/thoth-api/src/model/location/mod.rs @@ -60,6 +60,9 @@ pub enum LocationPlatform { #[cfg_attr(feature = "backend", db_rename = "SciELO Books")] #[strum(serialize = "SciELO Books")] ScieloBooks, + #[cfg_attr(feature = "backend", db_rename = "Publisher Website")] + #[strum(serialize = "Publisher Website")] + PublisherWebsite, #[cfg_attr(feature = "backend", db_rename = "Other")] #[default] Other, @@ -180,6 +183,7 @@ fn test_locationplatform_display() { ); assert_eq!(format!("{}", LocationPlatform::ScienceOpen), "ScienceOpen"); assert_eq!(format!("{}", LocationPlatform::ScieloBooks), "SciELO Books"); + assert_eq!(format!("{}", LocationPlatform::PublisherWebsite), "Publisher Website"); assert_eq!(format!("{}", LocationPlatform::Other), "Other"); } @@ -242,6 +246,10 @@ fn test_locationplatform_fromstr() { LocationPlatform::from_str("SciELO Books").unwrap(), LocationPlatform::ScieloBooks ); + assert_eq!( + LocationPlatform::from_str("Publisher Website").unwrap(), + LocationPlatform::PublisherWebsite + ); assert_eq!( LocationPlatform::from_str("Other").unwrap(), LocationPlatform::Other