-
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 #611 from leepeuker/add-watch-date-location
Add location to watch dates
- Loading branch information
Showing
25 changed files
with
910 additions
and
26 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
db/migrations/mysql/20240821173031_AddLocationToUserWatchDatesTable.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,47 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
final class AddLocationToUserWatchDatesTable extends AbstractMigration | ||
{ | ||
public function down() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
ALTER TABLE `movie_user_watch_dates` | ||
DROP FOREIGN KEY `fk_movie_user_watch_dates_location_id`, | ||
DROP COLUMN `location_id`; | ||
SQL | ||
); | ||
|
||
$this->execute( | ||
<<<SQL | ||
DROP TABLE IF EXISTS `location`; | ||
SQL | ||
); | ||
} | ||
|
||
public function up() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
CREATE TABLE `location` ( | ||
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, | ||
`user_id` INT(10) UNSIGNED NOT NULL, | ||
`name` TEXT NOT NULL, | ||
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
`updated_at` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, | ||
PRIMARY KEY (`id`), | ||
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE | ||
) | ||
SQL, | ||
); | ||
$this->execute( | ||
<<<SQL | ||
ALTER TABLE `movie_user_watch_dates` | ||
ADD COLUMN `location_id` INT(10) UNSIGNED DEFAULT NULL AFTER `position`, | ||
ADD CONSTRAINT `fk_movie_user_watch_dates_location_id` FOREIGN KEY (`location_id`) REFERENCES `location` (`id`) ON DELETE CASCADE; | ||
SQL | ||
); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
db/migrations/sqlite/20240821173031_AddLocationToUserWatchDatesTable.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,74 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
final class AddLocationToUserWatchDatesTable extends AbstractMigration | ||
{ | ||
public function down() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
DROP TABLE `location` | ||
SQL, | ||
); | ||
$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, | ||
`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, position) | ||
SELECT movie_id, user_id, watched_at, plays, comment, position 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 `location` ( | ||
`id` INTEGER NOT NULL, | ||
`user_id` TEXT NOT NULL, | ||
`name` TEXT NOT NULL, | ||
`created_at` TEXT NOT NULL, | ||
`updated_at` TEXT DEFAULT NULL, | ||
PRIMARY KEY (`id`), | ||
FOREIGN KEY (`user_id`) REFERENCES user (`id`) ON DELETE CASCADE | ||
) | ||
SQL, | ||
); | ||
$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, | ||
`position` INTEGER NOT NULL DEFAULT 1, | ||
`location_id` INTEGER DEFAULT NULL, | ||
FOREIGN KEY (`user_id`) REFERENCES user (`id`) ON DELETE CASCADE, | ||
FOREIGN KEY (`movie_id`) REFERENCES movie (`id`) ON DELETE CASCADE | ||
FOREIGN KEY (`location_id`) REFERENCES location (`id`) ON DELETE CASCADE | ||
) | ||
SQL, | ||
); | ||
$this->execute( | ||
'INSERT INTO `movie_user_watch_dates_tmp` (movie_id, user_id, watched_at, plays, comment, position ) | ||
SELECT movie_id, user_id, watched_at, plays, comment, position 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
Oops, something went wrong.