New migration. Copypaste table now have foreign key for languages.

This commit is contained in:
Alexey Skobkin 2015-03-02 23:12:49 +03:00
parent 03baa5bb6c
commit a79d56d973
3 changed files with 46 additions and 6 deletions

View file

@ -6,7 +6,7 @@ use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
* Updating tables and column names
*/
class Version20150302213116 extends AbstractMigration
{

View file

@ -0,0 +1,39 @@
<?php
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Converting languages to the InnoDB and adding foreign key
*/
class Version20150302223210 extends AbstractMigration
{
public function up(Schema $schema)
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->write('Converting languages table to InnoDB format...');
$this->addSql('ALTER TABLE languages ENGINE=InnoDB');
$this->write('Updating copypaste table structure...');
$this->addSql('ALTER TABLE copypastes CHANGE language language_id INT DEFAULT NULL');
$this->write('Adding foreign key...');
$this->addSql('ALTER TABLE copypastes ADD CONSTRAINT FK_DBA4BEBE82F1BAF4 FOREIGN KEY (language_id) REFERENCES languages (id)');
$this->write('Creating copypaste language index...');
$this->addSql('CREATE INDEX IDX_DBA4BEBE82F1BAF4 ON copypastes (language_id)');
}
public function down(Schema $schema)
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->write('Dropping foreign key...');
$this->addSql('ALTER TABLE copypastes DROP FOREIGN KEY FK_DBA4BEBE82F1BAF4');
$this->write('Dropping copypaste language index...');
$this->addSql('DROP INDEX IDX_DBA4BEBE82F1BAF4 ON copypastes');
$this->addSql('ALTER TABLE copypastes CHANGE language_id language INT NOT NULL, DROP language_id');
$this->write('Converting languages table to MyISAM format...');
$this->addSql('ALTER TABLE languages ENGINE=MyISAM');
}
}

View file

@ -41,9 +41,10 @@ class Copypaste
private $description;
/**
* @var integer
* @var Language
*
* @ORM\Column(name="language", type="integer", nullable=false)
* @ORM\ManyToOne(targetEntity="Language")
* @ORM\JoinColumn(name="language_id", referencedColumnName="id")
*/
private $language;
@ -138,7 +139,7 @@ class Copypaste
}
/**
* Get codeComment
* Get code description
*
* @return string
*/
@ -240,7 +241,7 @@ class Copypaste
}
/**
* Set dateExp
* Set expiration date
*
* @param \DateTime $dateExpire
* @return Paste
@ -253,7 +254,7 @@ class Copypaste
}
/**
* Get dateExp
* Get expiration date
*
* @return \DateTime
*/