Version20161028123400.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. error_log('Version20161028123400');
  19. $iidColumn = $schema
  20. ->getTable('c_student_publication_comment')
  21. ->getColumn('iid');
  22. if (!$iidColumn->getAutoincrement()) {
  23. $iidColumn->setAutoincrement(true);
  24. }
  25. // Deleting users that don't exist anymore
  26. $sql = 'DELETE FROM access_url_rel_user WHERE user_id NOT IN (SELECT user_id from user)';
  27. $this->addSql($sql);
  28. $table = $schema->getTable('personal_agenda');
  29. if ($table->hasIndex('id')) {
  30. $this->addSql('ALTER TABLE personal_agenda DROP INDEX id');
  31. $this->addSql('ALTER TABLE personal_agenda DROP INDEX idx_personal_agenda_user');
  32. $this->addSql('ALTER TABLE personal_agenda DROP INDEX idx_personal_agenda_parent');
  33. $this->addSql('ALTER TABLE personal_agenda modify id INT NOT NULL');
  34. if ($table->hasPrimaryKey()) {
  35. $this->addSql('ALTER TABLE personal_agenda drop primary key ');
  36. }
  37. $this->addSql('ALTER TABLE personal_agenda CHANGE id id INT AUTO_INCREMENT NOT NULL PRIMARY KEY');
  38. $this->addSql('CREATE INDEX idx_personal_agenda_user ON personal_agenda (user)');
  39. $this->addSql('CREATE INDEX idx_personal_agenda_parent ON personal_agenda (parent_event_id)');
  40. }
  41. }
  42. /**
  43. * @param Schema $schema
  44. */
  45. public function down(Schema $schema)
  46. {
  47. $schema
  48. ->getTable('c_student_publication_comment')
  49. ->getColumn('iid')
  50. ->setAutoincrement(false);
  51. }
  52. }