diff --git a/utilities/database_upgrader.py b/utilities/database_upgrader.py index c2a8c81..bd41f0d 100644 --- a/utilities/database_upgrader.py +++ b/utilities/database_upgrader.py @@ -5,6 +5,44 @@ import sys import ycdl +def upgrade_1_to_2(sql): + ''' + In this version, the duration column was added. + ''' + cur = sql.cursor() + cur.executescript(''' + ALTER TABLE videos RENAME TO videos_old; + CREATE TABLE videos( + id TEXT, + published INT, + author_id TEXT, + title TEXT, + description TEXT, + duration INT, + thumbnail TEXT, + download TEXT + ); + INSERT INTO videos SELECT + id, + published, + author_id, + title, + description, + NULL, + thumbnail, + download + FROM videos_old; + DROP TABLE videos_old; + ''') + +def upgrade_2_to_3(sql): + ''' + In this version, a column `automark` was added to the channels table, where + you can set channels to automatically mark videos as ignored or downloaded. + ''' + cur = sql.cursor() + cur.execute('ALTER TABLE channels ADD COLUMN automark TEXT') + def upgrade_3_to_4(sql): ''' In this version, the views column was added. @@ -37,44 +75,6 @@ def upgrade_3_to_4(sql): DROP TABLE videos_old; ''') -def upgrade_2_to_3(sql): - ''' - In this version, a column `automark` was added to the channels table, where - you can set channels to automatically mark videos as ignored or downloaded. - ''' - cur = sql.cursor() - cur.execute('ALTER TABLE channels ADD COLUMN automark TEXT') - -def upgrade_1_to_2(sql): - ''' - In this version, the duration column was added. - ''' - cur = sql.cursor() - cur.executescript(''' - ALTER TABLE videos RENAME TO videos_old; - CREATE TABLE videos( - id TEXT, - published INT, - author_id TEXT, - title TEXT, - description TEXT, - duration INT, - thumbnail TEXT, - download TEXT - ); - INSERT INTO videos SELECT - id, - published, - author_id, - title, - description, - NULL, - thumbnail, - download - FROM videos_old; - DROP TABLE videos_old; - ''') - def upgrade_all(database_filepath): ''' Given the directory containing a phototagger database, apply all of the