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