-
Notifications
You must be signed in to change notification settings - Fork 17
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 #503 from leepeuker/remove-watch-date-requirement-…
…for-plays Remove requirement of watch date for plays
- Loading branch information
Showing
20 changed files
with
397 additions
and
250 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
db/migrations/mysql/20230911074701_SetWatchDateNullableForUsers.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,29 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
final class SetWatchDateNullableForUsers extends AbstractMigration | ||
{ | ||
public function down() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
ALTER TABLE movie_user_watch_dates ADD PRIMARY KEY (movie_id, user_id, watched_at); | ||
ALTER TABLE movie_user_watch_dates DROP CONSTRAINT unique_watched_dates; | ||
ALTER TABLE movie_user_watch_dates MODIFY COLUMN watched_at DATE NOT NULL ; | ||
SQL, | ||
); | ||
} | ||
|
||
public function up() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
ALTER TABLE movie_user_watch_dates ADD CONSTRAINT unique_watched_dates UNIQUE (movie_id, user_id, watched_at); | ||
ALTER TABLE movie_user_watch_dates DROP PRIMARY KEY; | ||
ALTER TABLE movie_user_watch_dates MODIFY COLUMN watched_at DATE NULL; | ||
SQL, | ||
); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
db/migrations/sqlite/20230911074701_SetWatchDateNullableForUsers.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,53 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
final class SetWatchDateNullableForUsers extends AbstractMigration | ||
{ | ||
public function down() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
CREATE TABLE `movie_user_watch_dates_tmp` ( | ||
`movie_id` INTEGER NOT NULL, | ||
`user_id` INTEGER NOT NULL, | ||
`watched_at` TEXT NOT NULL, | ||
`plays` INTEGER DEFAULT 1, | ||
`comment` TEXT DEFAULT NULL, | ||
FOREIGN KEY (`user_id`) REFERENCES user (`id`) ON DELETE CASCADE, | ||
FOREIGN KEY (`movie_id`) REFERENCES movie (`id`) ON DELETE CASCADE | ||
) | ||
SQL, | ||
); | ||
$this->execute( | ||
'INSERT INTO `movie_user_watch_dates_tmp` (movie_id, user_id, watched_at, plays, comment) | ||
SELECT movie_id, user_id, watched_at, plays, comment FROM movie_user_watch_dates', | ||
); | ||
$this->execute('DROP TABLE `movie_user_watch_dates`'); | ||
$this->execute('ALTER TABLE `movie_user_watch_dates_tmp` RENAME TO `movie_user_watch_dates`'); | ||
} | ||
|
||
public function up() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
CREATE TABLE `movie_user_watch_dates_tmp` ( | ||
`movie_id` INTEGER NOT NULL, | ||
`user_id` INTEGER NOT NULL, | ||
`watched_at` TEXT, | ||
`plays` INTEGER DEFAULT 1, | ||
`comment` TEXT DEFAULT NULL, | ||
UNIQUE(`movie_id`, `user_id`, `watched_at`), | ||
FOREIGN KEY (`user_id`) REFERENCES user (`id`) ON DELETE CASCADE, | ||
FOREIGN KEY (`movie_id`) REFERENCES movie (`id`) ON DELETE CASCADE | ||
) | ||
SQL, | ||
); | ||
$this->execute( | ||
'INSERT INTO `movie_user_watch_dates_tmp` (movie_id, user_id, watched_at, plays, comment) | ||
SELECT * FROM movie_user_watch_dates', | ||
); | ||
$this->execute('DROP TABLE `movie_user_watch_dates`'); | ||
$this->execute('ALTER TABLE `movie_user_watch_dates_tmp` RENAME TO `movie_user_watch_dates`'); | ||
} | ||
} |
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
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
Oops, something went wrong.