From 8d350a89f478ee1a8fd6e84110cc5e3fcaeeb4aa Mon Sep 17 00:00:00 2001 From: Kyrch Date: Thu, 2 Apr 2026 12:39:11 -0300 Subject: [PATCH] feat: add IDs for pivots (#1149) --- .gitignore | 1 + app/Models/List/Playlist.php | 2 +- app/Models/Wiki/Anime.php | 6 ++-- .../Wiki/Anime/Theme/AnimeThemeEntry.php | 3 +- app/Models/Wiki/Artist.php | 21 ++++++++++--- app/Models/Wiki/ExternalResource.php | 10 +++--- app/Models/Wiki/Image.php | 5 ++- app/Models/Wiki/Series.php | 1 + app/Models/Wiki/Song.php | 4 +-- app/Models/Wiki/Studio.php | 5 +-- app/Models/Wiki/Video.php | 1 + app/Pivots/BaseMorphPivot.php | 31 ++++++------------- app/Pivots/BasePivot.php | 31 ++++++------------- app/Pivots/Document/PageRole.php | 14 --------- app/Pivots/Morph/Imageable.php | 14 --------- app/Pivots/Morph/Resourceable.php | 14 --------- app/Pivots/Wiki/AnimeSeries.php | 13 -------- app/Pivots/Wiki/AnimeStudio.php | 13 -------- app/Pivots/Wiki/AnimeThemeEntryVideo.php | 13 -------- app/Pivots/Wiki/ArtistMember.php | 13 -------- app/Pivots/Wiki/ArtistSong.php | 13 -------- .../2020_05_05_054036_create_anime_series.php | 3 +- ..._055804_create_anime_theme_entry_video.php | 3 +- .../2020_05_05_062655_create_artist_song.php | 3 +- ...2020_06_10_050701_create_artist_member.php | 3 +- .../2021_08_20_213018_create_anime_studio.php | 3 +- ...8_15_215051_create_resourceables_table.php | 5 +-- ...5_08_16_025830_create_imageables_table.php | 5 +-- 28 files changed, 75 insertions(+), 178 deletions(-) diff --git a/.gitignore b/.gitignore index 229589236..044ea46d3 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ yarn-error.log auth.json *.sqlite *.sqlite3 +*.sql public/css/app.css public/js/app.js test.php \ No newline at end of file diff --git a/app/Models/List/Playlist.php b/app/Models/List/Playlist.php index b0700f404..8fa687dfb 100644 --- a/app/Models/List/Playlist.php +++ b/app/Models/List/Playlist.php @@ -199,7 +199,7 @@ class Playlist extends BaseModel implements HasAggregateLikes, HasHashids, HasIm return $this->morphToMany(Image::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGEABLE_ID, Imageable::ATTRIBUTE_IMAGE) ->using(Imageable::class) ->as('playlistimage') - ->withPivot(Imageable::ATTRIBUTE_DEPTH) + ->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH]) ->withTimestamps(); } diff --git a/app/Models/Wiki/Anime.php b/app/Models/Wiki/Anime.php index c4ff73490..168870ab1 100644 --- a/app/Models/Wiki/Anime.php +++ b/app/Models/Wiki/Anime.php @@ -224,6 +224,7 @@ class Anime extends BaseModel implements Auditable, HasImages, HasResources, Has return $this->belongsToMany(Series::class, AnimeSeries::TABLE, AnimeSeries::ATTRIBUTE_ANIME, AnimeSeries::ATTRIBUTE_SERIES) ->using(AnimeSeries::class) ->as(AnimeSeriesJsonResource::$wrap) + ->withPivot(AnimeSeries::ATTRIBUTE_ID) ->withTimestamps(); } @@ -242,8 +243,8 @@ class Anime extends BaseModel implements Auditable, HasImages, HasResources, Has { return $this->morphToMany(ExternalResource::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCE) ->using(Resourceable::class) - ->withPivot(Resourceable::ATTRIBUTE_AS) ->as('animeresource') + ->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS]) ->withTimestamps(); } @@ -255,7 +256,7 @@ class Anime extends BaseModel implements Auditable, HasImages, HasResources, Has return $this->morphToMany(Image::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGEABLE_ID, Imageable::ATTRIBUTE_IMAGE) ->using(Imageable::class) ->as('animeimage') - ->withPivot(Imageable::ATTRIBUTE_DEPTH) + ->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH]) ->withTimestamps(); } @@ -267,6 +268,7 @@ class Anime extends BaseModel implements Auditable, HasImages, HasResources, Has return $this->belongsToMany(Studio::class, AnimeStudio::TABLE, AnimeStudio::ATTRIBUTE_ANIME, AnimeStudio::ATTRIBUTE_STUDIO) ->using(AnimeStudio::class) ->as(AnimeStudioJsonResource::$wrap) + ->withPivot(AnimeStudio::ATTRIBUTE_ID) ->withTimestamps(); } diff --git a/app/Models/Wiki/Anime/Theme/AnimeThemeEntry.php b/app/Models/Wiki/Anime/Theme/AnimeThemeEntry.php index dde1911ed..e27931851 100644 --- a/app/Models/Wiki/Anime/Theme/AnimeThemeEntry.php +++ b/app/Models/Wiki/Anime/Theme/AnimeThemeEntry.php @@ -208,6 +208,7 @@ class AnimeThemeEntry extends BaseModel implements Auditable, HasAggregateLikes, ) ->using(AnimeThemeEntryVideo::class) ->as(AnimeThemeEntryVideoJsonResource::$wrap) + ->withPivot([AnimeThemeEntryVideo::ATTRIBUTE_ID]) ->withTimestamps(); } @@ -218,8 +219,8 @@ class AnimeThemeEntry extends BaseModel implements Auditable, HasAggregateLikes, { return $this->morphToMany(ExternalResource::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCE) ->using(Resourceable::class) - ->withPivot(Resourceable::ATTRIBUTE_AS) ->as('entryresource') + ->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS]) ->withTimestamps(); } diff --git a/app/Models/Wiki/Artist.php b/app/Models/Wiki/Artist.php index 18b5b12f8..06adac530 100644 --- a/app/Models/Wiki/Artist.php +++ b/app/Models/Wiki/Artist.php @@ -191,6 +191,7 @@ class Artist extends BaseModel implements Auditable, HasImages, HasResources, Ha ->using(ArtistSong::class) ->withPivot([ArtistSong::ATTRIBUTE_ALIAS, ArtistSong::ATTRIBUTE_AS]) ->as(ArtistSongJsonResource::$wrap) + ->withPivot(ArtistSong::ATTRIBUTE_ID) ->withTimestamps(); } @@ -254,8 +255,14 @@ class Artist extends BaseModel implements Auditable, HasImages, HasResources, Ha { return $this->belongsToMany(Artist::class, ArtistMember::TABLE, ArtistMember::ATTRIBUTE_ARTIST, ArtistMember::ATTRIBUTE_MEMBER) ->using(ArtistMember::class) - ->withPivot([ArtistMember::ATTRIBUTE_ALIAS, ArtistMember::ATTRIBUTE_AS, ArtistMember::ATTRIBUTE_NOTES, ArtistMember::ATTRIBUTE_RELEVANCE]) ->as(ArtistMemberJsonResource::$wrap) + ->withPivot([ + ArtistMember::ATTRIBUTE_ID, + ArtistMember::ATTRIBUTE_ALIAS, + ArtistMember::ATTRIBUTE_AS, + ArtistMember::ATTRIBUTE_NOTES, + ArtistMember::ATTRIBUTE_RELEVANCE, + ]) ->withTimestamps(); } @@ -266,8 +273,14 @@ class Artist extends BaseModel implements Auditable, HasImages, HasResources, Ha { return $this->belongsToMany(Artist::class, ArtistMember::TABLE, ArtistMember::ATTRIBUTE_MEMBER, ArtistMember::ATTRIBUTE_ARTIST) ->using(ArtistMember::class) - ->withPivot([ArtistMember::ATTRIBUTE_ALIAS, ArtistMember::ATTRIBUTE_AS, ArtistMember::ATTRIBUTE_NOTES]) ->as(ArtistMemberJsonResource::$wrap) + ->withPivot([ + ArtistMember::ATTRIBUTE_ID, + ArtistMember::ATTRIBUTE_ALIAS, + ArtistMember::ATTRIBUTE_AS, + ArtistMember::ATTRIBUTE_NOTES, + ArtistMember::ATTRIBUTE_RELEVANCE, + ]) ->withTimestamps(); } @@ -278,8 +291,8 @@ class Artist extends BaseModel implements Auditable, HasImages, HasResources, Ha { return $this->morphToMany(ExternalResource::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCE) ->using(Resourceable::class) - ->withPivot(Resourceable::ATTRIBUTE_AS) ->as('artistresource') + ->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS]) ->withTimestamps(); } @@ -290,8 +303,8 @@ class Artist extends BaseModel implements Auditable, HasImages, HasResources, Ha { return $this->morphToMany(Image::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGEABLE_ID, Imageable::ATTRIBUTE_IMAGE) ->using(Imageable::class) - ->withPivot(Imageable::ATTRIBUTE_DEPTH) ->as('artistimage') + ->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH]) ->withTimestamps(); } } diff --git a/app/Models/Wiki/ExternalResource.php b/app/Models/Wiki/ExternalResource.php index 226f27415..b39d04e55 100644 --- a/app/Models/Wiki/ExternalResource.php +++ b/app/Models/Wiki/ExternalResource.php @@ -114,8 +114,8 @@ class ExternalResource extends BaseModel implements Auditable, SoftDeletable { return $this->morphedByMany(Anime::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID) ->using(Resourceable::class) - ->withPivot(Resourceable::ATTRIBUTE_AS) ->as('animeresource') + ->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS]) ->withTimestamps(); } @@ -126,8 +126,8 @@ class ExternalResource extends BaseModel implements Auditable, SoftDeletable { return $this->morphedByMany(AnimeThemeEntry::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID) ->using(Resourceable::class) - ->withPivot(Resourceable::ATTRIBUTE_AS) ->as('entryresource') + ->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS]) ->withTimestamps(); } @@ -138,8 +138,8 @@ class ExternalResource extends BaseModel implements Auditable, SoftDeletable { return $this->morphedByMany(Artist::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID) ->using(Resourceable::class) - ->withPivot(Resourceable::ATTRIBUTE_AS) ->as('artistresource') + ->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS]) ->withTimestamps(); } @@ -150,8 +150,8 @@ class ExternalResource extends BaseModel implements Auditable, SoftDeletable { return $this->morphedByMany(Song::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID) ->using(Resourceable::class) - ->withPivot(Resourceable::ATTRIBUTE_AS) ->as('songresource') + ->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS]) ->withTimestamps(); } @@ -162,8 +162,8 @@ class ExternalResource extends BaseModel implements Auditable, SoftDeletable { return $this->morphedByMany(Studio::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID) ->using(Resourceable::class) - ->withPivot(Resourceable::ATTRIBUTE_AS) ->as('studioresource') + ->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS]) ->withTimestamps(); } } diff --git a/app/Models/Wiki/Image.php b/app/Models/Wiki/Image.php index b97c1cb71..814268ec4 100644 --- a/app/Models/Wiki/Image.php +++ b/app/Models/Wiki/Image.php @@ -133,6 +133,7 @@ class Image extends BaseModel implements Auditable, SoftDeletable return $this->morphedByMany(Anime::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGE, Imageable::ATTRIBUTE_IMAGEABLE_ID) ->using(Imageable::class) ->as('animeimage') + ->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH]) ->withTimestamps(); } @@ -144,7 +145,7 @@ class Image extends BaseModel implements Auditable, SoftDeletable return $this->morphedByMany(Artist::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGE, Imageable::ATTRIBUTE_IMAGEABLE_ID) ->using(Imageable::class) ->as('artistimage') - ->withPivot(Imageable::ATTRIBUTE_DEPTH) + ->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH]) ->withTimestamps(); } @@ -156,6 +157,7 @@ class Image extends BaseModel implements Auditable, SoftDeletable return $this->morphedByMany(Studio::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGE, Imageable::ATTRIBUTE_IMAGEABLE_ID) ->using(Imageable::class) ->as('studioimage') + ->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH]) ->withTimestamps(); } @@ -167,6 +169,7 @@ class Image extends BaseModel implements Auditable, SoftDeletable return $this->morphedByMany(Playlist::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGE, Imageable::ATTRIBUTE_IMAGEABLE_ID) ->using(Imageable::class) ->as('playlistimage') + ->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH]) ->withTimestamps(); } } diff --git a/app/Models/Wiki/Series.php b/app/Models/Wiki/Series.php index ab30e5b22..b0fde868c 100644 --- a/app/Models/Wiki/Series.php +++ b/app/Models/Wiki/Series.php @@ -140,6 +140,7 @@ class Series extends BaseModel implements Auditable, SoftDeletable return $this->belongsToMany(Anime::class, AnimeSeries::TABLE, AnimeSeries::ATTRIBUTE_SERIES, AnimeSeries::ATTRIBUTE_ANIME) ->using(AnimeSeries::class) ->as(AnimeSeriesJsonResource::$wrap) + ->withPivot([AnimeSeries::ATTRIBUTE_ID]) ->withTimestamps(); } } diff --git a/app/Models/Wiki/Song.php b/app/Models/Wiki/Song.php index 6db9ae0ec..d0a92271f 100644 --- a/app/Models/Wiki/Song.php +++ b/app/Models/Wiki/Song.php @@ -155,8 +155,8 @@ class Song extends BaseModel implements Auditable, HasResources, SoftDeletable { return $this->belongsToMany(Artist::class, ArtistSong::TABLE, ArtistSong::ATTRIBUTE_SONG, ArtistSong::ATTRIBUTE_ARTIST) ->using(ArtistSong::class) - ->withPivot([ArtistSong::ATTRIBUTE_ALIAS, ArtistSong::ATTRIBUTE_AS]) ->as(ArtistSongJsonResource::$wrap) + ->withPivot([ArtistSong::ATTRIBUTE_ID, ArtistSong::ATTRIBUTE_ALIAS, ArtistSong::ATTRIBUTE_AS]) ->withTimestamps(); } @@ -175,8 +175,8 @@ class Song extends BaseModel implements Auditable, HasResources, SoftDeletable { return $this->morphToMany(ExternalResource::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCE) ->using(Resourceable::class) - ->withPivot(Resourceable::ATTRIBUTE_AS) ->as('songresource') + ->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS]) ->withTimestamps(); } } diff --git a/app/Models/Wiki/Studio.php b/app/Models/Wiki/Studio.php index be6cc10e8..d1115835e 100644 --- a/app/Models/Wiki/Studio.php +++ b/app/Models/Wiki/Studio.php @@ -138,6 +138,7 @@ class Studio extends BaseModel implements Auditable, HasImages, HasResources, So return $this->belongsToMany(Anime::class, AnimeStudio::TABLE, AnimeStudio::ATTRIBUTE_STUDIO, AnimeStudio::ATTRIBUTE_ANIME) ->using(AnimeStudio::class) ->as(AnimeStudioJsonResource::$wrap) + ->withPivot([AnimeStudio::ATTRIBUTE_ID]) ->withTimestamps(); } @@ -148,8 +149,8 @@ class Studio extends BaseModel implements Auditable, HasImages, HasResources, So { return $this->morphToMany(ExternalResource::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCE) ->using(Resourceable::class) - ->withPivot(Resourceable::ATTRIBUTE_AS) ->as('studioresource') + ->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS]) ->withTimestamps(); } @@ -161,7 +162,7 @@ class Studio extends BaseModel implements Auditable, HasImages, HasResources, So return $this->morphToMany(Image::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGEABLE_ID, Imageable::ATTRIBUTE_IMAGE) ->using(Imageable::class) ->as('studioimage') - ->withPivot(Imageable::ATTRIBUTE_DEPTH) + ->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH]) ->withTimestamps(); } } diff --git a/app/Models/Wiki/Video.php b/app/Models/Wiki/Video.php index b2812dda2..3631e3e7b 100644 --- a/app/Models/Wiki/Video.php +++ b/app/Models/Wiki/Video.php @@ -310,6 +310,7 @@ class Video extends BaseModel implements Auditable, SoftDeletable, Streamable return $this->belongsToMany(AnimeThemeEntry::class, AnimeThemeEntryVideo::TABLE, AnimeThemeEntryVideo::ATTRIBUTE_VIDEO, AnimeThemeEntryVideo::ATTRIBUTE_ENTRY) ->using(AnimeThemeEntryVideo::class) ->as(AnimeThemeEntryVideoJsonResource::$wrap) + ->withPivot([AnimeThemeEntryVideo::ATTRIBUTE_ID]) ->withTimestamps(); } diff --git a/app/Pivots/BaseMorphPivot.php b/app/Pivots/BaseMorphPivot.php index a2f425dab..10ee29279 100644 --- a/app/Pivots/BaseMorphPivot.php +++ b/app/Pivots/BaseMorphPivot.php @@ -4,13 +4,13 @@ declare(strict_types=1); namespace App\Pivots; -use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphPivot; use Illuminate\Support\Carbon; /** + * @property int $id * @property Carbon $created_at * @property Carbon $updated_at */ @@ -18,32 +18,19 @@ abstract class BaseMorphPivot extends MorphPivot { use HasFactory; + final public const ATTRIBUTE_ID = 'id'; final public const ATTRIBUTE_CREATED_AT = Model::CREATED_AT; final public const ATTRIBUTE_UPDATED_AT = Model::UPDATED_AT; + /** + * Indicates if the IDs are auto-incrementing. + * + * @var bool + */ + public $incrementing = true; + /** * The storage format of the model's date columns. */ protected $dateFormat = 'Y-m-d\TH:i:s.u'; - - /** - * Set the keys for a select query. - * - * @noinspection PhpMissingParentCallCommonInspection - */ - protected function setKeysForSelectQuery($query): Builder - { - foreach ($this->getPrimaryKeys() as $primaryKey) { - $query->where($primaryKey, $this->getAttribute($primaryKey)); - } - - return $query; - } - - /** - * Get the composite primary key for the pivot. - * - * @return string[] - */ - abstract protected function getPrimaryKeys(): array; } diff --git a/app/Pivots/BasePivot.php b/app/Pivots/BasePivot.php index 15fcb8005..ad741a85e 100644 --- a/app/Pivots/BasePivot.php +++ b/app/Pivots/BasePivot.php @@ -4,13 +4,13 @@ declare(strict_types=1); namespace App\Pivots; -use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Support\Carbon; /** + * @property int $id * @property Carbon $created_at * @property Carbon $updated_at */ @@ -18,32 +18,19 @@ abstract class BasePivot extends Pivot { use HasFactory; + final public const ATTRIBUTE_ID = 'id'; final public const ATTRIBUTE_CREATED_AT = Model::CREATED_AT; final public const ATTRIBUTE_UPDATED_AT = Model::UPDATED_AT; + /** + * Indicates if the IDs are auto-incrementing. + * + * @var bool + */ + public $incrementing = true; + /** * The storage format of the model's date columns. */ protected $dateFormat = 'Y-m-d\TH:i:s.u'; - - /** - * Set the keys for a select query. - * - * @noinspection PhpMissingParentCallCommonInspection - */ - protected function setKeysForSelectQuery($query): Builder - { - foreach ($this->getPrimaryKeys() as $primaryKey) { - $query->where($primaryKey, $this->getAttribute($primaryKey)); - } - - return $query; - } - - /** - * Get the composite primary key for the pivot. - * - * @return string[] - */ - abstract protected function getPrimaryKeys(): array; } diff --git a/app/Pivots/Document/PageRole.php b/app/Pivots/Document/PageRole.php index 61f0f5411..5e095c2d7 100644 --- a/app/Pivots/Document/PageRole.php +++ b/app/Pivots/Document/PageRole.php @@ -13,7 +13,6 @@ use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Relations\BelongsTo; /** - * @property int $id * @property Page $page * @property int $page_id * @property Role $role @@ -27,7 +26,6 @@ class PageRole extends BasePivot { final public const string TABLE = 'page_roles'; - final public const string ATTRIBUTE_ID = 'id'; final public const string ATTRIBUTE_PAGE = 'page_id'; final public const string ATTRIBUTE_ROLE = 'role_id'; final public const string ATTRIBUTE_TYPE = 'type'; @@ -46,18 +44,6 @@ class PageRole extends BasePivot PageRole::ATTRIBUTE_TYPE, ]; - /** - * Get the composite primary key for the pivot. - * - * @return string[] - */ - protected function getPrimaryKeys(): array - { - return [ - PageRole::ATTRIBUTE_ID, - ]; - } - /** * Get the attributes that should be cast. * diff --git a/app/Pivots/Morph/Imageable.php b/app/Pivots/Morph/Imageable.php index ee262cc79..9f45c2a41 100644 --- a/app/Pivots/Morph/Imageable.php +++ b/app/Pivots/Morph/Imageable.php @@ -96,20 +96,6 @@ class Imageable extends BaseMorphPivot ]; } - /** - * Get the composite primary key for the pivot. - * - * @return string[] - */ - protected function getPrimaryKeys(): array - { - return [ - Imageable::ATTRIBUTE_IMAGE, - Imageable::ATTRIBUTE_IMAGEABLE_TYPE, - Imageable::ATTRIBUTE_IMAGEABLE_ID, - ]; - } - /** * Gets the image that owns the imageable. * diff --git a/app/Pivots/Morph/Resourceable.php b/app/Pivots/Morph/Resourceable.php index 21d8057de..a2d0a8a80 100644 --- a/app/Pivots/Morph/Resourceable.php +++ b/app/Pivots/Morph/Resourceable.php @@ -83,20 +83,6 @@ class Resourceable extends BaseMorphPivot Resourceable::ATTRIBUTE_RESOURCEABLE_ID, ]; - /** - * Get the composite primary key for the pivot. - * - * @return string[] - */ - protected function getPrimaryKeys(): array - { - return [ - Resourceable::ATTRIBUTE_RESOURCE, - Resourceable::ATTRIBUTE_RESOURCEABLE_TYPE, - Resourceable::ATTRIBUTE_RESOURCEABLE_ID, - ]; - } - /** * Get the attributes that should be cast. * diff --git a/app/Pivots/Wiki/AnimeSeries.php b/app/Pivots/Wiki/AnimeSeries.php index 97fb704f0..e88b08a61 100644 --- a/app/Pivots/Wiki/AnimeSeries.php +++ b/app/Pivots/Wiki/AnimeSeries.php @@ -54,19 +54,6 @@ class AnimeSeries extends BasePivot AnimeSeries::ATTRIBUTE_SERIES, ]; - /** - * Get the composite primary key for the pivot. - * - * @return string[] - */ - protected function getPrimaryKeys(): array - { - return [ - AnimeSeries::ATTRIBUTE_ANIME, - AnimeSeries::ATTRIBUTE_SERIES, - ]; - } - /** * Get the attributes that should be cast. * diff --git a/app/Pivots/Wiki/AnimeStudio.php b/app/Pivots/Wiki/AnimeStudio.php index aa02855c4..5623f1009 100644 --- a/app/Pivots/Wiki/AnimeStudio.php +++ b/app/Pivots/Wiki/AnimeStudio.php @@ -54,19 +54,6 @@ class AnimeStudio extends BasePivot AnimeStudio::ATTRIBUTE_STUDIO, ]; - /** - * Get the composite primary key for the pivot. - * - * @return string[] - */ - protected function getPrimaryKeys(): array - { - return [ - AnimeStudio::ATTRIBUTE_ANIME, - AnimeStudio::ATTRIBUTE_STUDIO, - ]; - } - /** * Get the attributes that should be cast. * diff --git a/app/Pivots/Wiki/AnimeThemeEntryVideo.php b/app/Pivots/Wiki/AnimeThemeEntryVideo.php index 0edba1628..9e0814c3d 100644 --- a/app/Pivots/Wiki/AnimeThemeEntryVideo.php +++ b/app/Pivots/Wiki/AnimeThemeEntryVideo.php @@ -58,19 +58,6 @@ class AnimeThemeEntryVideo extends BasePivot AnimeThemeEntryVideo::ATTRIBUTE_VIDEO, ]; - /** - * Get the composite primary key for the pivot. - * - * @return string[] - */ - protected function getPrimaryKeys(): array - { - return [ - AnimeThemeEntryVideo::ATTRIBUTE_ENTRY, - AnimeThemeEntryVideo::ATTRIBUTE_VIDEO, - ]; - } - /** * Get the attributes that should be cast. * diff --git a/app/Pivots/Wiki/ArtistMember.php b/app/Pivots/Wiki/ArtistMember.php index a3e65557c..9e7f17983 100644 --- a/app/Pivots/Wiki/ArtistMember.php +++ b/app/Pivots/Wiki/ArtistMember.php @@ -67,19 +67,6 @@ class ArtistMember extends BasePivot ArtistMember::ATTRIBUTE_RELEVANCE, ]; - /** - * Get the composite primary key for the pivot. - * - * @return string[] - */ - protected function getPrimaryKeys(): array - { - return [ - ArtistMember::ATTRIBUTE_ARTIST, - ArtistMember::ATTRIBUTE_MEMBER, - ]; - } - /** * Get the attributes that should be cast. * diff --git a/app/Pivots/Wiki/ArtistSong.php b/app/Pivots/Wiki/ArtistSong.php index 31671d23f..52eefe74c 100644 --- a/app/Pivots/Wiki/ArtistSong.php +++ b/app/Pivots/Wiki/ArtistSong.php @@ -46,19 +46,6 @@ class ArtistSong extends BasePivot ArtistSong::ATTRIBUTE_SONG, ]; - /** - * Get the composite primary key for the pivot. - * - * @return string[] - */ - protected function getPrimaryKeys(): array - { - return [ - ArtistSong::ATTRIBUTE_ARTIST, - ArtistSong::ATTRIBUTE_SONG, - ]; - } - /** * Get the attributes that should be cast. * diff --git a/database/migrations/2020_05_05_054036_create_anime_series.php b/database/migrations/2020_05_05_054036_create_anime_series.php index 3cbea128f..1c21c59da 100644 --- a/database/migrations/2020_05_05_054036_create_anime_series.php +++ b/database/migrations/2020_05_05_054036_create_anime_series.php @@ -15,12 +15,13 @@ return new class extends Migration { if (! Schema::hasTable('anime_series')) { Schema::create('anime_series', function (Blueprint $table) { + $table->id(); $table->timestamps(6); $table->unsignedBigInteger('anime_id'); $table->foreign('anime_id')->references('anime_id')->on('anime')->cascadeOnDelete(); $table->unsignedBigInteger('series_id'); $table->foreign('series_id')->references('series_id')->on('series')->cascadeOnDelete(); - $table->primary(['anime_id', 'series_id']); + $table->unique(['anime_id', 'series_id'], 'anime_series_unique'); }); } } diff --git a/database/migrations/2020_05_05_055804_create_anime_theme_entry_video.php b/database/migrations/2020_05_05_055804_create_anime_theme_entry_video.php index 48bb079de..0e445889d 100644 --- a/database/migrations/2020_05_05_055804_create_anime_theme_entry_video.php +++ b/database/migrations/2020_05_05_055804_create_anime_theme_entry_video.php @@ -15,12 +15,13 @@ return new class extends Migration { if (! Schema::hasTable('anime_theme_entry_video')) { Schema::create('anime_theme_entry_video', function (Blueprint $table) { + $table->id(); $table->timestamps(6); $table->unsignedBigInteger('entry_id'); $table->foreign('entry_id')->references('entry_id')->on('anime_theme_entries')->cascadeOnDelete(); $table->unsignedBigInteger('video_id'); $table->foreign('video_id')->references('video_id')->on('videos')->cascadeOnDelete(); - $table->primary(['entry_id', 'video_id']); + $table->unique(['entry_id', 'video_id'], 'entry_video_unique'); }); } } diff --git a/database/migrations/2020_05_05_062655_create_artist_song.php b/database/migrations/2020_05_05_062655_create_artist_song.php index 9bdc770ec..cc8d66f20 100644 --- a/database/migrations/2020_05_05_062655_create_artist_song.php +++ b/database/migrations/2020_05_05_062655_create_artist_song.php @@ -15,14 +15,15 @@ return new class extends Migration { if (! Schema::hasTable('artist_song')) { Schema::create('artist_song', function (Blueprint $table) { + $table->id(); $table->timestamps(6); $table->unsignedBigInteger('artist_id'); $table->foreign('artist_id')->references('artist_id')->on('artists')->cascadeOnDelete(); $table->unsignedBigInteger('song_id'); $table->foreign('song_id')->references('song_id')->on('songs')->cascadeOnDelete(); - $table->primary(['artist_id', 'song_id']); $table->string('as')->nullable(); $table->string('alias')->nullable(); + $table->unique(['artist_id', 'song_id'], 'artist_song_unique'); }); } } diff --git a/database/migrations/2020_06_10_050701_create_artist_member.php b/database/migrations/2020_06_10_050701_create_artist_member.php index c88718e90..d1bc33905 100644 --- a/database/migrations/2020_06_10_050701_create_artist_member.php +++ b/database/migrations/2020_06_10_050701_create_artist_member.php @@ -15,15 +15,16 @@ return new class extends Migration { if (! Schema::hasTable('artist_member')) { Schema::create('artist_member', function (Blueprint $table) { + $table->id(); $table->timestamps(6); $table->unsignedBigInteger('artist_id'); $table->foreign('artist_id')->references('artist_id')->on('artists')->cascadeOnDelete(); $table->unsignedBigInteger('member_id'); $table->foreign('member_id')->references('artist_id')->on('artists')->cascadeOnDelete(); - $table->primary(['artist_id', 'member_id']); $table->string('as')->nullable(); $table->string('alias')->nullable(); $table->string('notes')->nullable(); + $table->unique(['artist_id', 'member_id'], 'artist_member_unique'); }); } } diff --git a/database/migrations/2021_08_20_213018_create_anime_studio.php b/database/migrations/2021_08_20_213018_create_anime_studio.php index 0d7ddc6ee..706db39c9 100644 --- a/database/migrations/2021_08_20_213018_create_anime_studio.php +++ b/database/migrations/2021_08_20_213018_create_anime_studio.php @@ -15,12 +15,13 @@ return new class extends Migration { if (! Schema::hasTable('anime_studio')) { Schema::create('anime_studio', function (Blueprint $table) { + $table->id(); $table->timestamps(6); $table->unsignedBigInteger('anime_id'); $table->foreign('anime_id')->references('anime_id')->on('anime')->cascadeOnDelete(); $table->unsignedBigInteger('studio_id'); $table->foreign('studio_id')->references('studio_id')->on('studios')->cascadeOnDelete(); - $table->primary(['anime_id', 'studio_id']); + $table->unique(['anime_id', 'studio_id'], 'anime_studio_unique'); }); } } diff --git a/database/migrations/2025_08_15_215051_create_resourceables_table.php b/database/migrations/2025_08_15_215051_create_resourceables_table.php index 468edb1ff..a102b6018 100644 --- a/database/migrations/2025_08_15_215051_create_resourceables_table.php +++ b/database/migrations/2025_08_15_215051_create_resourceables_table.php @@ -15,6 +15,7 @@ return new class extends Migration { if (! Schema::hasTable('resourceables')) { Schema::create('resourceables', function (Blueprint $table) { + $table->id(); $table->unsignedBigInteger('resource_id'); $table->foreign('resource_id')->references('resource_id')->on('resources')->cascadeOnDelete(); @@ -23,11 +24,11 @@ return new class extends Migration $table->timestamps(6); - $table->primary([ + $table->unique([ 'resource_id', 'resourceable_type', 'resourceable_id', - ]); + ], 'resourceable_unique'); }); } } diff --git a/database/migrations/2025_08_16_025830_create_imageables_table.php b/database/migrations/2025_08_16_025830_create_imageables_table.php index 25231f915..b9ff4670d 100644 --- a/database/migrations/2025_08_16_025830_create_imageables_table.php +++ b/database/migrations/2025_08_16_025830_create_imageables_table.php @@ -15,6 +15,7 @@ return new class extends Migration { if (! Schema::hasTable('imageables')) { Schema::create('imageables', function (Blueprint $table) { + $table->id(); $table->unsignedBigInteger('image_id'); $table->foreign('image_id')->references('image_id')->on('images')->cascadeOnDelete(); @@ -23,11 +24,11 @@ return new class extends Migration $table->timestamps(6); - $table->primary([ + $table->unique([ 'image_id', 'imageable_type', 'imageable_id', - ]); + ], 'imageable_unique'); }); } }