Remove work sections

This commit is contained in:
Elias Projahn 2022-02-09 21:43:20 +01:00
parent 3350c6be95
commit ee8399e93d
10 changed files with 24 additions and 332 deletions

View file

@ -5,7 +5,6 @@ DROP TABLE "instruments";
DROP TABLE "works";
DROP TABLE "instrumentations";
DROP TABLE "work_parts";
DROP TABLE "work_sections";
DROP TABLE "ensembles";
DROP TABLE "recordings";
DROP TABLE "performances";

View file

@ -28,13 +28,6 @@ CREATE TABLE "work_parts" (
"title" TEXT NOT NULL
);
CREATE TABLE "work_sections" (
"id" BIGINT NOT NULL PRIMARY KEY,
"work" TEXT NOT NULL REFERENCES "works"("id") ON DELETE CASCADE,
"title" TEXT NOT NULL,
"before_index" BIGINT NOT NULL
);
CREATE TABLE "ensembles" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL

View file

@ -75,15 +75,6 @@ table! {
}
}
table! {
work_sections (id) {
id -> BigInt,
work -> Text,
title -> Text,
before_index -> BigInt,
}
}
table! {
works (id) {
id -> Text,
@ -102,7 +93,6 @@ joinable!(recordings -> works (work));
joinable!(tracks -> mediums (medium));
joinable!(tracks -> recordings (recording));
joinable!(work_parts -> works (work));
joinable!(work_sections -> works (work));
joinable!(works -> persons (composer));
allow_tables_to_appear_in_same_query!(
@ -115,6 +105,5 @@ allow_tables_to_appear_in_same_query!(
recordings,
tracks,
work_parts,
work_sections,
works,
);

View file

@ -1,5 +1,5 @@
use super::generate_id;
use super::schema::{instrumentations, work_parts, work_sections, works};
use super::schema::{instrumentations, work_parts, works};
use super::{Database, Error, Instrument, Person, Result};
use diesel::prelude::*;
use diesel::{Insertable, Queryable};
@ -43,28 +43,12 @@ struct WorkPartRow {
pub title: String,
}
/// Table row data for a work section.
#[derive(Insertable, Queryable, Debug, Clone)]
#[table_name = "work_sections"]
struct WorkSectionRow {
pub id: i64,
pub work: String,
pub title: String,
pub before_index: i64,
}
/// A concrete work part that can be recorded.
#[derive(PartialEq, Eq, Hash, Debug, Clone)]
pub struct WorkPart {
pub title: String,
}
/// A heading between work parts.
#[derive(PartialEq, Eq, Hash, Debug, Clone)]
pub struct WorkSection {
pub title: String,
pub before_index: usize,
}
/// A specific work by a composer.
#[derive(PartialEq, Eq, Hash, Debug, Clone)]
pub struct Work {
@ -73,7 +57,6 @@ pub struct Work {
pub composer: Person,
pub instruments: Vec<Instrument>,
pub parts: Vec<WorkPart>,
pub sections: Vec<WorkSection>,
}
impl Work {
@ -85,7 +68,6 @@ impl Work {
composer,
instruments: Vec::new(),
parts: Vec::new(),
sections: Vec::new(),
}
}
@ -129,7 +111,6 @@ impl Database {
let Work {
instruments,
parts,
sections,
..
} = work;
@ -158,19 +139,6 @@ impl Database {
.execute(&self.connection)?;
}
for section in sections {
let row = WorkSectionRow {
id: rand::random(),
work: work_id.to_string(),
title: section.title,
before_index: section.before_index as i64,
};
diesel::insert_into(work_sections::table)
.values(row)
.execute(&self.connection)?;
}
Ok(())
})?;
@ -221,19 +189,6 @@ impl Database {
});
}
let mut sections: Vec<WorkSection> = Vec::new();
let section_rows = work_sections::table
.filter(work_sections::work.eq(&row.id))
.load::<WorkSectionRow>(&self.connection)?;
for section_row in section_rows {
sections.push(WorkSection {
title: section_row.title,
before_index: section_row.before_index as usize,
});
}
let person_id = row.composer;
let person = self
.get_person(&person_id)?
@ -245,7 +200,6 @@ impl Database {
title: row.title,
instruments,
parts,
sections,
})
}