New migration. Copypaste table now have foreign key for languages.
This commit is contained in:
parent
03baa5bb6c
commit
a79d56d973
|
@ -6,7 +6,7 @@ use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||||
use Doctrine\DBAL\Schema\Schema;
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auto-generated Migration: Please modify to your needs!
|
* Updating tables and column names
|
||||||
*/
|
*/
|
||||||
class Version20150302213116 extends AbstractMigration
|
class Version20150302213116 extends AbstractMigration
|
||||||
{
|
{
|
||||||
|
|
39
app/DoctrineMigrations/Version20150302223210.php
Normal file
39
app/DoctrineMigrations/Version20150302223210.php
Normal 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');
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,9 +41,10 @@ class Copypaste
|
||||||
private $description;
|
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;
|
private $language;
|
||||||
|
|
||||||
|
@ -138,7 +139,7 @@ class Copypaste
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get codeComment
|
* Get code description
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
@ -240,7 +241,7 @@ class Copypaste
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set dateExp
|
* Set expiration date
|
||||||
*
|
*
|
||||||
* @param \DateTime $dateExpire
|
* @param \DateTime $dateExpire
|
||||||
* @return Paste
|
* @return Paste
|
||||||
|
@ -253,7 +254,7 @@ class Copypaste
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get dateExp
|
* Get expiration date
|
||||||
*
|
*
|
||||||
* @return \DateTime
|
* @return \DateTime
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue