diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a074f77..f27c81f0 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] +### Added +- [648](https://github.com/thoth-pub/thoth/issues/648) - Added new `LocationPlatform`, `THOTH`, for Locations where file is hosted directly by Thoth on S3. ## [[0.12.14]](https://github.com/thoth-pub/thoth/releases/tag/v0.12.14) - 2024-11-04 ### Changed diff --git a/thoth-api/migrations/v0.13.0/down.sql b/thoth-api/migrations/v0.13.0/down.sql new file mode 100644 index 00000000..7207af34 --- /dev/null +++ b/thoth-api/migrations/v0.13.0/down.sql @@ -0,0 +1,34 @@ +UPDATE location SET location_platform = 'Other' WHERE location_platform = 'Thoth'; + +-- 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', + 'Zenodo', + '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.13.0/up.sql b/thoth-api/migrations/v0.13.0/up.sql new file mode 100644 index 00000000..505e038b --- /dev/null +++ b/thoth-api/migrations/v0.13.0/up.sql @@ -0,0 +1 @@ +ALTER TYPE location_platform ADD VALUE IF NOT EXISTS 'Thoth'; diff --git a/thoth-api/src/model/location/mod.rs b/thoth-api/src/model/location/mod.rs index fba42a0a..8e7c8784 100644 --- a/thoth-api/src/model/location/mod.rs +++ b/thoth-api/src/model/location/mod.rs @@ -135,6 +135,13 @@ pub enum LocationPlatform { )] #[strum(serialize = "Publisher Website")] PublisherWebsite, + #[cfg_attr( + feature = "backend", + db_rename = "Thoth", + graphql(description = "Publisher CDN hosted by Thoth") + )] + #[strum(serialize = "Thoth")] + Thoth, #[cfg_attr( feature = "backend", db_rename = "Other", @@ -311,6 +318,7 @@ fn test_locationplatform_display() { format!("{}", LocationPlatform::PublisherWebsite), "Publisher Website" ); + assert_eq!(format!("{}", LocationPlatform::Thoth), "Thoth"); assert_eq!(format!("{}", LocationPlatform::Other), "Other"); } @@ -381,6 +389,10 @@ fn test_locationplatform_fromstr() { LocationPlatform::from_str("Publisher Website").unwrap(), LocationPlatform::PublisherWebsite ); + assert_eq!( + LocationPlatform::from_str("Thoth").unwrap(), + LocationPlatform::Thoth + ); assert_eq!( LocationPlatform::from_str("Other").unwrap(), LocationPlatform::Other