|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Migrations; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Migrations\AbstractMigration; |
|
6
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Auto-generated Migration: Please modify to your needs! |
|
10
|
|
|
*/ |
|
11
|
|
|
class Version20180308222215 extends AbstractMigration |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
public function up(Schema $schema) |
|
14
|
|
|
{ |
|
15
|
|
|
// this up() migration is auto-generated, please modify it to your needs |
|
16
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); |
|
17
|
|
|
|
|
18
|
|
|
$this->addSql('CREATE TABLE users__organizations (user_id INT NOT NULL, organization_id INT NOT NULL, INDEX IDX_9394C5E4A76ED395 (user_id), INDEX IDX_9394C5E432C8A3DE (organization_id), PRIMARY KEY(user_id, organization_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'); |
|
19
|
|
|
$this->addSql('ALTER TABLE users__organizations ADD CONSTRAINT FK_9394C5E4A76ED395 FOREIGN KEY (user_id) REFERENCES users__user (id) ON DELETE CASCADE'); |
|
20
|
|
|
$this->addSql('ALTER TABLE users__organizations ADD CONSTRAINT FK_9394C5E432C8A3DE FOREIGN KEY (organization_id) REFERENCES organization (id) ON DELETE CASCADE'); |
|
21
|
|
|
$this->addSql('ALTER TABLE users__user DROP FOREIGN KEY FK_37C1021B32C8A3DE'); |
|
22
|
|
|
$this->addSql('DROP INDEX IDX_37C1021B32C8A3DE ON users__user'); |
|
23
|
|
|
$this->addSql('ALTER TABLE users__user DROP organization_id'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function down(Schema $schema) |
|
27
|
|
|
{ |
|
28
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
|
29
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); |
|
30
|
|
|
|
|
31
|
|
|
$this->addSql('DROP TABLE users__organizations'); |
|
32
|
|
|
$this->addSql('ALTER TABLE users__user ADD organization_id INT DEFAULT NULL'); |
|
33
|
|
|
$this->addSql('ALTER TABLE users__user ADD CONSTRAINT FK_37C1021B32C8A3DE FOREIGN KEY (organization_id) REFERENCES organization (id)'); |
|
34
|
|
|
$this->addSql('CREATE INDEX IDX_37C1021B32C8A3DE ON users__user (organization_id)'); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|