1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DoctrineMigrations; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Schema\Schema; |
8
|
|
|
use Doctrine\Migrations\AbstractMigration; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Auto-generated Migration: Please modify to your needs! |
12
|
|
|
*/ |
13
|
|
|
final class Version20180912064422 extends AbstractMigration |
14
|
|
|
{ |
15
|
|
|
public function up(Schema $schema): void |
16
|
|
|
{ |
17
|
|
|
// this up() migration is auto-generated, please modify it to your needs |
18
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); |
19
|
|
|
|
20
|
|
|
$this->addSql('CREATE SEQUENCE users_interested_movies_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); |
21
|
|
|
$this->addSql('CREATE TABLE users_interested_movies (id INT NOT NULL, user_id INT NOT NULL, movie_id INT NOT NULL, PRIMARY KEY(id))'); |
22
|
|
|
$this->addSql('CREATE INDEX IDX_F2A24D01A76ED395 ON users_interested_movies (user_id)'); |
23
|
|
|
$this->addSql('CREATE INDEX IDX_F2A24D018F93B6FC ON users_interested_movies (movie_id)'); |
24
|
|
|
$this->addSql('CREATE UNIQUE INDEX idx_UserInterestedMovie_user_id_movie_id ON users_interested_movies (user_id, movie_id)'); |
25
|
|
|
$this->addSql('ALTER TABLE users_interested_movies ADD CONSTRAINT FK_F2A24D01A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
26
|
|
|
$this->addSql('ALTER TABLE users_interested_movies ADD CONSTRAINT FK_F2A24D018F93B6FC FOREIGN KEY (movie_id) REFERENCES movies (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function down(Schema $schema): void |
30
|
|
|
{ |
31
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
32
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); |
33
|
|
|
|
34
|
|
|
$this->addSql('CREATE SCHEMA public'); |
35
|
|
|
$this->addSql('DROP SEQUENCE users_interested_movies_id_seq CASCADE'); |
36
|
|
|
$this->addSql('DROP TABLE users_interested_movies'); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|