Skip to content

Commit ac67199

Browse files
authored
Drop legacy id (#3375)
1 parent d9c363a commit ac67199

8 files changed

Lines changed: 70 additions & 91 deletions

File tree

app/Constants/RandomID.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,4 @@ class RandomID
2727
*/
2828
public const ID_LENGTH = 24;
2929
public const ID_TYPE = 'string';
30-
public const LEGACY_ID_NAME = 'legacy_id';
31-
public const LEGACY_ID_TYPE = 'integer';
3230
}

app/Exceptions/Handler.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use App\Exceptions\Handlers\AccessDBDenied;
1515
use App\Exceptions\Handlers\AdminSetterHandler;
1616
use App\Exceptions\Handlers\InstallationHandler;
17-
use App\Exceptions\Handlers\LegacyIdExceptionHandler;
1817
use App\Exceptions\Handlers\MigrationHandler;
1918
use App\Exceptions\Handlers\NoEncryptionKey;
2019
use App\Exceptions\Handlers\ViteManifestNotFoundHandler;
@@ -115,7 +114,6 @@ class Handler extends ExceptionHandler
115114
AdminSetterHandler::class,
116115
MigrationHandler::class,
117116
ViteManifestNotFoundHandler::class,
118-
LegacyIdExceptionHandler::class,
119117
];
120118

121119
/** @var array<int,class-string<\Throwable>> */

app/Exceptions/Handlers/LegacyIdExceptionHandler.php

Lines changed: 0 additions & 54 deletions
This file was deleted.

app/Models/BaseAlbumImpl.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
* implementation of it) and we need this class to be instantiable.
9898
*
9999
* @property string $id
100-
* @property int $legacy_id
101100
* @property Carbon $created_at
102101
* @property Carbon $updated_at
103102
* @property string $title
@@ -176,7 +175,6 @@ class BaseAlbumImpl extends Model implements HasRandomID
176175
*/
177176
protected $attributes = [
178177
'id' => null,
179-
RandomID::LEGACY_ID_NAME => null,
180178
'created_at' => null,
181179
'updated_at' => null,
182180
'title' => null, // Sic! `title` is actually non-nullable, but using `null` here forces the caller to actually set a title before saving.
@@ -196,7 +194,6 @@ class BaseAlbumImpl extends Model implements HasRandomID
196194
*/
197195
protected $casts = [
198196
'id' => RandomID::ID_TYPE,
199-
RandomID::LEGACY_ID_NAME => RandomID::LEGACY_ID_TYPE,
200197
'created_at' => 'datetime',
201198
'updated_at' => 'datetime',
202199
'is_nsfw' => 'boolean',

app/Models/Extensions/BaseAlbum.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
*
3737
* @property string $id
3838
* @property string $title
39-
* @property int $legacy_id
4039
* @property Carbon $created_at
4140
* @property Carbon $updated_at
4241
* @property string|null $description

app/Models/Extensions/HasRandomIDAndLegacyTimeBasedID.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use App\Exceptions\InsufficientEntropyException;
1313
use App\Exceptions\Internal\NotImplementedException;
1414
use App\Exceptions\Internal\TimeBasedIdException;
15-
use App\Models\Configs;
1615
use Illuminate\Database\Eloquent\Builder;
1716
use Illuminate\Database\Eloquent\InvalidCastException;
1817
use Illuminate\Database\Eloquent\JsonEncodingException;
@@ -64,9 +63,6 @@ public function setAttribute($key, $value): mixed
6463
if ($key === $this->getKeyName()) {
6564
throw new NotImplementedException('must not set primary key explicitly, primary key will be set on first insert');
6665
}
67-
if ($key === RandomID::LEGACY_ID_NAME) {
68-
throw new NotImplementedException('must not set legacy key explicitly, legacy key will be set on first insert');
69-
}
7066

7167
return parent::setAttribute($key, $value);
7268
}
@@ -170,27 +166,6 @@ private function generateKey(): void
170166
} catch (\Exception $e) {
171167
throw new InsufficientEntropyException($e);
172168
}
173-
// @codeCoverageIgnoreEnd
174-
if (
175-
PHP_INT_MAX === 2147483647 ||
176-
Configs::getValueAsBool('force_32bit_ids')
177-
) {
178-
// For 32-bit installations, we can only afford to store the
179-
// full seconds in id. The calling code needs to be able to
180-
// handle duplicate ids. Note that this also exposes us to
181-
// the year 2038 problem.
182-
// @codeCoverageIgnoreStart
183-
$legacy_id = sprintf('%010d', microtime(true));
184-
// @codeCoverageIgnoreEnd
185-
} else {
186-
// Ensure 4 digits after the decimal point, 15 characters
187-
// total (including the decimal point), 0-padded on the
188-
// left if needed (shouldn't be needed unless we move back in
189-
// time :-) )
190-
$legacy_id = sprintf('%015.4f', microtime(true));
191-
$legacy_id = str_replace('.', '', $legacy_id);
192-
}
193169
$this->attributes[$this->getKeyName()] = $id;
194-
$this->attributes[RandomID::LEGACY_ID_NAME] = intval($legacy_id);
195170
}
196171
}

