|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Zenstruck\Foundry\Tests\Fixtures\Migrations; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
8
|
|
|
use Doctrine\Migrations\AbstractMigration; |
|
9
|
|
|
|
|
10
|
|
|
final class Version20210820131819 extends AbstractMigration |
|
11
|
|
|
{ |
|
12
|
|
|
public function getDescription(): string |
|
13
|
|
|
{ |
|
14
|
|
|
return ''; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function up(Schema $schema): void |
|
18
|
|
|
{ |
|
19
|
|
|
$this->addSql('CREATE TABLE bars (id INT AUTO_INCREMENT NOT NULL, foo_id INT DEFAULT NULL, INDEX IDX_2D7B7A718E48560F (foo_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); |
|
20
|
|
|
$this->addSql('CREATE TABLE foos (id INT AUTO_INCREMENT NOT NULL, one_to_one_id INT NOT NULL, many_to_one_id INT NOT NULL, UNIQUE INDEX UNIQ_57EBAC30B549C760 (one_to_one_id), INDEX IDX_57EBAC30EAB5DEB (many_to_one_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); |
|
21
|
|
|
$this->addSql('CREATE TABLE foo_bar (foo_id INT NOT NULL, bar_id INT NOT NULL, INDEX IDX_8D1AB1FE8E48560F (foo_id), INDEX IDX_8D1AB1FE89A253A (bar_id), PRIMARY KEY(foo_id, bar_id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); |
|
22
|
|
|
$this->addSql('ALTER TABLE bars ADD CONSTRAINT FK_2D7B7A718E48560F FOREIGN KEY (foo_id) REFERENCES foos (id)'); |
|
23
|
|
|
$this->addSql('ALTER TABLE foos ADD CONSTRAINT FK_57EBAC30B549C760 FOREIGN KEY (one_to_one_id) REFERENCES bars (id)'); |
|
24
|
|
|
$this->addSql('ALTER TABLE foos ADD CONSTRAINT FK_57EBAC30EAB5DEB FOREIGN KEY (many_to_one_id) REFERENCES bars (id)'); |
|
25
|
|
|
$this->addSql('ALTER TABLE foo_bar ADD CONSTRAINT FK_8D1AB1FE8E48560F FOREIGN KEY (foo_id) REFERENCES foos (id) ON DELETE CASCADE'); |
|
26
|
|
|
$this->addSql('ALTER TABLE foo_bar ADD CONSTRAINT FK_8D1AB1FE89A253A FOREIGN KEY (bar_id) REFERENCES bars (id) ON DELETE CASCADE'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function down(Schema $schema): void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->addSql('ALTER TABLE foos DROP FOREIGN KEY FK_57EBAC30B549C760'); |
|
32
|
|
|
$this->addSql('ALTER TABLE foos DROP FOREIGN KEY FK_57EBAC30EAB5DEB'); |
|
33
|
|
|
$this->addSql('ALTER TABLE foo_bar DROP FOREIGN KEY FK_8D1AB1FE89A253A'); |
|
34
|
|
|
$this->addSql('ALTER TABLE bars DROP FOREIGN KEY FK_2D7B7A718E48560F'); |
|
35
|
|
|
$this->addSql('ALTER TABLE foo_bar DROP FOREIGN KEY FK_8D1AB1FE8E48560F'); |
|
36
|
|
|
$this->addSql('DROP TABLE bars'); |
|
37
|
|
|
$this->addSql('DROP TABLE foos'); |
|
38
|
|
|
$this->addSql('DROP TABLE foo_bar'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function isTransactional(): bool |
|
42
|
|
|
{ |
|
43
|
|
|
return false; |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|