Also add Kick to dataset

This commit is contained in:
Joakim Hellsén 2026-03-17 00:07:22 +01:00
commit 563266d8cc
Signed by: Joakim Hellsén
SSH key fingerprint: SHA256:/9h/CsExpFp+PRhsfA0xznFx2CGfTT5R/kpuFfUgEQk
3 changed files with 22 additions and 12 deletions

View file

@ -645,8 +645,8 @@ def dataset_backups_view(request: HttpRequest) -> HttpResponse:
datasets.sort(key=operator.itemgetter("updated_at"), reverse=True) datasets.sort(key=operator.itemgetter("updated_at"), reverse=True)
seo_context: dict[str, Any] = _build_seo_context( seo_context: dict[str, Any] = _build_seo_context(
page_title="Twitch Dataset", page_title="Twitch/Kick drop data",
page_description="Database backups and datasets available for download.", page_description="Twitch/Kick datasets available for download, including historical drop campaign data and more.",
) )
context: dict[str, Any] = { context: dict[str, Any] = {
"datasets": datasets, "datasets": datasets,

View file

@ -19,9 +19,9 @@ if TYPE_CHECKING:
class Command(BaseCommand): 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: def add_arguments(self, parser: ArgumentParser) -> None:
"""Define arguments for the backup command.""" """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") timestamp: str = timezone.localtime(timezone.now()).strftime("%Y%m%d-%H%M%S")
output_path: Path = output_dir / f"{prefix}-{timestamp}.sql.zst" 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: 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 return
if django_connection.vendor == "postgresql": if django_connection.vendor == "postgresql":

View file

@ -84,34 +84,39 @@ class TestBackupCommand:
assert "twitch_game" in content assert "twitch_game" in content
assert "Test Org" in content assert "Test Org" in content
def test_backup_excludes_non_twitch_tables(self, tmp_path: Path) -> None: def test_backup_excludes_non_app_tables(self, tmp_path: Path) -> None:
"""Test that backup only includes twitch_ prefixed tables.""" """Test that backup includes app tables and excludes non-app tables."""
_skip_if_pg_dump_missing() _skip_if_pg_dump_missing()
# Create test data so tables exist # Create test data so tables exist
Organization.objects.create(twitch_id="test001", name="Test Org") Organization.objects.create(twitch_id="test001", name="Test Org")
output_dir = tmp_path / "backups" output_dir: Path = tmp_path / "backups"
output_dir.mkdir() output_dir.mkdir()
call_command("backup_db", output_dir=str(output_dir), prefix="test") 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 ( with (
backup_file.open("rb") as raw_handle, backup_file.open("rb") as raw_handle,
zstd.open(raw_handle, "r") as compressed, zstd.open(raw_handle, "r") as compressed,
io.TextIOWrapper(compressed, encoding="utf-8") as handle, 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 # Should NOT contain django admin, silk, or debug toolbar tables
assert "django_session" not in content 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 "silk_" not in content
assert "debug_toolbar_" not in content assert "debug_toolbar_" not in content
assert "django_admin_log" 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 "twitch_" in content
assert "kick_" in content
def test_backup_with_custom_prefix(self, tmp_path: Path) -> None: def test_backup_with_custom_prefix(self, tmp_path: Path) -> None:
"""Test that custom prefix is used in filename.""" """Test that custom prefix is used in filename."""