Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/Constants/RandomID.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ class RandomID
*/
public const ID_LENGTH = 24;
public const ID_TYPE = 'string';
public const LEGACY_ID_NAME = 'legacy_id';
public const LEGACY_ID_TYPE = 'integer';
}
2 changes: 0 additions & 2 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use App\Exceptions\Handlers\AccessDBDenied;
use App\Exceptions\Handlers\AdminSetterHandler;
use App\Exceptions\Handlers\InstallationHandler;
use App\Exceptions\Handlers\LegacyIdExceptionHandler;
use App\Exceptions\Handlers\MigrationHandler;
use App\Exceptions\Handlers\NoEncryptionKey;
use App\Exceptions\Handlers\ViteManifestNotFoundHandler;
Expand Down Expand Up @@ -115,7 +114,6 @@ class Handler extends ExceptionHandler
AdminSetterHandler::class,
MigrationHandler::class,
ViteManifestNotFoundHandler::class,
LegacyIdExceptionHandler::class,
];

/** @var array<int,class-string<\Throwable>> */
Expand Down
54 changes: 0 additions & 54 deletions app/Exceptions/Handlers/LegacyIdExceptionHandler.php

This file was deleted.

3 changes: 0 additions & 3 deletions app/Models/BaseAlbumImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
* implementation of it) and we need this class to be instantiable.
*
* @property string $id
* @property int $legacy_id
* @property Carbon $created_at
* @property Carbon $updated_at
* @property string $title
Expand Down Expand Up @@ -176,7 +175,6 @@ class BaseAlbumImpl extends Model implements HasRandomID
*/
protected $attributes = [
'id' => null,
RandomID::LEGACY_ID_NAME => null,
'created_at' => null,
'updated_at' => null,
'title' => null, // Sic! `title` is actually non-nullable, but using `null` here forces the caller to actually set a title before saving.
Expand All @@ -196,7 +194,6 @@ class BaseAlbumImpl extends Model implements HasRandomID
*/
protected $casts = [
'id' => RandomID::ID_TYPE,
RandomID::LEGACY_ID_NAME => RandomID::LEGACY_ID_TYPE,
'created_at' => 'datetime',
'updated_at' => 'datetime',
'is_nsfw' => 'boolean',
Expand Down
1 change: 0 additions & 1 deletion app/Models/Extensions/BaseAlbum.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
*
* @property string $id
* @property string $title
* @property int $legacy_id
* @property Carbon $created_at
* @property Carbon $updated_at
* @property string|null $description
Expand Down
25 changes: 0 additions & 25 deletions app/Models/Extensions/HasRandomIDAndLegacyTimeBasedID.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use App\Exceptions\InsufficientEntropyException;
use App\Exceptions\Internal\NotImplementedException;
use App\Exceptions\Internal\TimeBasedIdException;
use App\Models\Configs;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\InvalidCastException;
use Illuminate\Database\Eloquent\JsonEncodingException;
Expand Down Expand Up @@ -64,9 +63,6 @@ public function setAttribute($key, $value): mixed
if ($key === $this->getKeyName()) {
throw new NotImplementedException('must not set primary key explicitly, primary key will be set on first insert');
}
if ($key === RandomID::LEGACY_ID_NAME) {
throw new NotImplementedException('must not set legacy key explicitly, legacy key will be set on first insert');
}

return parent::setAttribute($key, $value);
}
Expand Down Expand Up @@ -170,27 +166,6 @@ private function generateKey(): void
} catch (\Exception $e) {
throw new InsufficientEntropyException($e);
}
// @codeCoverageIgnoreEnd
if (
PHP_INT_MAX === 2147483647 ||
Configs::getValueAsBool('force_32bit_ids')
) {
// For 32-bit installations, we can only afford to store the
// full seconds in id. The calling code needs to be able to
// handle duplicate ids. Note that this also exposes us to
// the year 2038 problem.
// @codeCoverageIgnoreStart
$legacy_id = sprintf('%010d', microtime(true));
// @codeCoverageIgnoreEnd
} else {
// Ensure 4 digits after the decimal point, 15 characters
// total (including the decimal point), 0-padded on the
// left if needed (shouldn't be needed unless we move back in
// time :-) )
$legacy_id = sprintf('%015.4f', microtime(true));
$legacy_id = str_replace('.', '', $legacy_id);
}
$this->attributes[$this->getKeyName()] = $id;
$this->attributes[RandomID::LEGACY_ID_NAME] = intval($legacy_id);
}
}
4 changes: 0 additions & 4 deletions app/Models/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use App\Casts\ArrayCast;
use App\Casts\DateTimeWithTimezoneCast;
use App\Casts\MustNotSetCast;
use App\Constants\RandomID;
use App\Contracts\Models\HasUTCBasedTimes;
use App\Enum\LicenseType;
use App\Enum\StorageDiskType;
Expand Down Expand Up @@ -43,7 +42,6 @@
* App\Models\Photo.
*
* @property string $id
* @property int $legacy_id
* @property string $title
* @property string|null $description
* @property string[] $tags
Expand Down Expand Up @@ -151,7 +149,6 @@ class Photo extends Model implements HasUTCBasedTimes
public $incrementing = false;

protected $casts = [
RandomID::LEGACY_ID_NAME => RandomID::LEGACY_ID_TYPE,
'created_at' => 'datetime',
'updated_at' => 'datetime',
'taken_at' => DateTimeWithTimezoneCast::class,
Expand All @@ -172,7 +169,6 @@ class Photo extends Model implements HasUTCBasedTimes
* relation but shall not be serialized to JSON
*/
protected $hidden = [
RandomID::LEGACY_ID_NAME,
'album', // do not serialize relation in order to avoid infinite loops
'owner', // do not serialize relation
'owner_id',
Expand Down
70 changes: 70 additions & 0 deletions database/migrations/2025_05_27_081037_drop_legacy_id.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

return new class() extends Migration {
public const LEGACY_ID_NAME = 'legacy_id';

/**
* Run the migrations.
*/
public function up(): void
{
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
}

Schema::table('photos', function (Blueprint $table) {
$table->dropColumn(self::LEGACY_ID_NAME);
});
Schema::table('base_albums', function (Blueprint $table) {
$table->dropColumn(self::LEGACY_ID_NAME);
});

DB::table('configs')
->where('key', '=', 'legacy_id_redirection')
->delete();
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('base_albums', function (Blueprint $table) {
$table->unsignedBigInteger('legacy_id')->after('id')->nullable(false);
});

Schema::table('photos', function (Blueprint $table) {
$table->unsignedBigInteger('legacy_id')->after('id')->nullable(false);
});

DB::table('configs')
->insert([
'key' => 'legacy_id_redirection',
'value' => '1',
'cat' => 'Admin',
'type_range' => '0|1',
'is_secret' => 0,
'description' => 'Enables/disables the redirection support for legacy IDs',
'level' => 0,
'not_on_docker' => 0,
'is_expert' => 1,
'order' => 6,
]);
}
};