Version20161028123400.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. /**
  7. * Class Version20161028123400
  8. * Add primary key as auto increment in c_student_publication_comment
  9. * @package Application\Migrations\Schema\V111
  10. */
  11. class Version20161028123400 extends AbstractMigrationChamilo
  12. {
  13. /**
  14. * @param Schema $schema
  15. */
  16. public function up(Schema $schema)
  17. {
  18. $iidColumn = $schema
  19. ->getTable('c_student_publication_comment')
  20. ->getColumn('iid');
  21. if (!$iidColumn->getAutoincrement()) {
  22. $iidColumn->setAutoincrement(true);
  23. }
  24. // Deleting users that don't exist anymore
  25. $sql = 'DELETE FROM access_url_rel_user WHERE user_id NOT IN (SELECT user_id from user)';
  26. $this->addSql($sql);
  27. $table = $schema->getTable('personal_agenda');
  28. if ($table->hasIndex('id')) {
  29. $this->addSql('ALTER TABLE personal_agenda modify id INT NOT NULL');
  30. $this->addSql('ALTER TABLE personal_agenda DROP index id');
  31. $this->addSql('ALTER TABLE personal_agenda DROP PRIMARY KEY');
  32. $this->addSql('ALTER TABLE personal_agenda CHANGE id id INT AUTO_INCREMENT NOT NULL PRIMARY KEY');
  33. }
  34. }
  35. /**
  36. * @param Schema $schema
  37. */
  38. public function down(Schema $schema)
  39. {
  40. $schema
  41. ->getTable('c_student_publication_comment')
  42. ->getColumn('iid')
  43. ->setAutoincrement(false);
  44. }
  45. }