From 63738bd70f93fa346d57ca61d552b050166566c4 Mon Sep 17 00:00:00 2001 From: Roland Date: Sat, 20 Jul 2024 15:35:16 -0600 Subject: [PATCH] Removing ChannelDownload in favor of Download.channel_id. --- .../8d0d81bc9c34_channel_channel_downloads.py | 20 +-- app/src/components/Channels.js | 4 +- app/src/components/admin/Downloads.js | 23 --- modules/videos/channel/lib.py | 45 +++--- modules/videos/channel/test/test_api.py | 38 ++--- modules/videos/channel/test/test_models.py | 33 ++-- modules/videos/conftest.py | 16 +- modules/videos/lib.py | 39 +++-- modules/videos/models.py | 150 +++++++----------- modules/videos/test/test_common.py | 53 ++++--- modules/videos/test/test_downloader.py | 15 +- modules/videos/test/test_lib.py | 43 ++++- modules/videos/test/test_migration.py | 40 ----- wrolpi/downloader.py | 89 ++++++----- wrolpi/errors.py | 6 + wrolpi/migration.py | 32 ---- wrolpi/test/test_root_api.py | 8 +- 17 files changed, 290 insertions(+), 364 deletions(-) delete mode 100644 modules/videos/test/test_migration.py delete mode 100644 wrolpi/migration.py diff --git a/alembic/versions/8d0d81bc9c34_channel_channel_downloads.py b/alembic/versions/8d0d81bc9c34_channel_channel_downloads.py index 799e8b12..06393ac5 100644 --- a/alembic/versions/8d0d81bc9c34_channel_channel_downloads.py +++ b/alembic/versions/8d0d81bc9c34_channel_channel_downloads.py @@ -1,4 +1,4 @@ -"""Channel.channel_downloads +"""Channel.downloads / Download.channel Revision ID: 8d0d81bc9c34 Revises: 00f11f309c53 @@ -11,6 +11,8 @@ from alembic import op from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import Session +from modules.videos.lib import link_channel_and_downloads + # revision identifiers, used by Alembic. revision = '8d0d81bc9c34' down_revision = '00f11f309c53' @@ -27,29 +29,21 @@ def upgrade(): session = Session(bind=bind) session.execute('ALTER TABLE download ADD CONSTRAINT download_url_unique UNIQUE (url)') - session.execute(''' - CREATE TABLE channel_download ( - channel_id INTEGER REFERENCES channel (id), - download_url TEXT REFERENCES download (url), - primary key (channel_id, download_url) - )''') + session.execute('ALTER TABLE download ADD COLUMN channel_id INTEGER REFERENCES channel(id)') - # Migration is separated for testing. See `test_channel_channel_downloads_migration` - from wrolpi.migration import migrate_channel_downloads - migrate_channel_downloads(session) + link_channel_and_downloads(session) session.execute('ALTER TABLE channel DROP COLUMN IF EXISTS match_regex') session.execute('ALTER TABLE channel DROP COLUMN IF EXISTS download_frequency') - if not DOCKERIZED: - session.execute('ALTER TABLE public.channel_download OWNER TO wrolpi') - def downgrade(): bind = op.get_bind() session = Session(bind=bind) session.execute('DROP TABLE IF EXISTS channel_download') + session.execute('ALTER TABLE download DROP COLUMN IF EXISTS channel_id') + session.execute('ALTER TABLE channel DROP COLUMN IF EXISTS channel_id') session.execute('ALTER TABLE channel ADD COLUMN IF NOT EXISTS match_regex TEXT') session.execute('ALTER TABLE channel ADD COLUMN IF NOT EXISTS download_frequency INTEGER') session.execute('ALTER TABLE download DROP CONSTRAINT IF EXISTS download_url_unique') diff --git a/app/src/components/Channels.js b/app/src/components/Channels.js index a2b5670f..3cc046e9 100644 --- a/app/src/components/Channels.js +++ b/app/src/components/Channels.js @@ -240,7 +240,7 @@ function ChannelPage({create, header}) { } } - let channelDownloads = channel && channel.channel_downloads ? channel.channel_downloads : null; + let downloads = channel && channel.downloads ? channel.downloads : null; const afterNewDownloadSave = async () => { await fetchChannel(); @@ -399,7 +399,7 @@ function ChannelPage({create, header}) { - + }
diff --git a/app/src/components/admin/Downloads.js b/app/src/components/admin/Downloads.js index b95e436a..45afe812 100644 --- a/app/src/components/admin/Downloads.js +++ b/app/src/components/admin/Downloads.js @@ -252,17 +252,6 @@ class RecurringDownloadRow extends React.Component { } } - handleDelete = async () => { - const {id} = this.props; - try { - await deleteDownload(id); - } finally { - if (this.props.fetchDownloads) { - this.props.fetchDownloads(); - } - } - } - handleRestart = async () => { const {id} = this.props; try { @@ -295,7 +284,6 @@ class RecurringDownloadRow extends React.Component { next_download, error, downloader, - channel_id } = this.props; const {errorModalOpen} = this.state; @@ -319,17 +307,6 @@ class RecurringDownloadRow extends React.Component { ; - const deleteButton = <> - - ; - const editButton = <>