1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Victoire\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 Version20170217154601 extends AbstractMigration |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @param Schema $schema |
15
|
|
|
*/ |
16
|
|
View Code Duplication |
public function up(Schema $schema) |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
// this up() migration is auto-generated, please modify it to your needs |
19
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); |
20
|
|
|
|
21
|
|
|
$this->addSql('CREATE TABLE vic_business_entity (id INT AUTO_INCREMENT NOT NULL, endpoint_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, availableWidgets LONGTEXT NOT NULL, type VARCHAR(255) NOT NULL, resource VARCHAR(255) DEFAULT NULL, getMethod LONGTEXT DEFAULT NULL, listMethod LONGTEXT DEFAULT NULL, pagerParameter LONGTEXT DEFAULT NULL, class VARCHAR(255) DEFAULT NULL, INDEX IDX_C445185621AF7E36 (endpoint_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;'); |
22
|
|
|
$this->addSql('CREATE TABLE vic_business_property (id INT AUTO_INCREMENT NOT NULL, business_entity_id INT DEFAULT NULL, types LONGTEXT DEFAULT NULL, name VARCHAR(255) DEFAULT NULL, choices LONGTEXT DEFAULT NULL, listMethod LONGTEXT DEFAULT NULL, filterMethod LONGTEXT DEFAULT NULL, INDEX IDX_A8EAD01198417B22 (business_entity_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;'); |
23
|
|
|
$this->addSql('CREATE TABLE vic_entity_proxy_new (id INT AUTO_INCREMENT NOT NULL, business_entity_id INT DEFAULT NULL, ressource_id VARCHAR(255) DEFAULT NULL, additionnal_properties LONGTEXT DEFAULT NULL, INDEX IDX_7BB88CBD98417B22 (business_entity_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;'); |
24
|
|
|
$this->addSql('CREATE TABLE vic_api_endpoint (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, host LONGTEXT NOT NULL, token LONGTEXT DEFAULT NULL, tokenType VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;'); |
25
|
|
|
$this->addSql('ALTER TABLE vic_business_entity ADD CONSTRAINT FK_C445185621AF7E36 FOREIGN KEY (endpoint_id) REFERENCES vic_api_endpoint (id) ON DELETE SET NULL;'); |
26
|
|
|
$this->addSql('ALTER TABLE vic_business_property ADD CONSTRAINT FK_A8EAD01198417B22 FOREIGN KEY (business_entity_id) REFERENCES vic_business_entity (id);'); |
27
|
|
|
$this->addSql('ALTER TABLE vic_entity_proxy_new ADD CONSTRAINT FK_7BB88CBD98417B22 FOREIGN KEY (business_entity_id) REFERENCES vic_business_entity (id) ON DELETE CASCADE;'); |
28
|
|
|
$this->addSql('ALTER TABLE vic_view DROP FOREIGN KEY FK_FAA91F341341DB46;'); |
29
|
|
|
$this->addSql('ALTER TABLE vic_view ADD related_business_entity_id INT DEFAULT NULL;'); |
30
|
|
|
$this->addSql('ALTER TABLE vic_view ADD CONSTRAINT FK_FAA91F342B7846BB FOREIGN KEY (related_business_entity_id) REFERENCES vic_business_entity (id) ON DELETE CASCADE;'); |
31
|
|
|
$this->addSql('CREATE INDEX IDX_FAA91F342B7846BB ON vic_view (related_business_entity_id);'); |
32
|
|
|
$this->addSql('ALTER TABLE vic_widget DROP FOREIGN KEY FK_57DF2B231341DB46;'); |
33
|
|
|
$this->addSql('ALTER TABLE vic_widget ADD related_business_entity_id INT DEFAULT NULL;'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param Schema $schema |
38
|
|
|
*/ |
39
|
|
View Code Duplication |
public function down(Schema $schema) |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
42
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); |
43
|
|
|
|
44
|
|
|
$this->addSql('DROP TABLE vic_business_entity;'); |
45
|
|
|
$this->addSql('DROP TABLE vic_business_property;'); |
46
|
|
|
$this->addSql('DROP TABLE vic_entity_proxy_new;'); |
47
|
|
|
$this->addSql('DROP TABLE vic_api_endpoint;'); |
48
|
|
|
$this->addSql('ALTER TABLE vic_business_entity DROP FOREIGN KEY FK_C445185621AF7E36;'); |
49
|
|
|
$this->addSql('ALTER TABLE vic_business_property DROP FOREIGN KEY FK_A8EAD01198417B22;'); |
50
|
|
|
$this->addSql('ALTER TABLE vic_entity_proxy_new DROP FOREIGN KEY FK_7BB88CBD98417B22 ;'); |
51
|
|
|
$this->addSql('ALTER TABLE vic_view ADD FOREIGN KEY FK_FAA91F341341DB46 FOREIGN KEY (entityProxy_id) REFERENCES vic_entity_proxy (id) ON DELETE CASCADE;'); |
52
|
|
|
$this->addSql('ALTER TABLE vic_view DROP COLUMN related_business_entity_id;'); |
53
|
|
|
$this->addSql('ALTER TABLE vic_view DROP FOREIGN KEY FK_FAA91F342B7846BB;'); |
54
|
|
|
$this->addSql('ALTER TABLE vic_view DROP INDEX IDX_FAA91F342B7846BB;'); |
55
|
|
|
$this->addSql('ALTER TABLE vic_widget ADD FOREIGN KEY FK_57DF2B231341DB46 FOREIGN KEY (entityProxy_id) REFERENCES vic_entity_proxy (id) ON DELETE CASCADE;'); |
56
|
|
|
$this->addSql('ALTER TABLE vic_widget DROP COLUMN related_business_entity_id;'); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.