diff --git a/src/rust/liblektor-rs/migrations/2022-09-30-204512_initial/down.sql b/src/rust/liblektor-rs/migrations/2022-09-30-204512_initial/down.sql index 9a50b90634bf40082be5b3a8b2c256fe1bbba947..d3df5c6d9791d08f146ef0b1a902c392e6eea89b 100644 --- a/src/rust/liblektor-rs/migrations/2022-09-30-204512_initial/down.sql +++ b/src/rust/liblektor-rs/migrations/2022-09-30-204512_initial/down.sql @@ -1,8 +1,9 @@ DROP TABLE repo; -DROP TABLE kara_repo; +DROP TABLE repo_kara; DROP TABLE kara; DROP TABLE kara_makers; DROP TABLE kara_tag; DROP TABLE tag; DROP TABLE kara_tags; DROP TABLE history; +DROP TABLE ISO_639_1; \ No newline at end of file diff --git a/src/rust/liblektor-rs/migrations/2022-09-30-204512_initial/up.sql b/src/rust/liblektor-rs/migrations/2022-09-30-204512_initial/up.sql index a4ec97be9d176b4ebcfbaa21db758f54b08c2261..8b01a905d5d1e85524b1431e19e598db98e7a987 100644 --- a/src/rust/liblektor-rs/migrations/2022-09-30-204512_initial/up.sql +++ b/src/rust/liblektor-rs/migrations/2022-09-30-204512_initial/up.sql @@ -1,8 +1,13 @@ +-- A list of repos karas where downloaded from. All repos should have different +-- names! Their IDs are local to the client. CREATE TABLE repo ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT , name TEXT NOT NULL UNIQUE ); +-- Link a kara in the local referencial to its reference in the distant repo. +-- Local IDs are all uniques and every client should be expected to have +-- different ones. CREATE TABLE repo_kara ( repo_id INTEGER NOT NULL REFERENCES repo(id) , repo_kara_id INTEGER NOT NULL @@ -10,6 +15,7 @@ CREATE TABLE repo_kara , PRIMARY KEY (repo_id, repo_kara_id, local_kara_id) ); +-- A kara entry in the databse. CREATE TABLE kara ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT , is_dl BOOLEAN NOT NULL DEFAULT false @@ -17,21 +23,25 @@ CREATE TABLE kara , song_type TEXT NOT NULL , song_origin TEXT NOT NULL , source_name TEXT NOT NULL - , language TEXT NOT NULL + , language TEXT NOT NULL REFERENCES ISO_639_1(code) , kara_hash TEXT NOT NULL -- TEXT ABOVE + HASH OF FILE IN FS ); +-- We can have multiple kara makers for one kara. CREATE TABLE kara_makers ( id INTEGER NOT NULL REFERENCES kara ON DELETE CASCADE , name TEXT NOT NULL , PRIMARY KEY (id, name) ); +-- Tags are informations used to be able to make queries in a easier way. CREATE TABLE tag ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT , name TEXT NOT NULL UNIQUE ); +-- The content of a tag for kara. Multiple tags for a single kara with the same +-- tag id means that there a list of values. CREATE TABLE kara_tags ( kara_id INTEGER NOT NULL REFERENCES kara(id) ON DELETE CASCADE , tag_id INTEGER NOT NULL REFERENCES tag(id) ON DELETE CASCADE @@ -39,7 +49,16 @@ CREATE TABLE kara_tags , PRIMARY KEY (kara_id, tag_id, value) ); +-- Store the history of played karas from the queue. For now we allow a kara to +-- appear multiple times in the history. CREATE TABLE history ( id INTEGER NOT NULL REFERENCES kara(id) ON DELETE CASCADE , epoch INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT ); + +-- The list of ISO 639-1 languages with their associated codes. +-- Should add an entry in the api to query available languages. +CREATE TABLE ISO_639_1 + ( code TEXT NOT NULL PRIMARY KEY + , name_en TEXT NOT NULL UNIQUE + ); \ No newline at end of file diff --git a/src/rust/liblektor-rs/src/database/schema.rs b/src/rust/liblektor-rs/src/database/schema.rs index f429bd48c796e16ffbe09d353e73f83fc19c915c..dc22363e565f1fd0ce40167ca87168b51bf9af85 100644 --- a/src/rust/liblektor-rs/src/database/schema.rs +++ b/src/rust/liblektor-rs/src/database/schema.rs @@ -1,5 +1,12 @@ // @generated automatically by Diesel CLI. +diesel::table! { + ISO_639_1 (code) { + code -> Text, + name_en -> Text, + } +} + diesel::table! { history (epoch) { id -> Integer, @@ -58,6 +65,7 @@ diesel::table! { } diesel::joinable!(history -> kara (id)); +diesel::joinable!(kara -> ISO_639_1 (language)); diesel::joinable!(kara_makers -> kara (id)); diesel::joinable!(kara_tags -> kara (kara_id)); diesel::joinable!(kara_tags -> tag (tag_id)); @@ -65,6 +73,7 @@ diesel::joinable!(repo_kara -> kara (local_kara_id)); diesel::joinable!(repo_kara -> repo (repo_id)); diesel::allow_tables_to_appear_in_same_query!( + ISO_639_1, history, kara, kara_makers,