Skip to content

fix(db): normalize stale positive-ID media file paths#168

Merged
GeiserX merged 1 commit into
mainfrom
fix/normalize-media-file-paths
May 24, 2026
Merged

fix(db): normalize stale positive-ID media file paths#168
GeiserX merged 1 commit into
mainfrom
fix/normalize-media-file-paths

Conversation

@GeiserX
Copy link
Copy Markdown
Owner

@GeiserX GeiserX commented May 24, 2026

Summary

  • Adds Alembic migration 013 that rewrites media.file_path values so the folder component uses the correct marked (negative) chat_id instead of the stale positive entity ID from pre-v4.0.5
  • Fixes the runtime media/thumbnail fallback to handle both basic groups (X-X) and channels/supergroups (X-100X)
  • Fixes _enforce_media_acl to recognize legacy positive folder IDs for multi-user setups

Root Cause

Before v4.0.5, the backup used entity.id (always positive) for directory names. After v4.0.5, it uses get_peer_id() (negative for groups/channels). The v4.0.6 migrate_to_marked_ids.sql fixed chat_id columns in all tables but never updated media.file_path strings. This left 55,402 out of 150,636 media rows (37%) with paths pointing to non-existent positive-ID directories.

Migration Details

  • Iterates all distinct negative chat_id values in the media table
  • For each, derives the old stale folder name (abs(chat_id) for basic groups, abs(chat_id) - 1000000000000 for channels)
  • Updates file_path using REPLACE() — only affects rows with the stale pattern
  • Works for both PostgreSQL and SQLite
  • Fully idempotent and reversible (downgrade restores original paths)

Test plan

  • _derive_stale_folder() unit tests pass for basic groups, channels, users, and edge cases
  • CI lint + tests pass
  • Deploy to production, verify migration runs on startup
  • Verify thumbnails load for previously-broken groups (e.g., "Marayadas, Sergiadas y Annaisadas")
  • Verify channels with old data also resolve correctly

Before v4.0.5, backup stored media in directories named with raw positive
entity IDs. After v4.0.5, directories use Telethon's marked IDs (negative
for groups/channels). The v4.0.6 migration fixed chat_id columns but never
updated file_path strings, leaving ~37% of media rows with broken paths.

Adds Alembic migration 013 that rewrites file_path values so the folder
component matches the marked chat_id. Also fixes the runtime fallback to
handle both basic groups (X→-X) and channels (X→-100X), and fixes the
ACL check to recognize legacy positive folder IDs.

Bump to v7.10.14.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 24, 2026

Warning

Review limit reached

@GeiserX, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 2 reviews/hour. Refill in 24 minutes and 33 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b7b384c2-773f-48b8-afdf-80f70234428b

📥 Commits

Reviewing files that changed from the base of the PR and between b100c03 and d46db69.

⛔ Files ignored due to path filters (1)
  • alembic/versions/20260524_013_fix_media_file_paths.py is excluded by !alembic/versions/**
📒 Files selected for processing (5)
  • pyproject.toml
  • scripts/entrypoint.sh
  • src/__init__.py
  • src/web/main.py
  • src/web/thumbnails.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/normalize-media-file-paths

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 24, 2026

Codecov Report

❌ Patch coverage is 51.51515% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.55%. Comparing base (b100c03) to head (d46db69).

Files with missing lines Patch % Lines
src/web/main.py 36.84% 12 Missing ⚠️
src/web/thumbnails.py 69.23% 4 Missing ⚠️

❌ Your patch check has failed because the patch coverage (51.51%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #168      +/-   ##
==========================================
- Coverage   92.76%   92.55%   -0.22%     
==========================================
  Files          22       22              
  Lines        6498     6527      +29     
==========================================
+ Hits         6028     6041      +13     
- Misses        470      486      +16     
Files with missing lines Coverage Δ
src/__init__.py 100.00% <100.00%> (ø)
src/web/thumbnails.py 80.68% <69.23%> (-2.22%) ⬇️
src/web/main.py 86.00% <36.84%> (-0.72%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/web/main.py Dismissed
Comment thread src/web/thumbnails.py Dismissed
Comment thread src/web/thumbnails.py Dismissed
@github-actions
Copy link
Copy Markdown

🐳 Dev images published!

  • drumsergio/telegram-archive:dev
  • drumsergio/telegram-archive-viewer:dev

The dev/test instance will pick up these changes automatically (Portainer GitOps).

To test locally:

docker pull drumsergio/telegram-archive:dev
docker pull drumsergio/telegram-archive-viewer:dev

@GeiserX GeiserX merged commit 04dce12 into main May 24, 2026
9 of 11 checks passed
@GeiserX GeiserX deleted the fix/normalize-media-file-paths branch May 24, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants