Skip to content

Commit

Permalink
Merge pull request #649 from thoth-pub/feature/648_create_thoth_locat…
Browse files Browse the repository at this point in the history
…ion_platform

Feature/648 create thoth location platform
  • Loading branch information
brendan-oconnell authored Nov 13, 2024
2 parents f314343 + 47ff5b7 commit f1a9bc5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions thoth-api/migrations/v0.13.0/down.sql
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions thoth-api/migrations/v0.13.0/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TYPE location_platform ADD VALUE IF NOT EXISTS 'Thoth';
12 changes: 12 additions & 0 deletions thoth-api/src/model/location/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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");
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f1a9bc5

Please sign in to comment.