-
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 #548 from leepeuker/add-watch-date-position
Add optional position to watch dates
- Loading branch information
Showing
14 changed files
with
250 additions
and
60 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
db/migrations/mysql/20231112151603_AddPositionToUserWatchDatesTable.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,24 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
final class AddPositionToUserWatchDatesTable extends AbstractMigration | ||
{ | ||
public function down() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
ALTER TABLE movie_user_watch_dates DROP COLUMN position; | ||
SQL, | ||
); | ||
} | ||
|
||
public function up() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
ALTER TABLE movie_user_watch_dates ADD COLUMN position SMALLINT DEFAULT 1 NOT NULL AFTER comment; | ||
SQL, | ||
); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
db/migrations/sqlite/20231112151603_AddPositionToUserWatchDatesTable.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 AddPositionToUserWatchDatesTable 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, | ||
`position` INTEGER NOT NULL DEFAULT 1, | ||
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
Oops, something went wrong.