diff --git a/app/DoctrineMigrations/Version20150302213116.php b/app/DoctrineMigrations/Version20150302213116.php index 741d8ba..b7a8634 100644 --- a/app/DoctrineMigrations/Version20150302213116.php +++ b/app/DoctrineMigrations/Version20150302213116.php @@ -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 { diff --git a/app/DoctrineMigrations/Version20150302223210.php b/app/DoctrineMigrations/Version20150302223210.php new file mode 100644 index 0000000..eaaef21 --- /dev/null +++ b/app/DoctrineMigrations/Version20150302223210.php @@ -0,0 +1,39 @@ +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'); + } +} diff --git a/src/Skobkin/Bundle/CopyPasteBundle/Entity/Copypaste.php b/src/Skobkin/Bundle/CopyPasteBundle/Entity/Copypaste.php index 97496d2..ed58077 100644 --- a/src/Skobkin/Bundle/CopyPasteBundle/Entity/Copypaste.php +++ b/src/Skobkin/Bundle/CopyPasteBundle/Entity/Copypaste.php @@ -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 */