mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
database: Allow tracks without medium
This commit is contained in:
parent
7eb85f094f
commit
a3f585aadf
4 changed files with 35 additions and 5 deletions
|
|
@ -0,0 +1,15 @@
|
|||
CREATE TABLE "old_tracks" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"medium" TEXT NOT NULL REFERENCES "mediums"("id") ON DELETE CASCADE,
|
||||
"index" INTEGER NOT NULL,
|
||||
"recording" TEXT NOT NULL REFERENCES "recordings"("id"),
|
||||
"work_parts" TEXT NOT NULL,
|
||||
"source_index" INTEGER NOT NULL,
|
||||
"path" TEXT NOT NULL,
|
||||
"last_used" BIGINT,
|
||||
"last_played" BIGINT
|
||||
);
|
||||
|
||||
INSERT INTO "old_tracks" SELECT * FROM "tracks" WHERE "medium" IS NOT NULL;
|
||||
DROP TABLE "tracks";
|
||||
ALTER TABLE "old_tracks" RENAME TO "tracks";
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
CREATE TABLE "new_tracks" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"medium" TEXT REFERENCES "mediums"("id") ON DELETE CASCADE,
|
||||
"index" INTEGER NOT NULL,
|
||||
"recording" TEXT NOT NULL REFERENCES "recordings"("id"),
|
||||
"work_parts" TEXT NOT NULL,
|
||||
"source_index" INTEGER NOT NULL,
|
||||
"path" TEXT NOT NULL,
|
||||
"last_used" BIGINT,
|
||||
"last_played" BIGINT
|
||||
);
|
||||
|
||||
INSERT INTO "new_tracks" SELECT * FROM "tracks";
|
||||
DROP TABLE "tracks";
|
||||
ALTER TABLE "new_tracks" RENAME TO "tracks";
|
||||
|
|
@ -93,7 +93,7 @@ struct MediumRow {
|
|||
#[table_name = "tracks"]
|
||||
struct TrackRow {
|
||||
pub id: String,
|
||||
pub medium: String,
|
||||
pub medium: Option<String>,
|
||||
pub index: i32,
|
||||
pub recording: String,
|
||||
pub work_parts: String,
|
||||
|
|
@ -150,7 +150,7 @@ impl Database {
|
|||
|
||||
let track_row = TrackRow {
|
||||
id: generate_id(),
|
||||
medium: medium_id.to_owned(),
|
||||
medium: Some(medium_id.to_owned()),
|
||||
index: index as i32,
|
||||
recording: track.recording.id.clone(),
|
||||
work_parts,
|
||||
|
|
@ -208,7 +208,7 @@ impl Database {
|
|||
let mut mediums: Vec<Medium> = Vec::new();
|
||||
|
||||
let rows = mediums::table
|
||||
.inner_join(tracks::table.on(tracks::medium.eq(mediums::id)))
|
||||
.inner_join(tracks::table.on(tracks::medium.eq(mediums::id.nullable())))
|
||||
.inner_join(recordings::table.on(recordings::id.eq(tracks::recording)))
|
||||
.inner_join(performances::table.on(performances::recording.eq(recordings::id)))
|
||||
.inner_join(persons::table.on(persons::id.nullable().eq(performances::person)))
|
||||
|
|
@ -230,7 +230,7 @@ impl Database {
|
|||
let mut mediums: Vec<Medium> = Vec::new();
|
||||
|
||||
let rows = mediums::table
|
||||
.inner_join(tracks::table.on(tracks::medium.eq(tracks::id)))
|
||||
.inner_join(tracks::table.on(tracks::medium.eq(tracks::id.nullable())))
|
||||
.inner_join(recordings::table.on(recordings::id.eq(tracks::recording)))
|
||||
.inner_join(performances::table.on(performances::recording.eq(recordings::id)))
|
||||
.inner_join(ensembles::table.on(ensembles::id.nullable().eq(performances::ensemble)))
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ diesel::table! {
|
|||
diesel::table! {
|
||||
tracks (id) {
|
||||
id -> Text,
|
||||
medium -> Text,
|
||||
medium -> Nullable<Text>,
|
||||
index -> Integer,
|
||||
recording -> Text,
|
||||
work_parts -> Text,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue