Skip to content

Lychee v3 redirect#4126

Merged
ildyria merged 11 commits intoLycheeOrg:masterfrom
tkulev:lychee_v3_redirect
Feb 28, 2026
Merged

Lychee v3 redirect#4126
ildyria merged 11 commits intoLycheeOrg:masterfrom
tkulev:lychee_v3_redirect

Conversation

@tkulev
Copy link
Contributor

@tkulev tkulev commented Feb 27, 2026

Added functionality that resolves Lychee v3 album url to v7, using field legacy_id from base_album table.

Summary by CodeRabbit

  • New Features

    • Legacy album links now automatically issue a 301 redirect to their current gallery URLs so bookmarks and external links keep working.
    • Redirect behavior is applied at the gallery route to catch legacy IDs early.
  • Bug Fixes / Reliability

    • Unknown or unmapped legacy IDs return a standard "Not Found" response.
    • Database migration updated to avoid unintentionally removing legacy ID data during upgrades.

@tkulev tkulev requested a review from a team as a code owner February 27, 2026 19:01
@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds middleware alias legacy_id_redirect to Kernel, implements LegacyLocalIdRedirect middleware to detect 14-digit legacy album IDs and redirect to current album IDs when mapped, inserts the middleware into the /gallery route, and modifies a migration to stop dropping base_albums.legacy_id while making its recreation conditional.

Changes

Cohort / File(s) Summary
Kernel middleware alias
app/Http/Kernel.php
Adds 'legacy_id_redirect' => \App\Http\Middleware\LegacyLocalIdRedirect::class to protected $middlewareAliases.
New middleware
app/Http/Middleware/LegacyLocalIdRedirect.php
Adds LegacyLocalIdRedirect middleware: checks route albumId, validates 14-digit numeric legacy ID, verifies legacy_id column exists, queries base_albums for a mapping, issues 301 redirect to gallery when found, proceeds if conditions not met, or throws NotFoundHttpException when mapping is absent.
Route update
routes/web_v2.php
Inserts legacy_id_redirect into the /gallery route middleware chain (between migration:complete and existing middlewares).
Migration tweak
database/migrations/2025_05_27_081037_drop_legacy_id.php
up() no longer drops base_albums.legacy_id (now changed to alter to nullable unsignedBigInteger); down() re-addition of base_albums.legacy_id is conditional (only if missing). Photos table handling unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I’m a rabbit tracing fourteen-digit trails,
I hop from old IDs to new gallery vales,
A polite 301 and a whisker-twitch cheer,
If no map is found I sniff and disappear,
Then bound on—breadcrumbs and bright carrots near 🐇✨

🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 90b0c8b and 66c8511.

📒 Files selected for processing (2)
  • app/Http/Kernel.php
  • app/Http/Middleware/LegacyLocalIdRedirect.php

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 66c8511 and 39b810f.

📒 Files selected for processing (1)
  • app/Http/Middleware/LegacyLocalIdRedirect.php

@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.50%. Comparing base (17e9ccb) to head (ecc9317).
⚠️ Report is 1 commits behind head on master.

🚀 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
app/Http/Middleware/LegacyLocalIdRedirect.php (1)

32-37: Cache schema-column detection and fetch only required column.

Line 34 executes Schema::hasColumn() on every request, and line 36 fetches the full row when only the id is needed. Cache the schema check using a static property and select only the id column to reduce per-request database overhead.

♻️ Proposed refactor
 class LegacyLocalIdRedirect
 {
+	private static ?bool $has_legacy_id_column = null;
+
 	/**
 	 * Handles redirection from old albums (Lychee v3 format).
@@
 	public function handle(Request $request, \Closure $next)
 	{
@@
 		$album_id = $request->route('albumId');
+		$has_legacy_id_column = self::$has_legacy_id_column ??= Schema::hasColumn('base_albums', 'legacy_id');
 		if ($album_id !== null &&
 			preg_match('/^\d{14}$/', (string) $album_id) === 1 &&
-			Schema::hasColumn('base_albums', 'legacy_id')
+			$has_legacy_id_column
 		) {
-			$album = DB::table('base_albums')->where('legacy_id', '=', $album_id)->first();
+			$album = DB::table('base_albums')
+				->select('id')
+				->where('legacy_id', '=', (string) $album_id)
+				->first();
 			if ($album === null) {
 				throw new NotFoundHttpException();
 			}

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39b810f and 0d628e4.

📒 Files selected for processing (1)
  • app/Http/Middleware/LegacyLocalIdRedirect.php

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
database/migrations/2025_05_27_081037_drop_legacy_id.php (1)

49-54: Use the migration constant for column name consistently.

Line 52 hardcodes 'legacy_id' even though self::LEGACY_ID_NAME exists.

♻️ Proposed refactor
 		if (!Schema::hasColumn('base_albums', self::LEGACY_ID_NAME)) {
 			Schema::table('base_albums', function (Blueprint $table) {
-				$table->unsignedBigInteger('legacy_id')->after('id')->nullable(false);
+				$table->unsignedBigInteger(self::LEGACY_ID_NAME)->after('id')->nullable(false);
 			});
 		}

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d628e4 and 6146708.

📒 Files selected for processing (3)
  • app/Http/Kernel.php
  • database/migrations/2025_05_27_081037_drop_legacy_id.php
  • routes/web_v2.php

@ildyria
Copy link
Member

ildyria commented Feb 28, 2026

tested.

@ildyria ildyria enabled auto-merge (squash) February 28, 2026 22:09
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
database/migrations/2025_05_27_081037_drop_legacy_id.php (1)

35-37: ⚠️ Potential issue | 🟠 Major

Preserve uniqueness for base_albums.legacy_id if the column is retained

up() keeps the column (Line 36) but still drops base_albums_legacy_id_unique (Line 25). That can create duplicate legacy IDs and ambiguous redirect targets.

Suggested fix
 		try {
 			Schema::table('photos', function (Blueprint $table) {
 				$table->dropUnique('photos_legacy_id_unique');
 			});
-			Schema::table('base_albums', function (Blueprint $table) {
-				$table->dropUnique('base_albums_legacy_id_unique');
-			});
 		} catch (\Throwable $e) {
 			// Do nothing
 		}

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6146708 and ecc9317.

📒 Files selected for processing (1)
  • database/migrations/2025_05_27_081037_drop_legacy_id.php

@ildyria ildyria merged commit 464f589 into LycheeOrg:master Feb 28, 2026
44 checks passed
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.

3 participants