From cf858c018fd60c220d5c8a617809f64d8612971b Mon Sep 17 00:00:00 2001 From: rhigman <73792779+rhigman@users.noreply.github.com> Date: Mon, 29 Apr 2024 10:37:51 +0100 Subject: [PATCH] Add location migrations and update enum to include Zenodo --- CHANGELOG.md | 2 ++ thoth-api/migrations/v0.12.4/down.sql | 33 +++++++++++++++++++++++++++ thoth-api/migrations/v0.12.4/up.sql | 1 + thoth-api/src/model/location/mod.rs | 8 +++++++ 4 files changed, 44 insertions(+) create mode 100644 thoth-api/migrations/v0.12.4/down.sql create mode 100644 thoth-api/migrations/v0.12.4/up.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bcc4e3d..dadd6ef1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed + - [545](https://github.com/thoth-pub/thoth/issues/545) - Add Zenodo as a location platform ## [[0.12.3]](https://github.com/thoth-pub/thoth/releases/tag/v0.12.3) - 2024-04-26 ### Added diff --git a/thoth-api/migrations/v0.12.4/down.sql b/thoth-api/migrations/v0.12.4/down.sql new file mode 100644 index 00000000..96df703e --- /dev/null +++ b/thoth-api/migrations/v0.12.4/down.sql @@ -0,0 +1,33 @@ +UPDATE location SET location_platform = 'Other' WHERE location_platform = 'Zenodo'; + +-- 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', + 'Publisher Website', + '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.12.4/up.sql b/thoth-api/migrations/v0.12.4/up.sql new file mode 100644 index 00000000..6aadfa98 --- /dev/null +++ b/thoth-api/migrations/v0.12.4/up.sql @@ -0,0 +1 @@ +ALTER TYPE location_platform ADD VALUE IF NOT EXISTS 'Zenodo'; diff --git a/thoth-api/src/model/location/mod.rs b/thoth-api/src/model/location/mod.rs index faf28c29..2ed0c375 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 = "Zenodo")] + #[strum(serialize = "Zenodo")] + Zenodo, #[cfg_attr(feature = "backend", db_rename = "Publisher Website")] #[strum(serialize = "Publisher Website")] PublisherWebsite, @@ -183,6 +186,7 @@ fn test_locationplatform_display() { ); assert_eq!(format!("{}", LocationPlatform::ScienceOpen), "ScienceOpen"); assert_eq!(format!("{}", LocationPlatform::ScieloBooks), "SciELO Books"); + assert_eq!(format!("{}", LocationPlatform::Zenodo), "Zenodo"); assert_eq!( format!("{}", LocationPlatform::PublisherWebsite), "Publisher Website" @@ -249,6 +253,10 @@ fn test_locationplatform_fromstr() { LocationPlatform::from_str("SciELO Books").unwrap(), LocationPlatform::ScieloBooks ); + assert_eq!( + LocationPlatform::from_str("Zenodo").unwrap(), + LocationPlatform::Zenodo + ); assert_eq!( LocationPlatform::from_str("Publisher Website").unwrap(), LocationPlatform::PublisherWebsite