about summary refs log tree commit diff stats
path: root/crates
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-07-14 16:06:12 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-07-14 16:06:12 +0200
commite76c029e3392283fe0c230bba01a236b71089bbe (patch)
tree8a5cdd228893b8ec427a039a4feab438ae6ae00a /crates
parentfeat(crates/yt/storage): Migrate inserts to operations and use methods (diff)
downloadyt-e76c029e3392283fe0c230bba01a236b71089bbe.zip
fix(crates/yt/storage/migrate): Merge the `videos` and `video_options` tables
Keeping them separate was just introducing unnecessary friction.
Diffstat (limited to 'crates')
-rw-r--r--crates/yt/src/storage/migrate/mod.rs14
-rw-r--r--crates/yt/src/storage/migrate/sql/4_Three_to_Four.sql24
2 files changed, 36 insertions, 2 deletions
diff --git a/crates/yt/src/storage/migrate/mod.rs b/crates/yt/src/storage/migrate/mod.rs
index 4fa39ab..e2d93bd 100644
--- a/crates/yt/src/storage/migrate/mod.rs
+++ b/crates/yt/src/storage/migrate/mod.rs
@@ -91,8 +91,11 @@ pub(crate) enum DbVersion {
 
     /// Introduced: 2025-03-21.
     Three,
+
+    /// Introduced: 2025-07-05.
+    Four,
 }
-const CURRENT_VERSION: DbVersion = DbVersion::Three;
+const CURRENT_VERSION: DbVersion = DbVersion::Four;
 
 async fn add_error_context(
     function: impl Future<Output = Result<()>>,
@@ -143,6 +146,7 @@ impl DbVersion {
             DbVersion::One => 1,
             DbVersion::Two => 2,
             DbVersion::Three => 3,
+            DbVersion::Four => 4,
 
             DbVersion::Empty => unreachable!("A empty version does not have an associated integer"),
         }
@@ -154,11 +158,13 @@ impl DbVersion {
             (1, "yt") => Ok(DbVersion::One),
             (2, "yt") => Ok(DbVersion::Two),
             (3, "yt") => Ok(DbVersion::Three),
+            (4, "yt") => Ok(DbVersion::Four),
 
             (0, other) => bail!("Db version is Zero, but got unknown namespace: '{other}'"),
             (1, other) => bail!("Db version is One, but got unknown namespace: '{other}'"),
             (2, other) => bail!("Db version is Two, but got unknown namespace: '{other}'"),
             (3, other) => bail!("Db version is Three, but got unknown namespace: '{other}'"),
+            (4, other) => bail!("Db version is Four, but got unknown namespace: '{other}'"),
 
             (other, "yt") => bail!("Got unkown version for 'yt' namespace: {other}"),
             (num, nasp) => bail!("Got unkown version number ({num}) and namespace ('{nasp}')"),
@@ -188,8 +194,12 @@ impl DbVersion {
                 make_upgrade! {app, Self::Two, Self::Three, "./sql/3_Two_to_Three.sql"}
             }
 
-            // This is the current_version
             Self::Three => {
+                make_upgrade! {app, Self::Three, Self::Four, "./sql/4_Three_to_Four.sql"}
+            }
+
+            // This is the current_version
+            Self::Four => {
                 assert_eq!(self, CURRENT_VERSION);
                 assert_eq!(self, get_version(app).await?);
                 Ok(())
diff --git a/crates/yt/src/storage/migrate/sql/4_Three_to_Four.sql b/crates/yt/src/storage/migrate/sql/4_Three_to_Four.sql
new file mode 100644
index 0000000..9c283a1
--- /dev/null
+++ b/crates/yt/src/storage/migrate/sql/4_Three_to_Four.sql
@@ -0,0 +1,24 @@
+-- yt - A fully featured command line YouTube client
+--
+-- Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+-- SPDX-License-Identifier: GPL-3.0-or-later
+--
+-- This file is part of Yt.
+--
+-- You should have received a copy of the License along with this program.
+-- If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
+
+ALTER TABLE videos
+ADD COLUMN subtitle_langs TEXT;
+
+ALTER TABLE videos
+ADD COLUMN playback_speed REAL CHECK (playback_speed >= 0);
+
+UPDATE videos
+   SET playback_speed = video_options.playback_speed,
+       subtitle_langs = video_options.subtitle_langs
+  FROM video_options
+ WHERE videos.extractor_hash = video_options.extractor_hash;
+
+
+DROP TABLE video_options;