Version20160715122300.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. namespace Application\Migrations\Schema\V111;
  4. use Application\Migrations\AbstractMigrationChamilo;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\DBAL\Types\Type;
  7. /**
  8. * Class Version20160715122300
  9. * Add association mapping between Session and CStudentPublication
  10. * @package Application\Migrations\Schema\V111
  11. */
  12. class Version20160715122300 extends AbstractMigrationChamilo
  13. {
  14. /**
  15. * @param Schema $schema
  16. * @throws \Doctrine\DBAL\DBALException
  17. * @throws \Doctrine\DBAL\Schema\SchemaException
  18. */
  19. public function up(Schema $schema)
  20. {
  21. $this->addSql('ALTER TABLE c_student_publication CHANGE session_id session_id INT DEFAULT NULL');
  22. $this->addSql('UPDATE c_student_publication SET session_id = NULL WHERE session_id = 0');
  23. $this->addSql('ALTER TABLE c_student_publication ADD CONSTRAINT fk_session FOREIGN KEY (session_id) REFERENCES session (id)');
  24. }
  25. /**
  26. * @param Schema $schema
  27. * @throws \Doctrine\DBAL\DBALException
  28. * @throws \Doctrine\DBAL\Schema\SchemaException
  29. */
  30. public function down(Schema $schema)
  31. {
  32. $studentPublication = $schema->getTable('c_student_publication');
  33. $studentPublication->removeForeignKey('fk_session');
  34. $studentPublication->getColumn('session_id')->setNotnull(true);
  35. }
  36. }