From 563266d8cc19469f27c560f8e5a365e9f3566093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Helle=C5=9Ben?= Date: Tue, 17 Mar 2026 00:07:22 +0100 Subject: [PATCH] Also add Kick to dataset --- core/views.py | 4 ++-- twitch/management/commands/backup_db.py | 13 +++++++++---- twitch/tests/test_backup.py | 17 +++++++++++------ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/core/views.py b/core/views.py index 6d1d9cf..352109d 100644 --- a/core/views.py +++ b/core/views.py @@ -645,8 +645,8 @@ def dataset_backups_view(request: HttpRequest) -> HttpResponse: datasets.sort(key=operator.itemgetter("updated_at"), reverse=True) seo_context: dict[str, Any] = _build_seo_context( - page_title="Twitch Dataset", - page_description="Database backups and datasets available for download.", + page_title="Twitch/Kick drop data", + page_description="Twitch/Kick datasets available for download, including historical drop campaign data and more.", ) context: dict[str, Any] = { "datasets": datasets, diff --git a/twitch/management/commands/backup_db.py b/twitch/management/commands/backup_db.py index c708cbb..7c4e587 100644 --- a/twitch/management/commands/backup_db.py +++ b/twitch/management/commands/backup_db.py @@ -19,9 +19,9 @@ if TYPE_CHECKING: class Command(BaseCommand): - """Create a compressed SQL dump of the Twitch dataset tables.""" + """Create a compressed SQL dump of the Twitch and Kick dataset tables.""" - help = "Create a compressed SQL dump of the Twitch dataset tables." + help = "Create a compressed SQL dump of the Twitch and Kick dataset tables." def add_arguments(self, parser: ArgumentParser) -> None: """Define arguments for the backup command.""" @@ -59,9 +59,14 @@ class Command(BaseCommand): timestamp: str = timezone.localtime(timezone.now()).strftime("%Y%m%d-%H%M%S") output_path: Path = output_dir / f"{prefix}-{timestamp}.sql.zst" - allowed_tables = _get_allowed_tables("twitch_") + allowed_tables = sorted({ + *_get_allowed_tables("twitch_"), + *_get_allowed_tables("kick_"), + }) if not allowed_tables: - self.stdout.write(self.style.WARNING("No twitch tables found to back up.")) + self.stdout.write( + self.style.WARNING("No twitch or kick tables found to back up."), + ) return if django_connection.vendor == "postgresql": diff --git a/twitch/tests/test_backup.py b/twitch/tests/test_backup.py index 08d8c4f..6bc0b0d 100644 --- a/twitch/tests/test_backup.py +++ b/twitch/tests/test_backup.py @@ -84,34 +84,39 @@ class TestBackupCommand: assert "twitch_game" in content assert "Test Org" in content - def test_backup_excludes_non_twitch_tables(self, tmp_path: Path) -> None: - """Test that backup only includes twitch_ prefixed tables.""" + def test_backup_excludes_non_app_tables(self, tmp_path: Path) -> None: + """Test that backup includes app tables and excludes non-app tables.""" _skip_if_pg_dump_missing() # Create test data so tables exist Organization.objects.create(twitch_id="test001", name="Test Org") - output_dir = tmp_path / "backups" + output_dir: Path = tmp_path / "backups" output_dir.mkdir() call_command("backup_db", output_dir=str(output_dir), prefix="test") - backup_file = next(iter(output_dir.glob("test-*.sql.zst"))) + backup_file: Path = next(iter(output_dir.glob("test-*.sql.zst"))) with ( backup_file.open("rb") as raw_handle, zstd.open(raw_handle, "r") as compressed, io.TextIOWrapper(compressed, encoding="utf-8") as handle, ): - content = handle.read() + content: str = handle.read() # Should NOT contain django admin, silk, or debug toolbar tables assert "django_session" not in content + assert "django_migrations" not in content + assert "django_content_type" not in content assert "silk_" not in content assert "debug_toolbar_" not in content assert "django_admin_log" not in content + assert "auth_" not in content + assert "youtube_" not in content - # Should contain twitch tables + # Should contain twitch and kick tables assert "twitch_" in content + assert "kick_" in content def test_backup_with_custom_prefix(self, tmp_path: Path) -> None: """Test that custom prefix is used in filename."""