Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
2 changed files with 57 additions and 2 deletions
Showing only changes of commit 4c2abf5416 - Show all commits

View File

@ -23,7 +23,9 @@ class ReorganizeAnimeCollectionMedia extends AbstractMigration
// Get the old link entries // Get the old link entries
$insertRows = []; $insertRows = [];
$rows = $this->fetchAll('SELECT hummingbird_id, media_id from anime_set'); $rows = ($this->table('anime_set')->hasColumn('media_id'))
? $this->fetchAll('SELECT hummingbird_id, media_id from anime_set')
: [];
// Filter the numeric keys out of the row results // Filter the numeric keys out of the row results
foreach ($rows as $row) foreach ($rows as $row)
@ -39,7 +41,6 @@ class ReorganizeAnimeCollectionMedia extends AbstractMigration
$insertRows[] = $row; $insertRows[] = $row;
} }
// And put them in the new table // And put them in the new table
$linkTable = $this->table('anime_set_media_link'); $linkTable = $this->table('anime_set_media_link');
$linkTable->insert($insertRows)->save(); $linkTable->insert($insertRows)->save();

View File

@ -0,0 +1,54 @@
<?php
use Phinx\Migration\AbstractMigration;
class AnimeCollectionRefactorCleanup extends AbstractMigration
{
protected array $newMediaTypes = [
'LaserDisc',
'VHS',
'Digital',
'Video CD',
'Betamax',
'UMD',
'Other',
];
public function up()
{
// Add some new media types
$moreMediaTypes = [];
foreach ($this->newMediaTypes as $id => $medium)
{
$moreMediaTypes[] = [
'id' => $id + 5,
'type' => $medium,
];
}
$this->table('media')->insert($moreMediaTypes)->save();
// Cleanup existing media types a bit
$this->execute("UPDATE media SET type='Bootleg' WHERE id=4");
$this->execute('DELETE FROM media WHERE id=1');
// Remove foreign key and media_id column from anime_set
$animeSet = $this->table('anime_set');
if ($animeSet->hasColumn('media_id'))
{
$animeSet->dropForeignKey('media_id')->save();
$animeSet->removeColumn('media_id')->save();
}
}
public function down()
{
// Restore the original values for existing media
$this->execute("INSERT INTO media (id, type) VALUES (1, 'DVD & Blu-ray')");
$this->execute("UPDATE media SET type='Bootleg DVD' WHERE id=4");
// Remove the new media types
$values = array_map(fn ($medium) => "'{$medium}'", $this->newMediaTypes);
$valueList = implode(',', $values);
$this->execute("DELETE FROM media WHERE type IN ({$valueList})");
}
}