Remove separate part composers

This commit is contained in:
Elias Projahn 2021-02-07 09:44:52 +01:00
parent 59acc460f8
commit c0cfb1abfe
3 changed files with 1 additions and 21 deletions

View file

@ -37,8 +37,7 @@ CREATE TABLE work_parts (
id BIGINT NOT NULL PRIMARY KEY, id BIGINT NOT NULL PRIMARY KEY,
work TEXT NOT NULL REFERENCES works(id) ON DELETE CASCADE, work TEXT NOT NULL REFERENCES works(id) ON DELETE CASCADE,
part_index BIGINT NOT NULL, part_index BIGINT NOT NULL,
title TEXT NOT NULL, title TEXT NOT NULL
composer TEXT REFERENCES persons(id)
); );
CREATE TABLE work_sections ( CREATE TABLE work_sections (

View file

@ -94,7 +94,6 @@ table! {
work -> Text, work -> Text,
part_index -> Int8, part_index -> Int8,
title -> Text, title -> Text,
composer -> Nullable<Text>,
} }
} }
@ -131,7 +130,6 @@ joinable!(recordings -> works (work));
joinable!(track_sets -> mediums (medium)); joinable!(track_sets -> mediums (medium));
joinable!(track_sets -> recordings (recording)); joinable!(track_sets -> recordings (recording));
joinable!(tracks -> track_sets (track_set)); joinable!(tracks -> track_sets (track_set));
joinable!(work_parts -> persons (composer));
joinable!(work_parts -> works (work)); joinable!(work_parts -> works (work));
joinable!(work_sections -> works (work)); joinable!(work_sections -> works (work));
joinable!(works -> persons (composer)); joinable!(works -> persons (composer));

View file

@ -24,7 +24,6 @@ pub struct Work {
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct WorkPart { pub struct WorkPart {
pub title: String, pub title: String,
pub composer: Option<Person>,
} }
/// A heading within the work structure. /// A heading within the work structure.
@ -62,7 +61,6 @@ struct WorkPartRow {
pub work: String, pub work: String,
pub part_index: i64, pub part_index: i64,
pub title: String, pub title: String,
pub composer: Option<String>,
} }
/// Table data for a work section. /// Table data for a work section.
@ -106,14 +104,6 @@ pub fn update_work(conn: &DbConn, work: &Work, user: &User) -> Result<()> {
} }
} }
for part in &work.parts {
if let Some(person) = &part.composer {
if get_person(conn, &person.id)?.is_none() {
update_person(conn, person, &user)?;
}
}
}
// Add the actual work. // Add the actual work.
let row = WorkRow { let row = WorkRow {
@ -143,7 +133,6 @@ pub fn update_work(conn: &DbConn, work: &Work, user: &User) -> Result<()> {
work: id.clone(), work: id.clone(),
part_index: index.try_into()?, part_index: index.try_into()?,
title: part.title.clone(), title: part.title.clone(),
composer: part.composer.as_ref().map(|person| person.id.clone()),
}; };
diesel::insert_into(work_parts::table) diesel::insert_into(work_parts::table)
@ -242,12 +231,6 @@ fn get_description_for_work_row(conn: &DbConn, row: &WorkRow) -> Result<Work> {
for part_row in part_rows { for part_row in part_rows {
parts.push(WorkPart { parts.push(WorkPart {
title: part_row.title, title: part_row.title,
composer: match part_row.composer {
Some(id) => {
Some(get_person(conn, &id)?.ok_or(anyhow!("No person with ID: {}", id))?)
}
None => None,
},
}); });
} }