-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from leepeuker/fix-cast-issue-on-missing-char…
…acter-name Make cast character names nullable to prevent errors when name missing
- Loading branch information
Showing
5 changed files
with
66 additions
and
18 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
db/migrations/mysql/20221225093745_SetCastCharacterNameColumnToNullable.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
final class SetCastCharacterNameColumnToNullable extends AbstractMigration | ||
{ | ||
public function down() : void | ||
{ | ||
$this->execute('ALTER TABLE movie_cast MODIFY character_name TEXT NOT NULL'); | ||
} | ||
|
||
public function up() : void | ||
{ | ||
$this->execute('ALTER TABLE movie_cast MODIFY character_name TEXT DEFAULT NULL'); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
db/migrations/sqlite/20221225093745_SetCastCharacterNameColumnToNullable.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
final class SetCastCharacterNameColumnToNullable extends AbstractMigration | ||
{ | ||
public function down() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
CREATE TABLE `tmp_movie_cast` ( | ||
`person_id` INTEGER NOT NULL, | ||
`movie_id` INTEGER NOT NULL, | ||
`character_name` TEXT NOT NULL, | ||
`position` INTEGER DEFAULT NULL, | ||
FOREIGN KEY (`person_id`) REFERENCES person (`id`) ON DELETE CASCADE, | ||
FOREIGN KEY (`movie_id`) REFERENCES movie (`id`) ON DELETE CASCADE, | ||
UNIQUE (`movie_id`, `position`) | ||
) | ||
SQL, | ||
); | ||
$this->execute('INSERT INTO `tmp_movie_cast` (person_id, movie_id, character_name, position) SELECT * FROM movie_cast'); | ||
$this->execute('DROP TABLE `movie_cast`'); | ||
$this->execute('ALTER TABLE `tmp_movie_cast` RENAME TO `movie_cast`'); | ||
} | ||
|
||
public function up() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
CREATE TABLE `tmp_movie_cast` ( | ||
`person_id` INTEGER NOT NULL, | ||
`movie_id` INTEGER NOT NULL, | ||
`character_name` TEXT DEFAULT NULL, | ||
`position` INTEGER DEFAULT NULL, | ||
FOREIGN KEY (`person_id`) REFERENCES person (`id`) ON DELETE CASCADE, | ||
FOREIGN KEY (`movie_id`) REFERENCES movie (`id`) ON DELETE CASCADE, | ||
UNIQUE (`movie_id`, `position`) | ||
) | ||
SQL, | ||
); | ||
$this->execute('INSERT INTO `tmp_movie_cast` (person_id, movie_id, character_name, position) SELECT * FROM movie_cast'); | ||
$this->execute('DROP TABLE `movie_cast`'); | ||
$this->execute('ALTER TABLE `tmp_movie_cast` RENAME TO `movie_cast`'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters