add foreign key from report to scope

This commit is contained in:
2015-06-22 23:45:59 +02:00
parent 1c3c3b14ab
commit eb066b86aa
3 changed files with 58 additions and 8 deletions

View File

@@ -10,10 +10,6 @@ Chill\ReportBundle\Entity\Report:
fields:
date:
type: datetime
scope:
type: string
length: 255
nullable: true # TO REMOVE IF SCOPE IS USED
cFData:
type: json_array
manyToOne:
@@ -21,6 +17,8 @@ Chill\ReportBundle\Entity\Report:
targetEntity: Chill\MainBundle\Entity\User
person:
targetEntity: Chill\PersonBundle\Entity\Person
scope:
targetEntity: Chill\MainBundle\Entity\Scope
cFGroup:
targetEntity: Chill\CustomFieldsBundle\Entity\CustomFieldsGroup
lifecycleCallbacks: { }

View File

@@ -0,0 +1,42 @@
<?php
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Add a scope to report
*/
class Version20150622233319 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql',
'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE report ADD scope_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE report DROP scope'); //before this migration, scope was never used
$this->addSql('ALTER TABLE report ADD CONSTRAINT FK_report_scope '
. 'FOREIGN KEY (scope_id) '
. 'REFERENCES scopes (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_report_scope ON report (scope_id)');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql',
'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE Report DROP CONSTRAINT FK_C38372B2682B5931');
$this->addSql('DROP INDEX IDX_C38372B2682B5931');
$this->addSql('ALTER TABLE Report ADD scope VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE Report DROP scope_id');
}
}