Version20160405112100.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 Version20160405112100
  8. * @package Application\Migrations\Schema\V111
  9. */
  10. class Version20160405112100 extends AbstractMigrationChamilo
  11. {
  12. /**
  13. * @param Schema $schema
  14. */
  15. public function up(Schema $schema)
  16. {
  17. $this->addSql(
  18. 'CREATE TABLE skill_level_profile (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
  19. );
  20. $this->addSql(
  21. 'CREATE TABLE skill_level (id INT AUTO_INCREMENT NOT NULL, profile_id INT NOT NULL, name VARCHAR(255) NOT NULL, position INT, short_name VARCHAR(255), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
  22. );
  23. $this->addSql(
  24. 'ALTER TABLE skill_rel_user ADD acquired_level INT, ADD argumentation TEXT, ADD argumentation_author_id INT, MODIFY course_id INT, MODIFY session_id INT'
  25. );
  26. $this->addSql(
  27. 'CREATE TABLE skill_rel_user_comment (id INT AUTO_INCREMENT NOT NULL, skill_rel_user_id INT NOT NULL, feedback_giver_id INT NOT NULL, feedback_text TEXT, feedback_value INT, feedback_datetime DATETIME, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
  28. );
  29. $this->addSql('ALTER TABLE skill ADD profile_id INT');
  30. if ($schema->hasTable('skill')) {
  31. $table = $schema->getTable('skill');
  32. if ($table->hasForeignKey('FK_5E3DE477CCFA12B8') == false) {
  33. $this->addSql('ALTER TABLE skill ADD CONSTRAINT FK_5E3DE477CCFA12B8 FOREIGN KEY (profile_id) REFERENCES skill_level_profile (id);');
  34. }
  35. if ($table->hasIndex('IDX_5E3DE477CCFA12B8') == false) {
  36. $this->addSql('CREATE INDEX IDX_5E3DE477CCFA12B8 ON skill (profile_id);');
  37. }
  38. }
  39. // Skill
  40. if ($schema->hasTable('skill')) {
  41. $this->addSql('ALTER TABLE skill CHANGE name name VARCHAR(255) NOT NULL, CHANGE short_code short_code VARCHAR(100) NOT NULL, CHANGE description description LONGTEXT NOT NULL, CHANGE icon icon VARCHAR(255) NOT NULL, CHANGE updated_at updated_at DATETIME NOT NULL;');
  42. }
  43. // skill_rel_user
  44. if ($schema->hasTable('skill_rel_user')) {
  45. $table = $schema->getTable('skill_rel_user');
  46. $this->addSql('ALTER TABLE skill_rel_user CHANGE acquired_skill_at acquired_skill_at DATETIME NOT NULL, CHANGE argumentation argumentation LONGTEXT NOT NULL, CHANGE argumentation_author_id argumentation_author_id INT NOT NULL;');
  47. $this->addSql('UPDATE skill_rel_user SET course_id = NULL WHERE course_id = 0');
  48. $this->addSql('UPDATE skill_rel_user SET skill_id = NULL WHERE skill_id = 0');
  49. $this->addSql('UPDATE skill_rel_user SET user_id = NULL WHERE user_id = 0');
  50. $this->addSql('UPDATE skill_rel_user SET session_id = NULL WHERE session_id = 0');
  51. $this->addSql('UPDATE skill_rel_user SET acquired_level = NULL WHERE acquired_level = 0');
  52. if ($table->hasForeignKey('FK_79D3D95AA76ED395') == false) {
  53. $this->addSql('ALTER TABLE skill_rel_user ADD CONSTRAINT FK_79D3D95AA76ED395 FOREIGN KEY (user_id) REFERENCES user (id);');
  54. }
  55. if ($table->hasForeignKey('FK_79D3D95A5585C142') == false) {
  56. $this->addSql('ALTER TABLE skill_rel_user ADD CONSTRAINT FK_79D3D95A5585C142 FOREIGN KEY (skill_id) REFERENCES skill (id);');
  57. }
  58. if ($table->hasForeignKey('FK_79D3D95A591CC992') == false) {
  59. $this->addSql('ALTER TABLE skill_rel_user ADD CONSTRAINT FK_79D3D95A591CC992 FOREIGN KEY (course_id) REFERENCES course (id);');
  60. }
  61. if ($table->hasForeignKey('FK_79D3D95A613FECDF') == false) {
  62. $this->addSql('ALTER TABLE skill_rel_user ADD CONSTRAINT FK_79D3D95A613FECDF FOREIGN KEY (session_id) REFERENCES session (id);');
  63. }
  64. if ($table->hasForeignKey('FK_79D3D95AF68F11CE') == false) {
  65. $this->addSql('ALTER TABLE skill_rel_user ADD CONSTRAINT FK_79D3D95AF68F11CE FOREIGN KEY (acquired_level) REFERENCES skill_level (id);');
  66. }
  67. if ($table->hasIndex('IDX_79D3D95AA76ED395') == false) {
  68. $this->addSql('CREATE INDEX IDX_79D3D95AA76ED395 ON skill_rel_user(user_id);');
  69. }
  70. if ($table->hasIndex('IDX_79D3D95A5585C142') == false) {
  71. $this->addSql('CREATE INDEX IDX_79D3D95A5585C142 ON skill_rel_user(skill_id);');
  72. }
  73. if ($table->hasIndex('IDX_79D3D95A591CC992') == false) {
  74. $this->addSql('CREATE INDEX IDX_79D3D95A591CC992 ON skill_rel_user(course_id);');
  75. }
  76. if ($table->hasIndex('IDX_79D3D95A613FECDF') == false) {
  77. $this->addSql('CREATE INDEX IDX_79D3D95A613FECDF ON skill_rel_user(session_id);');
  78. }
  79. if ($table->hasIndex('IDX_79D3D95AF68F11CE') == false) {
  80. $this->addSql('CREATE INDEX IDX_79D3D95AF68F11CE ON skill_rel_user (acquired_level);');
  81. }
  82. if ($table->hasIndex('IDX_79D3D95AF68F11CE') == false) {
  83. $this->addSql('CREATE INDEX idx_select_s_c_u ON skill_rel_user (session_id, course_id, user_id);');
  84. }
  85. if ($table->hasIndex('IDX_79D3D95AF68F11CE') == false) {
  86. $this->addSql('CREATE INDEX idx_select_sk_u ON skill_rel_user(skill_id, user_id);');
  87. }
  88. }
  89. // skill_level
  90. if ($schema->hasTable('skill_level')) {
  91. $table = $schema->getTable('skill_level');
  92. $this->addSql('ALTER TABLE skill_level CHANGE profile_id profile_id INT DEFAULT NULL, CHANGE position position INT NOT NULL, CHANGE short_name short_name VARCHAR(255) NOT NULL;');
  93. if ($table->hasForeignKey('FK_BFC25F2FCCFA12B8') == false) {
  94. $this->addSql('ALTER TABLE skill_level ADD CONSTRAINT FK_BFC25F2FCCFA12B8 FOREIGN KEY (profile_id) REFERENCES skill_level_profile (id);');
  95. }
  96. if ($table->hasIndex('IDX_BFC25F2FCCFA12B8') == false) {
  97. $this->addSql('CREATE INDEX IDX_BFC25F2FCCFA12B8 ON skill_level (profile_id);');
  98. }
  99. }
  100. }
  101. /**
  102. * @param Schema $schema
  103. */
  104. public function down(Schema $schema)
  105. {
  106. $this->addSql(
  107. 'ALTER TABLE skill_rel_user DROP COLUMN acquired_level, DROP COLUMN argumentation, DROP COLUMN argumentation_author_id, MODIFY course_id INT NOT NULL, MODIFY session_id INT NOT NULL'
  108. );
  109. $this->addSql(
  110. 'ALTER TABLE skill DROP COLUMN profile_id'
  111. );
  112. $this->addSql('DROP TABLE skill_level');
  113. $this->addSql('DROP TABLE skill_level_profile');
  114. }
  115. }