app/Models/Photo.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use App\Casts\ArrayCast;
1313
use App\Casts\DateTimeWithTimezoneCast;
1414
use App\Casts\MustNotSetCast;
15-
use App\Constants\RandomID;
1615
use App\Contracts\Models\HasUTCBasedTimes;
1716
use App\Enum\LicenseType;
1817
use App\Enum\StorageDiskType;
@@ -43,7 +42,6 @@
4342
* App\Models\Photo.
4443
*
4544
* @property string $id
46-
* @property int $legacy_id
4745
* @property string $title
4846
* @property string|null $description
4947
* @property string[] $tags
@@ -151,7 +149,6 @@ class Photo extends Model implements HasUTCBasedTimes
151149
public $incrementing = false;
152150

153151
protected $casts = [
154-
RandomID::LEGACY_ID_NAME => RandomID::LEGACY_ID_TYPE,
155152
'created_at' => 'datetime',
156153
'updated_at' => 'datetime',
157154
'taken_at' => DateTimeWithTimezoneCast::class,
@@ -172,7 +169,6 @@ class Photo extends Model implements HasUTCBasedTimes
172169
* relation but shall not be serialized to JSON
173170
*/
174171
protected $hidden = [
175-
RandomID::LEGACY_ID_NAME,
176172
'album', // do not serialize relation in order to avoid infinite loops
177173
'owner', // do not serialize relation
178174
'owner_id',
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2025 LycheeOrg.
7+
*/
8+
9+
use Illuminate\Database\Migrations\Migration;
10+
use Illuminate\Database\Schema\Blueprint;
11+
12+
return new class() extends Migration {
13+
public const LEGACY_ID_NAME = 'legacy_id';
14+
15+
/**
16+
* Run the migrations.
17+
*/
18+
public function up(): void
19+
{
20+
try {
21+
Schema::table('photos', function (Blueprint $table) {
22+
$table->dropUnique('photos_legacy_id_unique');
23+
});
24+
Schema::table('base_albums', function (Blueprint $table) {
25+
$table->dropUnique('base_albums_legacy_id_unique');
26+
});
27+
} catch (\Throwable $e) {
28+
// Do nothing
29+
}
30+
31+
Schema::table('photos', function (Blueprint $table) {
32+
$table->dropColumn(self::LEGACY_ID_NAME);
33+
});
34+
Schema::table('base_albums', function (Blueprint $table) {
35+
$table->dropColumn(self::LEGACY_ID_NAME);
36+
});
37+
38+
DB::table('configs')
39+
->where('key', '=', 'legacy_id_redirection')
40+
->delete();
41+
}
42+
43+
/**
44+
* Reverse the migrations.
45+
*/
46+
public function down(): void
47+
{
48+
Schema::table('base_albums', function (Blueprint $table) {
49+
$table->unsignedBigInteger('legacy_id')->after('id')->nullable(false);
50+
});
51+
52+
Schema::table('photos', function (Blueprint $table) {
53+
$table->unsignedBigInteger('legacy_id')->after('id')->nullable(false);
54+
});
55+
56+
DB::table('configs')
57+
->insert([
58+
'key' => 'legacy_id_redirection',
59+
'value' => '1',
60+
'cat' => 'Admin',
61+
'type_range' => '0|1',
62+
'is_secret' => 0,
63+
'description' => 'Enables/disables the redirection support for legacy IDs',
64+
'level' => 0,
65+
'not_on_docker' => 0,
66+
'is_expert' => 1,
67+
'order' => 6,
68+
]);
69+
}
70+
};

0 commit comments

Comments
 (0)